-
-
Save kevinkassimo/49932dbcaa055c1afedcb2834100b56b to your computer and use it in GitHub Desktop.
RD (regular directory), Fancier cd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### Change current directory and cache it | |
# e.g. | |
# $ rd some/dir | |
# (after a while) | |
# $ rd # jump to some/dir | |
function rd { | |
if [[ ! -z "$1" ]]; then | |
cd "$1" | |
if [[ $? -eq 0 ]]; then | |
realpath "$1" > "$HOME/.rd_save" | |
fi | |
else | |
if [[ ! -f "$HOME/.rd_save" ]]; then | |
cd "$HOME" | |
else | |
read -r RD_LAST_DIR < "$HOME/.rd_save" | |
cd "$RD_LAST_DIR" | |
fi | |
fi | |
} | |
export -f rd | |
# in .bashrc, add the following line | |
# source PATH/TO/THIS/FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment