-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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