Skip to content

Instantly share code, notes, and snippets.

@disolovyov
Last active November 26, 2015 07:15
Show Gist options
  • Save disolovyov/bdfd8e38084dae1ebee9 to your computer and use it in GitHub Desktop.
Save disolovyov/bdfd8e38084dae1ebee9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
namespaces=(
"github.com/disolovyov"
"bitbucket.org/disolovyov"
)
function gopath() {
if [ -z "$1" ]; then
echo "Usage: gopath PROJECT"
return
fi
for path in "${namespaces[@]}"; do
local project="$GOPATH/src/$path/$1"
if [ -d "$project" ]; then
cd $project
return
fi
done
echo "Not found: $1"
}
function _gopath_complete() {
if [ $COMP_CWORD -ne 1 ]; then
return 1
fi
local comps=""
for path in "${namespaces[@]}"; do
dirs=$(ls ${GOPATH}/src/${path} 2>/dev/null)
comps="$comps $dirs"
done
local input="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "${comps}" -- ${input}) )
return 0
}
complete -F _gopath_complete gopath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment