summaryrefslogtreecommitdiffstats
path: root/src/init
diff options
context:
space:
mode:
authorEtienne Mabille <etienne.mabille-ext@transport.alstom.com>2019-12-19 22:20:44 +0100
committerMatan Kushner <hello@matchai.me>2019-12-19 16:20:44 -0500
commit879649d5422ad99d229e1f089f1f7327423f5ca4 (patch)
tree4eadd16b805be34d72fd592f4b173beece4182da /src/init
parentaab35674d2ca94a5d5debaf1caa5883e7c65bff3 (diff)
fix(bash): save and restore "$_" (#753)
Diffstat (limited to 'src/init')
-rw-r--r--src/init/starship.bash15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/init/starship.bash b/src/init/starship.bash
index da02f6e42..cf7b30db6 100644
--- a/src/init/starship.bash
+++ b/src/init/starship.bash
@@ -14,11 +14,16 @@
# Will be run before *every* command (even ones in pipes!)
starship_preexec() {
+ # Save previous command's last argument, otherwise it will be set to "starship_preexec"
+ local PREV_LAST_ARG=$1
+
# Avoid restarting the timer for commands in the same pipeline
if [ "$PREEXEC_READY" = "true" ]; then
PREEXEC_READY=false
STARSHIP_START_TIME=$(date +%s)
fi
+
+ : "$PREV_LAST_ARG"
}
# Will be run before the prompt is drawn
@@ -44,7 +49,7 @@ starship_precmd() {
# If the user appears to be using https://github.com/rcaloras/bash-preexec,
# then hook our functions into their framework.
if [[ $preexec_functions ]]; then
- preexec_functions+=(starship_preexec)
+ preexec_functions+=('starship_preexec "$_"')
precmd_functions+=(starship_precmd)
else
# We want to avoid destroying an existing DEBUG hook. If we detect one, create
@@ -52,12 +57,12 @@ else
# re-trap DEBUG to use this new function. This prevents a trap clobber.
dbg_trap="$(trap -p DEBUG | cut -d' ' -f3 | tr -d \')"
if [[ -z "$dbg_trap" ]]; then
- trap starship_preexec DEBUG
- elif [[ "$dbg_trap" != "starship_preexec" && "$dbg_trap" != "starship_preexec_all" ]]; then
+ trap 'starship_preexec "$_"' DEBUG
+ elif [[ "$dbg_trap" != 'starship_preexec "$_"' && "$dbg_trap" != 'starship_preexec_all "$_"' ]]; then
function starship_preexec_all(){
- $dbg_trap; starship_preexec
+ local PREV_LAST_ARG=$1 ; $dbg_trap; starship_preexec; : "$PREV_LAST_ARG";
}
- trap starship_preexec_all DEBUG
+ trap 'starship_preexec_all "$_"' DEBUG
fi
# Finally, prepare the precmd function and set up the start time.