Bash shell script code for navigating between project directories on the command line, including auto completion.
- Copy
pcd.sh
to your home directory:
curl https://raw.githubusercontent.com/oyvindstegard/pcd/main/pcd.sh \
-o ~/.pcd.sh
- Add code to shell init file
~/.bashrc
:
PROJECTS_PATH=~/your-projects-root-directory
source ~/.pcd.sh
- Open a shell, type
pcd
and hit TAB three times – you should see your project directories being auto completed.
After loading the code, type pcd
and hit TAB a couple of times to
see completion of all project directories. Hit ENTER to jump to
project. It will also complete into a project sub-directory as optional second
argument.
To jump up to a project root directory you can use pcd ..
– this works if it
is a git repository. You can combine it with a second arg to drill into another
directory tree of the same project:
~/dev/myrepo/target/build/foo/bar$ pcd .. src
~/dev/myrepo/src$
Lastly, you can use the option -p
to use pushd
instead cd
when changing
directory.
- Consider supporting a colon-delimited PROJECTS_PATH-variable with multiple roots.