Skip to content

Commit

Permalink
Update bash-preexec to 0.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
rcaloras committed Feb 13, 2017
1 parent 42fc603 commit 268b8a5
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions bashhub/shell/deps/bash-preexec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Author: Ryan Caloras ([email protected])
# Forked from Original Author: Glyph Lefkowitz
#
# V0.3.1
# V0.3.2
#

# General Usage:
Expand Down Expand Up @@ -43,10 +43,11 @@ __bp_imported="defined"
# Should be available to each precmd and preexec
# functions, should they want it.
__bp_last_ret_value="$?"
__bp_last_argument_prev_command="$_"

# Command to set our preexec trap. It's invoked once via
# PROMPT_COMMAND and then removed.
__bp_trap_install_string="trap '__bp_preexec_invoke_exec' DEBUG;"
__bp_trap_install_string="trap '__bp_preexec_invoke_exec \"\$_\"' DEBUG;"

# Remove ignorespace and or replace ignoreboth from HISTCONTROL
# so we can accurately invoke preexec with a command from our
Expand Down Expand Up @@ -97,7 +98,7 @@ __bp_precmd_invoke_cmd() {
# Only execute this function if it actually exists.
# Test existence of functions with: declare -[Ff]
if type -t "$precmd_function" 1>/dev/null; then
__bp_set_ret_value $__bp_last_ret_value
__bp_set_ret_value "$__bp_last_ret_value" "$__bp_last_argument_prev_command"
$precmd_function
fi
done
Expand Down Expand Up @@ -137,6 +138,11 @@ __bp_in_prompt_command() {
# interactively, and invoke 'preexec' if so.
__bp_preexec_invoke_exec() {


# Save the contents of $_ so that it can be restored later on.
# https://stackoverflow.com/questions/40944532/bash-preserve-in-a-debug-trap#40944702
__bp_last_argument_prev_command="$1"

# Checks if the file descriptor is not standard out (i.e. '1')
# __bp_delay_install checks if we're in test. Needed for bats to run.
# Prevents preexec from being invoked for functions in PS1
Expand Down Expand Up @@ -194,6 +200,9 @@ __bp_preexec_invoke_exec() {
$preexec_function "$this_command"
fi
done

# Restore the last argument of the last executed command
: "$__bp_last_argument_prev_command"
}

# Returns PROMPT_COMMAND with a semicolon appended
Expand Down Expand Up @@ -253,7 +262,7 @@ __bp_install() {
# Install our hooks in PROMPT_COMMAND to allow our trap to know when we've
# actually entered something.
PROMPT_COMMAND="__bp_precmd_invoke_cmd; ${existing_prompt_command} __bp_interactive_mode;"
trap '__bp_preexec_invoke_exec' DEBUG;
eval "$__bp_trap_install_string"

# Add two functions to our arrays for convenience
# of definition.
Expand Down

0 comments on commit 268b8a5

Please sign in to comment.