-
Notifications
You must be signed in to change notification settings - Fork 95
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
Don't clobber $_ #32
Don't clobber $_ #32
Conversation
@HaleTom Thanks for the PR! I'm traveling at the moment, but I'll give this a look in a few days and would love to merge this in. |
- Include $_ on our trap invocation to preserve its value. It should simply forward the previous value so that it's now availble. - Previoulsy it just be set to __bp_preexec_invoke_exec.
@HaleTom Just updated the PR. I think all it needs is to have Give it a try. If it looks good I'll merge 👍 Thanks for your help! |
Not for me:
|
Hmm is that in the same session as your previous version of bash-preexec? bash-preexec won't override a previous version that's already included in the current bash session by checking I just tried testing this PR on a slightly older version of bash 4.4 and I can't recreate :/ elementz@Kashmir:~/git/HaleTom/bash-preexec (fix-dollar_underscore)$ source bash-preexec.sh
elementz@Kashmir:~/git/HaleTom/bash-preexec (fix-dollar_underscore)$ echo $BASH_VERSION
4.4.0(1)-release
elementz@Kashmir:~/git/HaleTom/bash-preexec (fix-dollar_underscore)$ echo $_
4.4.0(1)-release
elementz@Kashmir:~/git/HaleTom/bash-preexec (fix-dollar_underscore)$ : 1 2 3
elementz@Kashmir:~/git/HaleTom/bash-preexec (fix-dollar_underscore)$ echo $_
3
elementz@Kashmir:~/git/HaleTom/bash-preexec (fix-dollar_underscore)$ preexec() { echo "Hello $1"; }
elementz@Kashmir:~/git/HaleTom/bash-preexec (fix-dollar_underscore)$ echo $_
Hello echo $_
3
elementz@Kashmir:~/git/HaleTom/bash-preexec (fix-dollar_underscore)$ Let me see if I can get a version of 4.4.5 to try as well. |
I just double checked - no previous sourcing of I have: |
Hmm okay, I'll add back your preservation of |
What about the test... another PR when I get around to fixing |
Pushed that latest, @HaleTom give it a try locally. The previous test case added was not correct. I removed it in my first commit. I don't see an easy way to test this since it depends on the internal workings of bash to update $_ and the debug trap. Bats is more for unit tests on individual functions. If this patchset works for you, we can give it some more thought regarding a potential test case. |
Bump. @HaleTom any chance to review the latest? |
I haven't forgotten about this - I'm just rebuilding a server and doing the usual Festivus activities. It will likely be two weeks as I'm also moving through 2 countries in that time. Happy New Year! |
@HaleTom no worries. Please give it a try when you get a moment. If anyone else in the community has a sec, please give this a run to see if $_ is being preserved. It's working locally for me, but I want to test across a few other systems and bash versions. |
@HaleTom Bump! Got a sec to test this PR? |
@HaleTom I'm planning on merging this and cutting 3.2. Please check it against your setup when you're available. |
8698348
to
4e033ce
Compare
4e033ce
to
d056f7d
Compare
👍 🍔 🍟 |
@HaleTom feel free to reopen as needed. Thanks for your contribution and opening this. |
$_
should give the last argument of the last command.Currently it gives
__bp_preexec_invoke_exec
:Fix this to produce the expected behaviour:
Note that
bash-bats
currently suffers from the same bug (it's a feature of bash), so the newly added test fails. I have manually tested it and it passes.