Skip to content

Commit c853a7e

Browse files
committed
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.
1 parent 8926de0 commit c853a7e

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

bash-preexec.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,8 @@ __bp_preexec_invoke_exec() {
250250
fi
251251

252252
local this_command
253-
this_command=$(
254-
export LC_ALL=C
255-
HISTTIMEFORMAT='' builtin history 1 | sed '1 s/^ *[0-9][0-9]*[* ] //'
256-
)
253+
this_command=$(LC_ALL=C HISTTIMEFORMAT='' builtin history 1)
254+
this_command="${this_command# *[[:digit:]]*[* ] }"
257255

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

0 commit comments

Comments
 (0)