Skip to content

Commit

Permalink
Improved the substitution pattern
Browse files Browse the repository at this point in the history
The history number is printed as "%5d" so we need to handle all possible
columns.

    declare -a lines=(
        "10000  history 1"
        " 1000  history 1"
        "    1  history 1"
        " 1000* history 1"
        " 1000   history 1"
    )

    for line in "${lines[@]}"; do
        echo "${line#*[[:digit:]][* ] }"
    done
  • Loading branch information
jparise committed Jan 13, 2025
1 parent c853a7e commit 11aba65
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion bash-preexec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ __bp_preexec_invoke_exec() {

local this_command
this_command=$(LC_ALL=C HISTTIMEFORMAT='' builtin history 1)
this_command="${this_command# *[[:digit:]]*[* ] }"
this_command="${this_command#*[[:digit:]][* ] }"

# Sanity check to make sure we have something to invoke our function with.
if [[ -z "$this_command" ]]; then
Expand Down

0 comments on commit 11aba65

Please sign in to comment.