mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
fix: Sed improvements (#1087)
This commit is contained in:
parent
41162849cf
commit
4b93bc81aa
@ -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
|
||||
|
@ -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
|
||||
@ -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")
|
||||
|
||||
@ -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"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user