mirror of
https://github.com/lloeki/dotfiles.git
synced 2025-12-06 07:24:39 +01:00
automatic GOPATH
This commit is contained in:
parent
04a1b20792
commit
85d27c709e
2 changed files with 36 additions and 0 deletions
35
zsh/go
Normal file
35
zsh/go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
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
|
||||
1
zsh/rc
1
zsh/rc
|
|
@ -12,6 +12,7 @@ source $DOTFILES_ZSH_DIR/vi
|
|||
source $DOTFILES_ZSH_DIR/completion
|
||||
source $DOTFILES_ZSH_DIR/prompt
|
||||
source $DOTFILES_ZSH_DIR/bundler
|
||||
source $DOTFILES_ZSH_DIR/go
|
||||
|
||||
source $DOTFILES_SHELL_DIR/git_prompt_info
|
||||
GIT_PS1_SHOWDIRTYSTATE=1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue