Skip to content

Instantly share code, notes, and snippets.

@rodreegez
Created May 20, 2010 14:27
Show Gist options
  • Save rodreegez/407620 to your computer and use it in GitHub Desktop.
Save rodreegez/407620 to your computer and use it in GitHub Desktop.

Awesome bash function for switching to a project

_get_project_names(){
  local cur prev base
  COMPREPLY=()
  cur="${COMP_WORDS[COMP_CWORD]}"
  prev="${COMP_WORDS[COMP_CWORD-1]}"
  local names=$(for x in `ls -d1 /Users/$USER/Projects/*`; do echo ${x/\/Users\/$USER\/Projects\//} ; done)
  COMPREPLY=( $(compgen -W "${names}" -- ${cur}) )
}

p(){ cd /Users/$USER/Projects/$1/; }

complete -F _get_project_names p

Just type p followed by the first (few) letter(s) of your projects name, hit ->| (tab) to auto complete, hit return to go to ~/Projects/<project_name>

Credit to Edd

@dstrelau
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment