fix(history): drop jjf entry on cancel/error paths too
Previously, the original `jjf …` invocation only got dropped from history on successful confirm. A cancelled or errored picker left a useless `jjf …` entry behind. Now bash drops it unconditionally via `_jjf_drop_last_history`; fish arms the postexec hook before the `--emit` call so the deletion happens regardless of exit path.
This commit is contained in:
2 files changed
+17
-10
No files matched your search
+13
-7
@@ -1,3 +1,9 @@
|
||||
_jjf_drop_last_history() {
|
||||
local _off
|
||||
_off=$(history 1 2>/dev/null | awk '{print $1}')
|
||||
[ -n "$_off" ] && history -d "$_off" 2>/dev/null || true
|
||||
}
|
||||
|
||||
jjf() {
|
||||
# No args → default to `show` so `jjf` alone is a rev browser.
|
||||
if [ $# -eq 0 ]; then
|
||||
@@ -9,13 +15,13 @@ jjf() {
|
||||
return $?
|
||||
fi
|
||||
local _jjf_cmd
|
||||
_jjf_cmd="$(command jjf --emit "$@")" || return $?
|
||||
[ -n "$_jjf_cmd" ] || return 130
|
||||
# Replace the original `jjf …` history entry with the resolved jj command.
|
||||
local _jjf_last_offset
|
||||
_jjf_last_offset=$(history 1 2>/dev/null | awk '{print $1}')
|
||||
if [ -n "$_jjf_last_offset" ]; then
|
||||
history -d "$_jjf_last_offset" 2>/dev/null || true
|
||||
_jjf_cmd="$(command jjf --emit "$@")"
|
||||
local _jjf_rc=$?
|
||||
# Always drop the `jjf …` entry from history; on cancel/error there's
|
||||
# nothing to replace it with, on success we add the resolved command below.
|
||||
_jjf_drop_last_history
|
||||
if [ $_jjf_rc -ne 0 ] || [ -z "$_jjf_cmd" ]; then
|
||||
return $_jjf_rc
|
||||
fi
|
||||
history -s -- "$_jjf_cmd"
|
||||
sh -c "$_jjf_cmd"
|
||||
|
||||
+4
-3
@@ -9,6 +9,10 @@ function jjf
|
||||
command jjf $argv
|
||||
return $status
|
||||
end
|
||||
# Arm the postexec hook *before* invoking the picker so the original
|
||||
# `jjf …` entry is removed from history on any exit path (cancel, error,
|
||||
# or success). Fish records function invocations *after* return.
|
||||
set -g _jjf_pending_swap 1
|
||||
set -l _jjf_cmd (command jjf --emit $argv)
|
||||
set -l _jjf_status $status
|
||||
if test $_jjf_status -ne 0
|
||||
@@ -18,9 +22,6 @@ function jjf
|
||||
return 130
|
||||
end
|
||||
builtin history append -- $_jjf_cmd
|
||||
# Signal the postexec hook to remove the literal `jjf …` entry that fish
|
||||
# is about to record (fish records function invocations *after* return).
|
||||
set -g _jjf_pending_swap 1
|
||||
sh -c $_jjf_cmd
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user