mirror of
https://github.com/rcaloras/bash-preexec.git
synced 2026-11-03 14:39:43 -09:00
Remove dependency on sed(1) for history processing (#167)
* Remove dependency on sed(1) for history processing
We post-process `history 1`'s output to extract the current command.
This processing needs to strip the leading history number, an optional
`*` character indicating whether the entry was modified (or a space),
and then a space separating character.
We were previously using sed(1) for this, but we can implement an
equivalent transformation using bash's native parameter expansion
syntax.
* Improved the substitution pattern
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
This commit is contained in:
parent
cf2c1db8f6
commit
31ce2f3fdf
1 changed files with 2 additions and 4 deletions
|
|
@ -250,10 +250,8 @@ __bp_preexec_invoke_exec() {
|
|||
fi
|
||||
|
||||
local this_command
|
||||
this_command=$(
|
||||
export LC_ALL=C
|
||||
HISTTIMEFORMAT='' builtin history 1 | sed '1 s/^ *[0-9][0-9]*[* ] //'
|
||||
)
|
||||
this_command=$(LC_ALL=C HISTTIMEFORMAT='' builtin history 1)
|
||||
this_command="${this_command#*[[:digit:]][* ] }"
|
||||
|
||||
# Sanity check to make sure we have something to invoke our function with.
|
||||
if [[ -z "$this_command" ]]; then
|
||||
|
|
|
|||
Loading…
Reference in a new issue