From 76adade69a018dec2a29b71770296cb263229656 Mon Sep 17 00:00:00 2001 From: Christian Fredrik Johnsen Date: Sun, 22 Dec 2024 12:15:06 +0100 Subject: [PATCH] fix: print_shell_function(), use ${1:-} instead of $1, AND use `echo \` setup instead of `echo '` 1) If people are using bash with `set -u` (enable unset variable checking), then they will get an error if they run `pyenv` in the CLI under the current setup. To avoid any errors when no positional arguments, we use ${1:-} instead of $1. 2) We find that the script looks better when using: ```bash echo \ 'pyenv() { local command=${1:-}' ``` As opposed to: ``` echo 'pyenv() { local command=${1:-}' ``` --- libexec/pyenv-init | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libexec/pyenv-init b/libexec/pyenv-init index b2dfab22..19d3ce1a 100755 --- a/libexec/pyenv-init +++ b/libexec/pyenv-init @@ -253,7 +253,8 @@ function print_shell_function() { commands=(`pyenv-commands --sh`) case "$shell" in fish ) - echo 'function pyenv + echo \ +'function pyenv set command $argv[1] set -e argv[1] @@ -266,18 +267,21 @@ function print_shell_function() { end' ;; ksh | ksh93 | mksh ) - echo 'function pyenv { - typeset command=$1' + echo \ +'function pyenv { + typeset command=${1:-}' ;; * ) - echo 'pyenv() { - local command=$1' + echo \ +'pyenv() { + local command=${1:-}' ;; esac if [ "$shell" != "fish" ]; then IFS="|" - echo ' [ "$#" -gt 0 ] && shift + echo \ +' [ "$#" -gt 0 ] && shift case "$command" in '"${commands[*]:-/}"') eval "$(pyenv "sh-$command" "$@")"