You can run a command every time you change directories in zsh with the chpwd function:
export CURRENT_PROJECT_PATH=$HOME/.current-project
function chpwd {
echo $(pwd) >! $CURRENT_PROJECT_PATH
}
current() {
if [[ -f $CURRENT_PROJECT_PATH ]]; then
cd "$(cat $CURRENT_PROJECT_PATH)"
fi
}
current
This will write the current directory to a hidden file in $HOME; opening a new
terminal will automatically cd to that directory.
About thoughtbot
We've been helping engineering teams deliver exceptional products for over 20 years. Our designers, developers, and product managers work closely with teams to solve your toughest software challenges through collaborative design and development. Learn more about us.
Could your team use a boost?
Ensure your team is moving as quickly as you need it to with thoughtbot's Team Augmentation. Our expert designers and developers embed in teams to hit tough goals while strengthening collaboration and communication.