Dark Light

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Faff

So, I saw gonzui and thought it might be useful. wget http://kent.dl.sourceforge.net/sourceforge/gonzui/gonzui-1.1.tar.gz tar zxvf gonzui-1.1.tar.gz cd gonzui-1.1 ./configure…