-
Notifications
You must be signed in to change notification settings - Fork 382
Description
Hi,
I just started using Zsh, not to mention oh-my-zsh, so please excuse me if I make a mistake triaging this issue. I was trying to get the Go prompt working for bullet-train (great theme by the way!), and I just couldn't. It turns out the logic that detects whether to use a Go prompt appears to be incorrect and incomplete:
# Go
prompt_go() {
setopt extended_glob
if [[ (-f *.go(#qN) || -d Godeps || -f glide.yaml) ]]; then
if command -v go > /dev/null 2>&1; then
prompt_segment $BULLETTRAIN_GO_BG $BULLETTRAIN_GO_FG $BULLETTRAIN_GO_PREFIX" $(go version | grep --colour=never -oE '[[:digit:]].[[:digit:]]+')"
fi
fi
}
Issue 1 - Glob Glob
Here's what I mean:
-
Create a temporary directory:
cd $(mktemp -d)
-
Enable extended glob:
setopt extended_glob
-
Test for go sources:
$ { [[ -f *.go(#qN) ]] && echo 'go source(s) detected!'; } || echo 'no go :(' no go :(
-
Create a file that ends with
.go
:touch hello.go
-
Test for go sources again:
$ { [[ -f *.go(#qN) ]] && echo 'go source(s) detected!'; } || echo 'no go :(' go source(s) detected!
-
Create a second file that ends with
.go
:touch world.go
-
Test for go sources again:
$ { [[ -f *.go(#qN) ]] && echo 'go source(s) detected!'; } || echo 'no go :(' no go :(
So why does the above fail? Because the -f
operator does not work against multiple operands:
-f file true if file exists and is a regular file.
Instead zsh
indicates to use the -n
operator for detecting multiple files:
$ { [[ -n *.go(#qN) ]] && echo 'go source(s) detected!'; } || echo 'no go :('
go source(s) detected!
Oh, and just to prove -n
works in the other cases:
# Remove world.go and expect a positive message
$ rm world.go && { [[ -n *.go(#qN) ]] && echo 'go source(s) detected!'; } || echo 'no go :('
go source(s) detected!
# Remove hello.go and expect a negative message
$ rm hello.go && { [[ -n *.go(#qN) ]] && echo 'go source(s) detected!'; } || echo 'no go :('
no go :(
Yep, works :)
Issue 2 - Go Modules
Finally, it looks like y'all don't yet support Go modules for detection. The detection line should be updated as follows (with the fix for the s/-f/-n/
:
if [[ (-n *.go(#qN) || -d Godeps || -f glide.yaml || -f go.mod) ]]; then
Thanks!