A thing I rely on in my daily life, bit haven’t really ever documented. It’s a bash function that’s in my global .bash_profile, and it looks like this:
function p {
PROJECTDIR=$(find ~/code/ -maxdepth 2 \( -type l -or -type d \) -iname \*$1\* -print -quit);
if [ $PROJECTDIR ];
then
echo -n "๐ "
pushd $PROJECTDIR
else
echo "๐"
fi
}
It’s a shortcut – p
– to hop around projects. Generally, code projects are in ~/code/SECTION/PROJECT
, so it looks for a directory in the top two levels of ~/code/
for something containing the argument, and pushd
to that directory (pushd
rather than cd
because it maintains a stack of former directories, making it easier to go back. cd -
will do that for a single directory, but I like the full stack you get from pushd
. It’s like a clipboard manager, once you start using it, it’s really hard to go back to something that doesn’t.
It works like this:
aquarion@archipelago ~: p autop
๐ ~/code/autopelago ~
aquarion@archipelago ~/code/autopelago (master): p steam
๐ ~/code/raoss/steam ~/code/autopelago ~
aquarion@archipelago ~/code/raoss/steam (master): p steam_screenshots
๐ ~/code/sort_steam_screenshots ~/code/raoss/steam ~/code/autopelago ~
aquarion@archipelago ~/code/sort_steam_screenshots: popd
~/code/raoss/steam ~/code/autopelago ~
aquarion@archipelago ~/code/raoss/steam (master): popd
~/code/autopelago ~
aquarion@archipelago ~/code/autopelago (master):
And you can see it in context of the rest of my bash_profile in my dotfiles repo.