I often work in a Linux environment with multiple windows open in a tmux session. One of the pattern I see often is the need to navigate to the same directory for multiple windows. For example, in window 1, I navigated to a directory deep within my project:
$ cd ~/long/path/to/my/directory
Then, on window 2, I want to navigate to the same directory. This often involves either copy the command from window 1 and paste into window 2, or retype the same command again. There must be a better way.
To solve this problem, I created two bash aliases: here and there. The here alias marks the current location and the there alias jumps to that location:
alias here='echo cd $PWD >~/.here.sh' alias there='source ~/.here.sh'
With this pair of commands, from window 1, I would navigate to where I want and issue the here command to mark. Then, on window 2, I issue the there command to navigate to the same directory.
How It Works
The here command records the current directory in a hidden file called ~/.here.sh and the there command just source that script. It’s that simple.