From 41e7085425eac1cbc093b7e74e83fb87b1f2d3bc Mon Sep 17 00:00:00 2001 From: Inndy Date: Wed, 24 Jul 2024 20:23:49 +0800 Subject: [PATCH 1/2] Fix `cd` command hook bug `cd $*` is wrong, passing down command arguments should use "$@" instead ref: https://unix.stackexchange.com/questions/41571/what-is-the-difference-between-and#94135 --- scripts/env/cd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/env/cd b/scripts/env/cd index ea1d1953..22a4c0b1 100644 --- a/scripts/env/cd +++ b/scripts/env/cd @@ -19,7 +19,7 @@ fi if __gvm_is_function cd; then eval "$(echo "__gvm_oldcd()"; declare -f cd | sed '1 s/{/\'$'\n''{/' | tail -n +2)" elif [[ "$(builtin type cd)" == "cd is a shell builtin" ]]; then - eval "$(echo "__gvm_oldcd() { builtin cd \$*; return \$?; }")" + eval "$(echo "__gvm_oldcd() { builtin cd \"\$@\"; return \$?; }")" fi # Path cleanup @@ -46,7 +46,7 @@ export PATH="$(__gvm_munge_path)" cd() { # @FIXME: gvm_oldcd is broken on re-sourcing .bashrc! if __gvm_is_function __gvm_oldcd; then - __gvm_oldcd $* + __gvm_oldcd "$@" fi local dot_go_version dot_go_pkgset rslt From f878ebf4a2c4d7a7b607236e26c734dbb8b37962 Mon Sep 17 00:00:00 2001 From: Inndy Date: Wed, 24 Jul 2024 20:36:29 +0800 Subject: [PATCH 2/2] Add option GVM_DISABLE_CD_HOOK to opt-out of `cd` hook --- scripts/env/cd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/env/cd b/scripts/env/cd index 22a4c0b1..37940ebb 100644 --- a/scripts/env/cd +++ b/scripts/env/cd @@ -1,5 +1,8 @@ #!/usr/bin/env bash +# To disable this cd hook and prevent potential slowdowns, set GVM_DISABLE_CD_HOOK to a non-empty string. +[ -n "$GVM_DISABLE_CD_HOOK" ] && return + # Override the cd() function to implement auto-switching of go version and # pkgset when changing into a directory.