From 21e0aaf2870acfac673cb3d5b38ff9379fac22ae Mon Sep 17 00:00:00 2001 From: Nikolaos Kakouros Date: Thu, 31 Jan 2019 17:16:41 +0100 Subject: [PATCH] Allows _GO_SCRIPTS_DIR to be equal to _GO_ROOTDIR --- go-core.bash | 9 +++++++++ lib/internal/commands | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) 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