Last active
August 29, 2015 14:20
-
-
Save dmlyons/f62b818ec1a9e03f0e20 to your computer and use it in GitHub Desktop.
A bash-completion script that will allow you to jump to specific go source directories with tab completion
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
function godir { | |
if [ -z "$1" ] | |
then | |
cd $GOPATH/src | |
else | |
if [ "$1" == "reload" ] | |
then | |
_go_package_names=( $(go list all) ) | |
else | |
cd $GOPATH/src/$1 | |
git status | |
fi | |
fi | |
echo "Current Directory is" `pwd` | |
} | |
complete -F _godir_completion godir | |
function _godir_completion { | |
local cur prev opts # no need to pollute the environment | |
COMPREPLY=() # clear the reply in case it was invoked previously | |
cur="${COMP_WORDS[COMP_CWORD]}" # current word I am trying | |
prev="${COMP_WORDS[COMP_CWORD-1]}" # previous word on the line | |
opts="" # other options that the command recognizes | |
if [ -z "$_go_package_names" ]; then | |
_go_package_names=( $(go list all) ) | |
fi | |
COMPREPLY=( $(compgen -W "${_go_package_names[*]}" -- "$cur") ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment