mirror of
https://github.com/lloeki/dotfiles.git
synced 2025-12-06 07:24:39 +01:00
bundler and go suport for bash too
This commit is contained in:
parent
85d27c709e
commit
6f4df09b76
4 changed files with 25 additions and 15 deletions
39
shell/go
Normal file
39
shell/go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
go_commands=(go)
|
||||
|
||||
_go-installed() {
|
||||
which go > /dev/null 2>&1
|
||||
}
|
||||
|
||||
_within-go-project() {
|
||||
local check_dir=$PWD
|
||||
local next_check_dir=${check_dir%/*}
|
||||
while [ "$next_check_dir" != "" ]; do
|
||||
if [ -f "$check_dir/.gopath" ]; then
|
||||
echo "$check_dir"
|
||||
return
|
||||
fi
|
||||
check_dir="$next_check_dir"
|
||||
next_check_dir=${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 [[ -n $ZSH_VERSION ]]; then
|
||||
if which _$cmd > /dev/null 2>&1; then
|
||||
compdef _$cmd gopath_$cmd=$cmd
|
||||
fi
|
||||
fi
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue