From 720180b9765a39c4a0d799a9db16e79221041d10 Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Sun, 12 Jan 2025 15:58:16 -0500 Subject: [PATCH] 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. --- bash-preexec.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bash-preexec.sh b/bash-preexec.sh index 641346a..404f12e 100644 --- a/bash-preexec.sh +++ b/bash-preexec.sh @@ -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