diff --git a/go-core.bash b/go-core.bash index 61cf511..418943a 100755 --- a/go-core.bash +++ b/go-core.bash @@ -413,6 +413,15 @@ _@go.set_scripts_dir() { "directory" >&2 return 1 fi + + # If '_GO_SCRIPTS_DIR' was set to '_GO_ROOTDIR', 'scripts_dir' would end up + # with a trailing space. This would cause issues later in the code where path + # comparison would fail as paths would result in double slashes before + # command script paths. + if [[ "${scripts_dir: -1}" == '/' ]]; then + scripts_dir="${scripts_dir%/}" + fi + _GO_SCRIPTS_DIR="$scripts_dir" } diff --git a/lib/internal/commands b/lib/internal/commands index 46f088f..46d6def 100644 --- a/lib/internal/commands +++ b/lib/internal/commands @@ -51,8 +51,13 @@ _@go.find_commands() { for scripts_dir in "$@"; do scripts=() + # Together with the existence of a potential script, we are also excluding + # the './go' itself. This is relevant for the case a user has set + # '_GO_SCRIPTS_DIR' to '_GO_ROOTDIR'. In that case, the './go' script would + # end up being considered a command script. for script in "$scripts_dir"/*; do - if [[ -f "$script" && -x "$script" ]]; then + if [[ -f "$script" && -x "$script" && + "$script" != "$_GO_ROOTDIR/$_GO_CMD" ]]; then scripts+=("$script") fi done