Skip to content

Instantly share code, notes, and snippets.

@kevinkassimo
Last active April 9, 2018 20:39
Show Gist options
  • Save kevinkassimo/49932dbcaa055c1afedcb2834100b56b to your computer and use it in GitHub Desktop.
Save kevinkassimo/49932dbcaa055c1afedcb2834100b56b to your computer and use it in GitHub Desktop.
RD (regular directory), Fancier cd
#!/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