Last active
January 5, 2018 19:58
-
-
Save Joopmicroop/3bd1db6da2cbb5e13b40abdb0d2a02d8 to your computer and use it in GitHub Desktop.
run script on cd'ing into and out of a directory
This file contains 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
# onCD | |
# ----- | |
# Place the code below in your .bashrc file. | |
# then place a script in any directory, named 'oncd.sh' | |
# the script will receive an argument of 'enter' or 'leave' | |
# when cd'ing into or out of the directory. | |
#(doesn't work with "shopt -s autocd", use COMMAND_PROMPT for that) | |
cd () { | |
oldpath=$PWD | |
builtin cd "$@" && oncd $oldpath | |
} | |
# these need more work | |
# pushd () { builtin pushd "$@" && oncd "enter" } | |
# popd () { builtin popd "$@" && oncd "enter" } | |
oncd () { | |
#echo "oldpath: $1" | |
[[ -f "$1/oncd.sh" ]] && sh $1/oncd.sh "leave" | |
[[ -f "oncd.sh" ]] && sh oncd.sh "enter" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment