Created
November 30, 2016 09:33
-
-
Save timbrandin/c57113ab0a941fda811b5dd4ecf299c2 to your computer and use it in GitHub Desktop.
Helper to jump around between project folders.
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
# Go to projects folder from anywhere. | |
_root=$(echo ~/Projects); | |
pl() { | |
if [ -d ${_root}/$1 ] | |
then | |
cd ${_root}/$1; | |
else | |
echo "Couldn't find $1"; | |
fi; | |
} | |
# Auto-complete pl-script. | |
# Now: | |
# - autocomplete of folders in _root | |
# - autocomplete of folders in _root/$2 | |
# Should be: | |
# - autocomplete of git repos in _root | |
# - autocomplete of git repos in _root/$2 | |
# - Remove trailing space or solve for that situation. | |
_pl() { | |
local cur=${COMP_WORDS[COMP_CWORD]}; | |
if [ -n "$2" ]; | |
then | |
_folder=$(echo "$2" | sed s/\\/.*$//g); | |
if [ -d ${_root}/${_folder} ]; | |
then | |
_projects=$(basename $(ls -d ${_root}/${_folder}/*/) | sed s/$/\\//g | sed s/^/${_folder}\\//g); | |
COMPREPLY=( $(compgen -W "$(echo ${_projects})" -- $cur) ); | |
else | |
_projects=$(basename $(ls -d ${_root}/*/) | sed s/$/\\//g); | |
COMPREPLY=( $(compgen -W "$(echo ${_projects})" -- $cur) ); | |
fi; | |
else | |
_projects=$(basename $(ls -d ${_root}/*/)); | |
COMPREPLY=( $(compgen -W "$(echo ${_projects})" -- $cur) ); | |
fi; | |
} | |
complete -F _pl -o filenames pl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment