Skip to content

Instantly share code, notes, and snippets.

@erkattak
Last active January 9, 2018 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erkattak/4c825e8990ea0ac53cd563c6b4249020 to your computer and use it in GitHub Desktop.
Save erkattak/4c825e8990ea0ac53cd563c6b4249020 to your computer and use it in GitHub Desktop.
Bash Project Switch With Completion
c() { cd "$HOME/Projects/${*}"; }
_c() {
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($(compgen -W "$(find $HOME/Projects -mindepth 2 -maxdepth 2 -type d | cut -d/ -f5-)" -- $cur))
}
complete -o nospace -F _c c

I keep all my projects on my local machine organized like so:

/Users/brkattk/Projects
├── agnostechvalley
│   ├── agnostechvalley.github.io
│   ├── katas
│   └── mac_vendor_lookup
├── brkattk
│   ├── Chatter
│   ├── elixir_for_programmers
│   ├── gentlemans_years
│   ├── tic_tac_toe
│   └── zmq-rock-paper-scissors
├── golang
│   └── src
└── oddnetworks
    ├── odd-android-ots
    ├── odd-android-tv-ots
    ├── odd_connect
    ├── oddcast
    └── www

I use either the bash + bash completion or zsh version of c to change into a new project.

asciicast

c(){cd ~/Projects/$1;}
compctl -W ~/Projects -/ c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment