mirror of
https://github.com/lloeki/dotfiles.git
synced 2025-12-06 07:24:39 +01:00
35 lines
652 B
Text
35 lines
652 B
Text
go_commands=(go)
|
|
|
|
_go-installed() {
|
|
which go > /dev/null 2>&1
|
|
}
|
|
|
|
_within-go-project() {
|
|
local check_dir=$PWD
|
|
while [ "$(dirname $check_dir)" != "/" ]; do
|
|
if [ -f "$check_dir/.gopath" ]; then
|
|
echo "$check_dir"
|
|
return
|
|
fi
|
|
check_dir="$(dirname $check_dir)"
|
|
done
|
|
false
|
|
}
|
|
|
|
_run-with-gopath() {
|
|
local go_path
|
|
if _go-installed && go_path=$(_within-go-project); then
|
|
GOPATH="$go_path" $@
|
|
else
|
|
$@
|
|
fi
|
|
}
|
|
|
|
for cmd in $go_commands; do
|
|
eval "function gopath_$cmd () { _run-with-gopath $cmd \$@}"
|
|
alias $cmd=gopath_$cmd
|
|
|
|
if which _$cmd > /dev/null 2>&1; then
|
|
compdef _$cmd gopath_$cmd=$cmd
|
|
fi
|
|
done
|