-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Use parameter substitution instead of dirname
/basename
, where safe to do so
#1926
Conversation
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, @davidpfarrell can you take a look as well?
If its only when its safe, I see no problem with merging this
I'd like to take a day to test this, but at first glance, this looks great. |
550b8e3
to
a0a7f7f
Compare
Hi @cornfeedhobo, did you have a time to test this? |
a0a7f7f
to
6dbb216
Compare
@NoahGorny, the Mac OS X test runners are so slow that |
0d1a8e1
to
d76398d
Compare
Convert `var=${dirname $filename)` to `var="${filename%/*}` in cases where there is no ambiguity. Make sure that the path in `$BASH_IT` is absolute because this path gets embedded in the template `.bash_profile` file if selected by the user.
Convert `var=$(basename $file)` to `var="${file##*/}"`
d76398d
to
470341b
Compare
::: Not me checking this PR twice a day hoping @cornfeedhobo found some time to look through this, nope. ::: |
Sorry y'all. Rough week. Taking a test drive with this today. Will report back shortly. @gaelicWizard @NoahGorny if you have any other PRs that need review and/or testing, this is a good weekend for me to power through them. Ping me in the comments. Thanks!! |
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.
Everything I tested works as expected. Great work here, and my apologies again for the delay in review!
No worries, thanks for the review @cornfeedhobo ❤️ |
Description
Reduce subshells and external commands by using Bash's string processing features instead of
dirname
andbasename
. This basically uses$PWD
,$BASH_SOURCE
, and "${pathname%*/}" and similar constructs to avoid subshells for$(pwd)
,dirname
, andbasename
.Motivation and Context
This is part of a set of patches to reduce usage of subshells and external binaries in Bash It.
The two commits here were part of #1914, but that PR went further than this one and some edge cases were identified which could lead to unintended behavior so those uses were left as-is. Both commits here operate specifically on code which specifies the full path within the same function and thus won't run in to possible issues with user-supplied strings. Merging this PR resolves #1914.
The two edge-cases are:
/
, and/
.Since parameter substitution is string manipulation, it lacks logic to insert
./
for an empty directory name, &c.How Has This Been Tested?
Tested locally, reviewed in part in #1914, and all tests pass.
Types of changes
Checklist:
clean_files.txt
and formatted it usinglint_clean_files.sh
.