This blog post introduces the jd function that enhances the cd (change directory) command for Bash shells under WSL to make it easier to access past working directories without the need to remember or type their paths, as well as to allow typing and pasting Windows paths.
You can use the jd function just as you would the cd command. You can alias cd to the jd function so that you get this behavior without having to retrain your fingers to type jd instead of cd. This function uses $HOME/.jd.lst to store directory paths.
If you pass a Windows path such as ‘C:\’ or ‘\\wsl.localhost\Ubuntu\’ the function will use the wslpath command to convert them to the corresponding Unix paths.
- You can pass -a to add all descendant directories of the current directory to the list.
- You can pass -h to get basic usage information.
- You can pass -l to get a list of past working directories.
- You can pass -n to specify one of those entries by number.
- You can pass -r to remove a range or entries that match a pattern,
If you alias cd to jd, you can use any of these approaches to ignore the alias and invoke the Bash native cd command:
- \cd
- builtin cd
- command cd /path/to/directory
I add this function and alias to a file that the shell sources at startup.
Here is the code:
Credit to Clippy 2.0: