Skip to content

Instantly share code, notes, and snippets.

@jonahbron
Last active December 17, 2015 17:38
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 jonahbron/5646971 to your computer and use it in GitHub Desktop.
Save jonahbron/5646971 to your computer and use it in GitHub Desktop.
Script to `cd` relative to a specific directory, with autocomplete. Useful for jumping to a project directory, for example. Automatically activates `virtualenvwrapper` if detected.
# Quickly `cd` relative to a specific directory
#
# author Jonah Dahlquist
# license CC0
# Path to projects directory
export JUMP_PATH=$HOME/Projects
# Change to directory relative to JUMP_PATH
p() {
if [[ -z $1 ]]; then
cd $JUMP_PATH
else
cd $JUMP_PATH/$1
if [ -d $WORKON_HOME/$1 ]; then
echo "Activating virtualenv"
workon $1
fi
fi
}
# Tab completion for directories in JUMP_PATH
project_directory_tab_complete() {
local cur opts
cur="${COMP_WORDS[COMP_CWORD]}"
opts=$(cd $JUMP_PATH ; ls -d */ | sed 's|/./||')
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
}
complete -F project_directory_tab_complete p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment