Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
fix: Sed improvements (#1087)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stratus3D authored Nov 15, 2021
1 parent 4116284 commit 4b93bc8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
17 changes: 7 additions & 10 deletions lib/commands/command-help.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,17 @@ EOF
}

asdf_extension_cmds() {
local plugins_path ext_cmd_path ext_cmds plugin
local plugins_path plugin_path ext_cmd_path ext_cmds plugin
plugins_path="$(get_plugin_path)"
# use find instead of ls -1
# shellcheck disable=SC2012
for plugin in $(ls -1 "$plugins_path" 2>/dev/null | sed "s#^$plugins_path/##"); do
ext_cmd_path="$plugins_path/$plugin/lib/commands"
ext_cmds=$(
ls -1 "$ext_cmd_path"/command*.bash 2>/dev/null |
sed "s#$ext_cmd_path/##"
)
for plugin_path in "$plugins_path"/*; do
plugin="$(basename "$plugin_path")"
ext_cmd_path="$plugin_path/lib/commands"
ext_cmds="$(find "$ext_cmd_path" -name "command*.bash")"
if [[ -n $ext_cmds ]]; then
printf "\\nPLUGIN %s\\n" "$plugin"
for ext_cmd in $ext_cmds; do
sed "s/-/ /g;s/.bash//;s/command-*/ asdf $plugin/;" <<<"$ext_cmd"
ext_cmd_name="$(basename "$ext_cmd")"
sed "s/-/ /g;s/.bash//;s/command-*/ asdf $plugin/;" <<<"$ext_cmd_name"
done | sort
fi
done
Expand Down
21 changes: 19 additions & 2 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ get_executable_path() {
check_if_version_exists "$plugin_name" "$version"

if [ "$version" = "system" ]; then
path=$(sed -e "s|$(asdf_data_dir)/shims||g; s|::|:|g" <<<"$PATH")
path=$(remove_path_from_path "$PATH" "$(asdf_data_dir)/shims")
cmd=$(basename "$executable_path")
cmd_path=$(PATH=$path command -v "$cmd" 2>&1)
# shellcheck disable=SC2181
Expand Down Expand Up @@ -755,7 +755,7 @@ with_shim_executable() {

run_within_env() {
local path
path=$(sed -e "s|$(asdf_data_dir)/shims||g; s|::|:|g" <<<"$PATH")
path=$(remove_path_from_path "$PATH" "$(asdf_data_dir)/shims")

executable_path=$(PATH=$path command -v "$shim_name")

Expand Down Expand Up @@ -806,3 +806,20 @@ with_shim_executable() {

return 126
}

substitute() {
# Use Bash substituion rather than sed as it will handle escaping of all
# strings for us.
local input=$1
local find_str=$2
local replace=$3
printf "%s" "${input//"$find_str"/"$replace"}"
}

remove_path_from_path() {
# A helper function for removing an arbitrary path from the PATH variable.
# Output is a new string suitable for assignment to PATH
local PATH=$1
local path=$2
substitute "$PATH" "$path" "" | sed -e "s|::|:|g"
}

0 comments on commit 4b93bc8

Please sign in to comment.