Skip to content
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

Merged
merged 2 commits into from Nov 15, 2021
Merged

fix: Sed improvements #1087

merged 2 commits into from Nov 15, 2021

Conversation

Stratus3D
Copy link
Member

Summary

  • fix: Use bash instead of sed for updating PATH environment variable
  • fix: Remove unnecessary ls and sed commands

Fixes: #686

@Stratus3D Stratus3D requested a review from a team as a code owner November 5, 2021 20:39
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
Copy link
Member Author

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/##"
)
Copy link
Member Author

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"}"
}
Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this Bash specific?

Copy link
Member Author

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.

@Stratus3D Stratus3D changed the title Sed improvements fix: Sed improvements Nov 5, 2021
Copy link
Contributor

@jthegedus jthegedus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Verify sed commands are correct
2 participants