From 417c12231081aab99af458862ecca657d02d03f5 Mon Sep 17 00:00:00 2001 From: Stephan Garland Date: Sun, 15 Jan 2023 17:28:13 -0500 Subject: [PATCH 1/7] feat: first pass at improving speed, mostly for list and current commands --- lib/utils.bash | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/utils.bash b/lib/utils.bash index cecfdec6c..da283200f 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -8,6 +8,14 @@ GREP_COLORS= ASDF_DIR=${ASDF_DIR:-''} ASDF_DATA_DIR=${ASDF_DATA_DIR:-''} +fast_basename() { + # if the path ends in a slash, remove it, then use parameter substitution + # if it doesn't, use parameter substitution on the path as-is + dirpath="$1" + [[ "$dirpath" == */ ]] && dirpath="${dirpath%/}" && dirpath="${dirpath##*/}" || dirpath="${dirpath##*/}" + echo $dirpath +} + asdf_version() { local version git_rev version="v$(cat "$(asdf_dir)/version.txt")" @@ -99,7 +107,7 @@ list_installed_versions() { if [ -d "$plugin_installs_path" ]; then for install in "${plugin_installs_path}"/*/; do [[ -e "$install" ]] || break - basename "$install" | sed 's/^ref-/ref:/' + fast_basename "$install" done fi } @@ -280,7 +288,7 @@ get_custom_executable_path() { # custom plugin hook for executable path if [ -x "${plugin_path}/bin/exec-path" ]; then - cmd=$(basename "$executable_path") + cmd=$(fast_basename "$executable_path") local relative_path # shellcheck disable=SC2001 relative_path=$(printf "%s\n" "$executable_path" | sed -e "s|${install_path}/||") @@ -300,7 +308,7 @@ get_executable_path() { if [ "$version" = "system" ]; then path=$(remove_path_from_path "$PATH" "$(asdf_data_dir)/shims") - cmd=$(basename "$executable_path") + cmd=$(fast_basename "$executable_path") cmd_path=$(PATH=$path command -v "$cmd" 2>&1) # shellcheck disable=SC2181 if [ $? -ne 0 ]; then @@ -320,8 +328,8 @@ parse_asdf_version_file() { if [ -f "$file_path" ]; then local version - version=$(strip_tool_version_comments "$file_path" | grep "^${plugin_name} " | sed -e "s/^${plugin_name} //") - + # this is actually only about 5% faster than the original, despite losing a function call and two pipes + version=$(awk -v plugin_name="$plugin_name" '!/^#/ { gsub(/#.*/,"",$0); gsub(/ +$/,"",$0)} $1 == plugin_name {print $NF}' "$file_path") if [ -n "$version" ]; then if [[ "$version" == path:* ]]; then util_resolve_user_path "${version#path:}" @@ -634,11 +642,15 @@ plugin_shims() { shim_plugin_versions() { local executable_name - executable_name=$(basename "$1") + # not sure why this needs a basename + executable_name=$(fast_basename "$1") local shim_path shim_path="$(asdf_data_dir)/shims/${executable_name}" if [ -x "$shim_path" ]; then - grep "# asdf-plugin: " "$shim_path" 2>/dev/null | sed -e "s/# asdf-plugin: //" | uniq + # not sure why uniq was needed here since asdf doesn't let you install the same plugin version twice - maybe for legacy? + # nevertheless, the awk command handles de-duping; if it isn't needed, the sed command is ~3% faster + #sed -n "/# asdf-plugin: /s/# asdf-plugin: //p 2>/dev/null" "$shim_path" + awk '/# asdf-plugin: / { l=$(NF-1) " " $NF; !seen[$0]++; if (seen[$0] < 2) { print l } }' "$shim_path" 2>/dev/null else printf "asdf: unknown shim %s\n" "$executable_name" return 1 @@ -647,11 +659,11 @@ shim_plugin_versions() { shim_plugins() { local executable_name - executable_name=$(basename "$1") + executable_name=$(fast_basename "$1") local shim_path shim_path="$(asdf_data_dir)/shims/${executable_name}" if [ -x "$shim_path" ]; then - grep "# asdf-plugin: " "$shim_path" 2>/dev/null | sed -e "s/# asdf-plugin: //" | cut -d' ' -f 1 | uniq + awk '/# asdf-plugin: / { l=$(NF-1) } END { print l} ' "$shim_path" 2>/dev/null else printf "asdf: unknown shim %s\n" "$executable_name" return 1 @@ -667,7 +679,9 @@ strip_tool_version_comments() { # 2. Find a # and delete it and everything after the #. # 3. Remove any whitespace from the end of the line. # Finally, the command will print the lines that are not empty. - sed '/^[[:blank:]]*#/d;s/#.*//;s/[[:blank:]]*$//' "$tool_version_path" + # this is ~2% faster than the original implementation + # by combining steps 2 and 3 + sed '/^[[:blank:]]*#/d; s/\s*#.*$//;' "$tool_version_path" } asdf_run_hook() { From 009ab6ebfe7777b2b0e33e0daf348efcf2b6b970 Mon Sep 17 00:00:00 2001 From: Stephan Garland Date: Thu, 19 Jan 2023 23:51:33 -0500 Subject: [PATCH 2/7] feat: added a fast_tr command, did some more grouping of commands where possible --- lib/utils.bash | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/lib/utils.bash b/lib/utils.bash index da283200f..b511aee95 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -7,13 +7,44 @@ GREP_COLORS= ASDF_DIR=${ASDF_DIR:-''} ASDF_DATA_DIR=${ASDF_DATA_DIR:-''} +BASH_MAJOR_VERSION=${BASH_VERSION%%.*} fast_basename() { # if the path ends in a slash, remove it, then use parameter substitution # if it doesn't, use parameter substitution on the path as-is dirpath="$1" [[ "$dirpath" == */ ]] && dirpath="${dirpath%/}" && dirpath="${dirpath##*/}" || dirpath="${dirpath##*/}" - echo $dirpath + printf "$dirpath" +} + +fast_tr() { + inputArr=("$@") + inputStr="${inputArr[0]}" + local outputStr + if [ ! ${#inputArr[@]} -eq 3 ] && [ ! ${#inputArr[@]} -eq 5 ]; then + printf "%s\n" "ERROR: fast_tr expects an array of 3 or 5 elements, got ${#inputArr[@]}" + return 1 + fi + # if bash >= v4, use parameter modification to upper/lower the string + if [ ${BASH_MAJOR_VERSION} -gt 3 ]; then + case ${inputArr[1]} in + "[:lower:]") + outputStr="${inputStr@U}" + ;; + "[:upper:]") + outputStr="${inputStr@L}" + ;; + "*") + printf "ERROR: fast_tr() expects [:lower:] and [:upper:] as arguments" + esac + # and then use parameter substitution to replace characters in the string + # if the 4th or 5th elements are not set, the substitution has no effect + outputStr="${outputStr//${inputArr[3]-''}/${inputArr[4]-''}}" + printf "${outputStr}" + else + # else use tr with the input array elements as args + printf "${inputStr}" | tr "${inputArr[1]}${inputArr[3]-''}" "${inputArr[2]}${inputArr[4]-''}" + fi } asdf_version() { @@ -198,7 +229,8 @@ find_versions() { version=$(get_version_from_env "$plugin_name") if [ -n "$version" ]; then local upcase_name - upcase_name=$(printf "%s\n" "$plugin_name" | tr '[:lower:]-' '[:upper:]_') + tr_args=("$plugin_name" "[:lower:]" "[:upper:]" "-" "_") + upcase_name=$(fast_tr ${tr_args[@]}) local version_env_var="ASDF_${upcase_name}_VERSION" printf "%s\n" "$version|$version_env_var environment variable" @@ -700,19 +732,18 @@ asdf_run_hook() { get_shim_versions() { shim_name=$1 shim_plugin_versions "${shim_name}" - shim_plugin_versions "${shim_name}" | cut -d' ' -f 1 | awk '{print$1" system"}' + shim_plugin_versions "${shim_name%% [0-9]*} system}" } preset_versions() { shim_name=$1 - shim_plugin_versions "${shim_name}" | cut -d' ' -f 1 | uniq | xargs -IPLUGIN bash -c ". $(asdf_dir)/lib/utils.bash; printf \"%s %s\n\" PLUGIN \$(get_preset_version_for PLUGIN)" + shim_plugin_versions "${shim_name%% [0-9]*}" | xargs -IPLUGIN bash -c ". $(asdf_dir)/lib/utils.bash; printf \"%s %s\n\" PLUGIN \$(get_preset_version_for PLUGIN)" } select_from_preset_version() { local shim_name=$1 local shim_versions local preset_versions - shim_versions=$(get_shim_versions "$shim_name") if [ -n "$shim_versions" ]; then preset_versions=$(preset_versions "$shim_name") @@ -735,7 +766,6 @@ select_version() { local plugins IFS=$'\n' read -rd '' -a plugins <<<"$(shim_plugins "$shim_name")" - for plugin_name in "${plugins[@]}"; do local version_and_path local version_string @@ -765,7 +795,7 @@ select_version() { with_shim_executable() { local shim_name - shim_name=$(basename "$1") + shim_name=$(fast_basename "$1") local shim_exec="${2}" if [ ! -f "$(asdf_data_dir)/shims/${shim_name}" ]; then @@ -775,7 +805,6 @@ with_shim_executable() { local selected_version selected_version="$(select_version "$shim_name")" - if [ -z "$selected_version" ]; then selected_version="$(select_from_preset_version "$shim_name")" fi From f4102044e9ab17651dec8c1c4613f087db86ee92 Mon Sep 17 00:00:00 2001 From: Stephan Garland Date: Tue, 24 Jan 2023 19:36:00 -0500 Subject: [PATCH 3/7] fix: using native bash versinfo array to check versions; fixed a bash5-ism --- lib/utils.bash | 7 +- no-code | 536 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 539 insertions(+), 4 deletions(-) create mode 100644 no-code diff --git a/lib/utils.bash b/lib/utils.bash index b511aee95..400f58637 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -7,7 +7,6 @@ GREP_COLORS= ASDF_DIR=${ASDF_DIR:-''} ASDF_DATA_DIR=${ASDF_DATA_DIR:-''} -BASH_MAJOR_VERSION=${BASH_VERSION%%.*} fast_basename() { # if the path ends in a slash, remove it, then use parameter substitution @@ -26,13 +25,13 @@ fast_tr() { return 1 fi # if bash >= v4, use parameter modification to upper/lower the string - if [ ${BASH_MAJOR_VERSION} -gt 3 ]; then + if [ ${BASH_VERSINFO[0]} -gt 3 ]; then case ${inputArr[1]} in "[:lower:]") - outputStr="${inputStr@U}" + outputStr="${inputStr^^}" ;; "[:upper:]") - outputStr="${inputStr@L}" + outputStr="${inputStr,,}" ;; "*") printf "ERROR: fast_tr() expects [:lower:] and [:upper:] as arguments" diff --git a/no-code b/no-code new file mode 100644 index 000000000..1013c767e --- /dev/null +++ b/no-code @@ -0,0 +1,536 @@ + + + + + + Page not found – Dan Q + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+
+ +
+ + +
+

It looks like nothing was found at this location. Maybe try one of the links below or a search?

+ + + + +

Archives

Try looking in the monthly archives. :)

+ + + +
+
+
+ +
+
+ + +
+ +
+
+
    +
  • © Dan Q 1998 – 2023
  • +
  • all original content CC-By-NC except where otherwise stated
  • +
  • made with handwritten ​​ HTML5, CSS3, and love
  • +
+
+
+
+ + + + + + From f585713401e31a19d219246af678d0dc69e50fc2 Mon Sep 17 00:00:00 2001 From: Stephan Garland Date: Tue, 24 Jan 2023 21:44:58 -0500 Subject: [PATCH 4/7] feat: changed fast_basename to use REPLY --- lib/utils.bash | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/utils.bash b/lib/utils.bash index 400f58637..cc9f8ad9f 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -9,11 +9,11 @@ ASDF_DIR=${ASDF_DIR:-''} ASDF_DATA_DIR=${ASDF_DATA_DIR:-''} fast_basename() { - # if the path ends in a slash, remove it, then use parameter substitution - # if it doesn't, use parameter substitution on the path as-is - dirpath="$1" - [[ "$dirpath" == */ ]] && dirpath="${dirpath%/}" && dirpath="${dirpath##*/}" || dirpath="${dirpath##*/}" - printf "$dirpath" + unset -v REPLY + local dirpath="$1" + dirpath=${dirpath%/} + dirpath=${dirpath##*/} + REPLY=$dirpath } fast_tr() { @@ -34,15 +34,15 @@ fast_tr() { outputStr="${inputStr,,}" ;; "*") - printf "ERROR: fast_tr() expects [:lower:] and [:upper:] as arguments" + printf "%s\n" "ERROR: fast_tr() expects [:lower:] and [:upper:] as arguments" esac # and then use parameter substitution to replace characters in the string # if the 4th or 5th elements are not set, the substitution has no effect outputStr="${outputStr//${inputArr[3]-''}/${inputArr[4]-''}}" - printf "${outputStr}" + printf "%s\n" "${outputStr}" else # else use tr with the input array elements as args - printf "${inputStr}" | tr "${inputArr[1]}${inputArr[3]-''}" "${inputArr[2]}${inputArr[4]-''}" + printf "%s\n" "${inputStr}" | tr "${inputArr[1]}${inputArr[3]-''}" "${inputArr[2]}${inputArr[4]-''}" fi } @@ -137,7 +137,7 @@ list_installed_versions() { if [ -d "$plugin_installs_path" ]; then for install in "${plugin_installs_path}"/*/; do [[ -e "$install" ]] || break - fast_basename "$install" + fast_basename "$install" && printf "%s\n" "$REPLY" done fi } @@ -319,7 +319,8 @@ get_custom_executable_path() { # custom plugin hook for executable path if [ -x "${plugin_path}/bin/exec-path" ]; then - cmd=$(fast_basename "$executable_path") + fast_basename "$executable_path" + local cmd="$REPLY" local relative_path # shellcheck disable=SC2001 relative_path=$(printf "%s\n" "$executable_path" | sed -e "s|${install_path}/||") @@ -339,7 +340,8 @@ get_executable_path() { if [ "$version" = "system" ]; then path=$(remove_path_from_path "$PATH" "$(asdf_data_dir)/shims") - cmd=$(fast_basename "$executable_path") + fast_basename "$executable_path" + local cmd="$REPLY" cmd_path=$(PATH=$path command -v "$cmd" 2>&1) # shellcheck disable=SC2181 if [ $? -ne 0 ]; then @@ -673,8 +675,8 @@ plugin_shims() { shim_plugin_versions() { local executable_name - # not sure why this needs a basename - executable_name=$(fast_basename "$1") + fast_basename "$1" + executable_name="$REPLY" local shim_path shim_path="$(asdf_data_dir)/shims/${executable_name}" if [ -x "$shim_path" ]; then @@ -690,7 +692,8 @@ shim_plugin_versions() { shim_plugins() { local executable_name - executable_name=$(fast_basename "$1") + fast_basename "$1" + executable_name="$REPLY" local shim_path shim_path="$(asdf_data_dir)/shims/${executable_name}" if [ -x "$shim_path" ]; then @@ -794,7 +797,8 @@ select_version() { with_shim_executable() { local shim_name - shim_name=$(fast_basename "$1") + fast_basename "$1" + shim_name="$REPLY" local shim_exec="${2}" if [ ! -f "$(asdf_data_dir)/shims/${shim_name}" ]; then From 0084332ee74dda2d1787fecd4809d298a2b9e141 Mon Sep 17 00:00:00 2001 From: Stephan Garland Date: Tue, 24 Jan 2023 22:28:06 -0500 Subject: [PATCH 5/7] feat: changed fast_tr to use REPLY; eliminated an unnecessary tr call --- lib/utils.bash | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/utils.bash b/lib/utils.bash index cc9f8ad9f..5ea10cee9 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -16,10 +16,12 @@ fast_basename() { REPLY=$dirpath } +# in order to make this able to call tr if bash v4 is unavailable, +# it requires inputting a tr-like string, e.g. tr '[:lower:]' '[:upper:]' fast_tr() { + unset -v REPLY inputArr=("$@") inputStr="${inputArr[0]}" - local outputStr if [ ! ${#inputArr[@]} -eq 3 ] && [ ! ${#inputArr[@]} -eq 5 ]; then printf "%s\n" "ERROR: fast_tr expects an array of 3 or 5 elements, got ${#inputArr[@]}" return 1 @@ -28,18 +30,17 @@ fast_tr() { if [ ${BASH_VERSINFO[0]} -gt 3 ]; then case ${inputArr[1]} in "[:lower:]") - outputStr="${inputStr^^}" + REPLY="${inputStr^^}" ;; "[:upper:]") - outputStr="${inputStr,,}" + REPLY="${inputStr,,}" ;; "*") printf "%s\n" "ERROR: fast_tr() expects [:lower:] and [:upper:] as arguments" esac # and then use parameter substitution to replace characters in the string # if the 4th or 5th elements are not set, the substitution has no effect - outputStr="${outputStr//${inputArr[3]-''}/${inputArr[4]-''}}" - printf "%s\n" "${outputStr}" + REPLY="${REPLY//${inputArr[3]-''}/${inputArr[4]-''}}" else # else use tr with the input array elements as args printf "%s\n" "${inputStr}" | tr "${inputArr[1]}${inputArr[3]-''}" "${inputArr[2]}${inputArr[4]-''}" @@ -228,8 +229,9 @@ find_versions() { version=$(get_version_from_env "$plugin_name") if [ -n "$version" ]; then local upcase_name - tr_args=("$plugin_name" "[:lower:]" "[:upper:]" "-" "_") - upcase_name=$(fast_tr ${tr_args[@]}) + local fast_tr_arr=("$plugin_name" "[:lower:]" "[:upper:]" "-" "_") + fast_tr "${fast_tr_arr[@]}" + upcase_name="$REPLY" local version_env_var="ASDF_${upcase_name}_VERSION" printf "%s\n" "$version|$version_env_var environment variable" @@ -276,7 +278,9 @@ display_no_version_set() { get_version_from_env() { local plugin_name=$1 local upcase_name - upcase_name=$(printf "%s\n" "$plugin_name" | tr '[:lower:]-' '[:upper:]_') + local fast_tr_arr=("$plugin_name" "[:lower:]" "[:upper:]" "-" "_") + fast_tr "${fast_tr_arr[@]}" + upcase_name="$REPLY" local version_env_var="ASDF_${upcase_name}_VERSION" local version=${!version_env_var:-} printf "%s\n" "$version" @@ -622,9 +626,7 @@ with_plugin_env() { local path exec_paths exec_paths="$(list_plugin_exec_paths "$plugin_name" "$full_version")" - # exec_paths contains a trailing newline which is converted to a colon, so no - # colon is needed between the subshell and the PATH variable in this string - path="$(tr '\n' ':' <<<"$exec_paths")$PATH" + path="${exec_paths}:$PATH" # If no custom exec-env transform, just execute callback if [ ! -f "${plugin_path}/bin/exec-env" ]; then From 3d86e296a75c2dbe8d13b65618df3560096d2cfc Mon Sep 17 00:00:00 2001 From: Stephan Garland Date: Tue, 24 Jan 2023 23:15:05 -0500 Subject: [PATCH 6/7] feat: minor changes to two functions; added comment for parse_asdf_version_file --- lib/utils.bash | 20 +- no-code | 536 ------------------------------------------------- 2 files changed, 9 insertions(+), 547 deletions(-) delete mode 100644 no-code diff --git a/lib/utils.bash b/lib/utils.bash index 5ea10cee9..3fa7ad687 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -365,8 +365,9 @@ parse_asdf_version_file() { if [ -f "$file_path" ]; then local version - # this is actually only about 5% faster than the original, despite losing a function call and two pipes + # this is causing multiple failures in tests/utils.bash, despite seeming to work identically version=$(awk -v plugin_name="$plugin_name" '!/^#/ { gsub(/#.*/,"",$0); gsub(/ +$/,"",$0)} $1 == plugin_name {print $NF}' "$file_path") + #version=$(strip_tool_version_comments "$file_path" | grep "^${plugin_name} " | sed -e "s/^${plugin_name} //") if [ -n "$version" ]; then if [[ "$version" == path:* ]]; then util_resolve_user_path "${version#path:}" @@ -663,10 +664,8 @@ plugin_executables() { is_executable() { local executable_path=$1 - if [[ (-f "$executable_path") && (-x "$executable_path") ]]; then - return 0 - fi - return 1 + [ -x "$executable_path" ] + return $? } plugin_shims() { @@ -710,13 +709,10 @@ strip_tool_version_comments() { local tool_version_path="$1" # Use sed to strip comments from the tool version file # Breakdown of sed command: - # This command represents 3 steps, separated by a semi-colon (;), that run on each line. + # This command represents 2 steps, separated by a semi-colon (;), that run on each line. # 1. Delete line if it starts with any blankspace and a #. - # 2. Find a # and delete it and everything after the #. - # 3. Remove any whitespace from the end of the line. + # 2. Find a # and delete it and everything after the #, and remove trailing whitespace. # Finally, the command will print the lines that are not empty. - # this is ~2% faster than the original implementation - # by combining steps 2 and 3 sed '/^[[:blank:]]*#/d; s/\s*#.*$//;' "$tool_version_path" } @@ -892,7 +888,9 @@ remove_path_from_path() { # Output is a new string suitable for assignment to PATH local PATH=$1 local path=$2 - substitute "$PATH" "$path" "" | sed -e "s|::|:|g" + PATH=${PATH//"$path"} + PATH=${PATH//"::"/":"} + printf "%s" $PATH } # @description Strings that began with a ~ are always paths. In diff --git a/no-code b/no-code deleted file mode 100644 index 1013c767e..000000000 --- a/no-code +++ /dev/null @@ -1,536 +0,0 @@ - - - - - - Page not found – Dan Q - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - -
- -
-
- -
- - -
-

It looks like nothing was found at this location. Maybe try one of the links below or a search?

- - - - -

Archives

Try looking in the monthly archives. :)

- - - -
-
-
- -
-
- - -
- -
-
-
    -
  • © Dan Q 1998 – 2023
  • -
  • all original content CC-By-NC except where otherwise stated
  • -
  • made with handwritten ​​ HTML5, CSS3, and love
  • -
-
-
-
- - - - - - From 1a6d8b9097121eb94685003ee8529e7b7fb4ae33 Mon Sep 17 00:00:00 2001 From: Stephan Garland Date: Fri, 10 Feb 2023 12:23:08 -0500 Subject: [PATCH 7/7] fix: identified and fixed bug with parse_asdf_version_file that was adding a leading space --- lib/utils.bash | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/utils.bash b/lib/utils.bash index 3fa7ad687..e4caf5afd 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -27,16 +27,17 @@ fast_tr() { return 1 fi # if bash >= v4, use parameter modification to upper/lower the string - if [ ${BASH_VERSINFO[0]} -gt 3 ]; then + if [ "${BASH_VERSINFO[0]}" -gt 3 ]; then case ${inputArr[1]} in - "[:lower:]") - REPLY="${inputStr^^}" - ;; - "[:upper:]") - REPLY="${inputStr,,}" - ;; - "*") - printf "%s\n" "ERROR: fast_tr() expects [:lower:] and [:upper:] as arguments" + "[:lower:]") + REPLY="${inputStr^^}" + ;; + "[:upper:]") + REPLY="${inputStr,,}" + ;; + "*") + printf "%s\n" "ERROR: fast_tr() expects [:lower:] and [:upper:] as arguments" + ;; esac # and then use parameter substitution to replace characters in the string # if the 4th or 5th elements are not set, the substitution has no effect @@ -365,9 +366,7 @@ parse_asdf_version_file() { if [ -f "$file_path" ]; then local version - # this is causing multiple failures in tests/utils.bash, despite seeming to work identically - version=$(awk -v plugin_name="$plugin_name" '!/^#/ { gsub(/#.*/,"",$0); gsub(/ +$/,"",$0)} $1 == plugin_name {print $NF}' "$file_path") - #version=$(strip_tool_version_comments "$file_path" | grep "^${plugin_name} " | sed -e "s/^${plugin_name} //") + version=$(awk -v plugin_name="$plugin_name" '!/^#/ { gsub(/#.*/,"",$0); gsub(/ +$/,"",$0) } $1 == plugin_name {$1=""; gsub(/^ +/,"",$0); print $0}' "$file_path") if [ -n "$version" ]; then if [[ "$version" == path:* ]]; then util_resolve_user_path "${version#path:}" @@ -888,9 +887,9 @@ remove_path_from_path() { # Output is a new string suitable for assignment to PATH local PATH=$1 local path=$2 - PATH=${PATH//"$path"} + PATH=${PATH//"$path"/} PATH=${PATH//"::"/":"} - printf "%s" $PATH + printf "%s" "$PATH" } # @description Strings that began with a ~ are always paths. In