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() {
|
jjf() {
|
||||||
# No args → default to `show` so `jjf` alone is a rev browser.
|
# No args → default to `show` so `jjf` alone is a rev browser.
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
@@ -9,13 +15,13 @@ jjf() {
|
|||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
local _jjf_cmd
|
local _jjf_cmd
|
||||||
_jjf_cmd="$(command jjf --emit "$@")" || return $?
|
_jjf_cmd="$(command jjf --emit "$@")"
|
||||||
[ -n "$_jjf_cmd" ] || return 130
|
local _jjf_rc=$?
|
||||||
# Replace the original `jjf …` history entry with the resolved jj command.
|
# Always drop the `jjf …` entry from history; on cancel/error there's
|
||||||
local _jjf_last_offset
|
# nothing to replace it with, on success we add the resolved command below.
|
||||||
_jjf_last_offset=$(history 1 2>/dev/null | awk '{print $1}')
|
_jjf_drop_last_history
|
||||||
if [ -n "$_jjf_last_offset" ]; then
|
if [ $_jjf_rc -ne 0 ] || [ -z "$_jjf_cmd" ]; then
|
||||||
history -d "$_jjf_last_offset" 2>/dev/null || true
|
return $_jjf_rc
|
||||||
fi
|
fi
|
||||||
history -s -- "$_jjf_cmd"
|
history -s -- "$_jjf_cmd"
|
||||||
sh -c "$_jjf_cmd"
|
sh -c "$_jjf_cmd"
|
||||||
|
|||||||
+4
-3
@@ -9,6 +9,10 @@ function jjf
|
|||||||
command jjf $argv
|
command jjf $argv
|
||||||
return $status
|
return $status
|
||||||
end
|
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_cmd (command jjf --emit $argv)
|
||||||
set -l _jjf_status $status
|
set -l _jjf_status $status
|
||||||
if test $_jjf_status -ne 0
|
if test $_jjf_status -ne 0
|
||||||
@@ -18,9 +22,6 @@ function jjf
|
|||||||
return 130
|
return 130
|
||||||
end
|
end
|
||||||
builtin history append -- $_jjf_cmd
|
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
|
sh -c $_jjf_cmd
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user