Skip to content

Commit

Permalink
[Fix] avoid parse error with common omz global aliases, in `nvm_print…
Browse files Browse the repository at this point in the history
…_color_code`

Merge pull request nvm-sh#2365 from hosamaly/patch-1
  • Loading branch information
ljharb authored Jan 20, 2021
2 parents 502089a + 31c5c5c commit 015623e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
32 changes: 16 additions & 16 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -785,22 +785,22 @@ nvm_get_colors() {

nvm_print_color_code() {
case "${1-}" in
r) nvm_echo '0;31m';;
R) nvm_echo '1;31m';;
g) nvm_echo '0;32m';;
G) nvm_echo '1;32m';;
b) nvm_echo '0;34m';;
B) nvm_echo '1;34m';;
c) nvm_echo '0;36m';;
C) nvm_echo '1;36m';;
m) nvm_echo '0;35m';;
M) nvm_echo '1;35m';;
y) nvm_echo '0;33m';;
Y) nvm_echo '1;33m';;
k) nvm_echo '0;30m';;
K) nvm_echo '1;30m';;
e) nvm_echo '0;37m';;
W) nvm_echo '1;37m';;
'r') nvm_echo '0;31m';;
'R') nvm_echo '1;31m';;
'g') nvm_echo '0;32m';;
'G') nvm_echo '1;32m';;
'b') nvm_echo '0;34m';;
'B') nvm_echo '1;34m';;
'c') nvm_echo '0;36m';;
'C') nvm_echo '1;36m';;
'm') nvm_echo '0;35m';;
'M') nvm_echo '1;35m';;
'y') nvm_echo '0;33m';;
'Y') nvm_echo '1;33m';;
'k') nvm_echo '0;30m';;
'K') nvm_echo '1;30m';;
'e') nvm_echo '0;37m';;
'W') nvm_echo '1;37m';;
*) nvm_err 'Invalid color code';
return 1
;;
Expand Down
30 changes: 30 additions & 0 deletions test/sourcing/Sourcing nvm.sh global alias bug
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

die () { echo "$@" ; exit 1; }

if [ -n "${ZSH_VERSION-}" ]; then
# these are set by omz: https://github.com/ohmyzsh/ohmyzsh/tree/1ac40cd4456230f09bf0258b173304929d118992/plugins/common-aliases
alias -g R='| less -S'
alias -g G='| less -S'
# these are set by yadr: https://github.com/skwp/dotfiles/blob/5c487de9b81cd4265ecc9df74477e410ffbda6a1/zsh/zsh-aliases.zsh
alias -g C='| wc -l'
alias -g H='| head'
alias -g L="| less"
alias -g N="| /dev/null"
alias -g S='| sort'
alias -g G='| grep'
fi

OUTPUT=$(\. ../../nvm.sh || echo 'sourcing returned nonzero exit code')
UNEXPECTED_OUTPUT="sourcing returned nonzero exit code"
[ "_$OUTPUT" != "_$UNEXPECTED_OUTPUT" ] || die "Sourcing nvm.sh should not fail"

if [ -n "${ZSH_VERSION-}" ]; then
unalias \R
unalias \G
unalias \C
unalias \H
unalias \L
unalias \N
unalias \S
fi

0 comments on commit 015623e

Please sign in to comment.