Mastodon github.com/rknightuk proven.lol/aaecd5

Navigate Project Folders with Pick

When I started my industrial placement at Radweb nearly 10 years ago (👴), Dan Harper sent me his bash aliases which included a lot of handy Git ones including this one that uses pick to list git branches. I can either do gco, search, and enter to checkout to that branch, or do gco branchName to checkout immediately to a branch:

function gco() {
if [ $# -eq 0 ]; then
git checkout $(git branch | pick)
else
git checkout "$@"
fi
}

I do use zsh-marks already to jump to folders I've expicitly marked (as well as jumping to the root of projects with jump sites) but last night while doing the cd ..; cd project-name dance between different projects I hadn't marked I realised I could apply this same thing to my personal sites folder which as the time of this writing has 97 folders. To do this, I needed to list out the directories with ls and the -1 option which tells ls to show one per line and just the folder name:

function site() {
if [ $# -eq 0 ]; then
cd ~/path/to/sites/$(ls -1 "~/path/to/sites" | pick)
else
cd ~/path/to/sites/"$@"
fi
}

So now to jump directly to the folder for this website instead of doing j sites then cd personal/rknight.me I can simply do site rknight.me. You can see all my aliases in my dotfiles on GitHub.

Discuss on the 'don 2023-01-19

💻 New blog post: Navigate Project Folders with Pick

Using Pick and a bash alias to navigate the ~100 projects in my sites folder. rknight.me/navigate-project-fo

Popular Posts

Analytics powered by Fathom