New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Sed improvements #1087
fix: Sed improvements #1087
Conversation
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to remove both ls
and sed
from this line and replace the sed
command with a simpler basename
command. I'm considering adding ls
to the banned commands list as I see it used in some anti-patterns in our codebase. To me it seems like listing files is done better with commands like find
, grep
, and the occasional globbing.
ext_cmds=$( | ||
ls -1 "$ext_cmd_path"/command*.bash 2>/dev/null | | ||
sed "s#$ext_cmd_path/##" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here. Was able to replace a ls
and sed
pipeline with just basename
.
local find_str=$2 | ||
local replace=$3 | ||
printf "%s" "${input//"$find_str"/"$replace"}" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit more code now, but this is much more robust than sed
because it can handle any character in the three input strings and will handle escaping for us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this Bash specific?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I believe so. But this is a Bash file and should only be executed by Bash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Summary
Fixes: #686