gvm
gvm copied to clipboard
Couldn't source environment when use grep with color output
Hello. I had a problem with gvm (latest version at this moment) when I tried to install any go version. It installs, but cannot be used:
$ gvm use go1.4
ERROR: Couldn't source environment
I found it's because line 20 in scripts/env/use
:
fuzzy_match=$($LS_PATH "$GVM_ROOT/gos" | $SORT_PATH | $GREP_PATH "$VERSION" | $HEAD_PATH -n 1 | $GREP_PATH "$VERSION")
It finds go version via ls
and grep
. But when grep used with color output (--color=always
or something like that) this command takes entire grep
output, with ANSI color codes. And so...
ls: /Users/ertaquo/.gvm/environments/\033[01;31m\033[K\033[01;31m\033[Kgo1.4\033[m\033[K\033[m\033[K: No such file or directory
I fixed it by modifying this line:
fuzzy_match=$($LS_PATH "$GVM_ROOT/gos" | $SORT_PATH | $GREP_PATH --color=never "$VERSION" | $HEAD_PATH -n 1 | $GREP_PATH --color=never "$VERSION")
But it's just nail and I sure it should be fixed in more properly way :)
OS X El Capitan 10.11.6
$ cat ~/.bash_profile
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls -GFh'
export GREP_OPTIONS='--color=always'
I fixed this by simply changing fuzzy_match
to equal $1
- so as long as you've installed the right version, you're good.
this problem also shows up with function gvm_export_path
in scripts/function/gvm_export_path
:
1 #!/usr/bin/env bash
2 function gvm_export_path() {
3 export PATH="$GVM_ROOT/bin:$(echo "$PATH" | tr ":" "\n" | "$GREP_PATH" -v '^$' | egrep -v "$GVM_ROOT/(pkgsets|gos|bin)" | tr "\n" ":" | sed 's/:*$//')"
4 export GVM_PATH_BACKUP="$PATH"
5 }
In line 3, there is an egrep
command. In my case, I have previously aliased egrep = 'egrep --color=always'
in my .bashrc script, and it breaks this function above.
Since egrep
is deprecated, and grep -E
is preferred, the solution here is to change the egrep
on line 3 above to "$GREP_PATH" -E