Skip to content

Instantly share code, notes, and snippets.

@ZebTheWizard
Created April 19, 2020 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZebTheWizard/8e378a67a139737e5c02cd535599e584 to your computer and use it in GitHub Desktop.
Save ZebTheWizard/8e378a67a139737e5c02cd535599e584 to your computer and use it in GitHub Desktop.
DEFAULT_DIRECTORY="$HOME"
LAST_CD_DIRECTORY=$(cat $HOME/.last_cd_directory 2>/dev/null)
CURRENT_SHELL="$0"
function go_to_default_or_previous
{
if (( $(ps aux | grep $CURRENT_SHELL | grep -v $$ | wc -l) > 0))
then
export DEFAULT_DIRECTORY="$LAST_CD_DIRECTORY"
fi
}
function cd
{
builtin cd "$1" && echo "$1" > $HOME/.last_cd_directory;
}
go_to_default_or_previous
cd $DEFAULT_DIRECTORY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment