From 49579b2d1f620db6a71d070b40416c1af8a32168 Mon Sep 17 00:00:00 2001 From: Tim <45259958+carlfriedrich@users.noreply.github.com> Date: Sat, 17 Sep 2022 18:16:30 +0200 Subject: [PATCH] Do not return an error in log, diff and stash show (#236) fzf has the following exit codes: 0 Normal exit 1 No match 2 Error 130 Interrupted with CTRL-C or ESC The forgit functions "log", "diff" and "stash show" are designed to display information, not to perform any action. Hence the fzf exit code 130 should not be interpreted as an error, it is normal exit behavior. Exclude this error value and return 0 in this case. --- conf.d/forgit.plugin.fish | 14 ++++++++++++++ forgit.plugin.zsh | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/conf.d/forgit.plugin.fish b/conf.d/forgit.plugin.fish index a499335..58ced23 100644 --- a/conf.d/forgit.plugin.fish +++ b/conf.d/forgit.plugin.fish @@ -93,6 +93,11 @@ function forgit::log -d "git commit viewer" eval "git log $graph --color=always --format='$log_format' $argv $forgit_emojify" | env FZF_DEFAULT_OPTS="$opts" fzf + + set fzf_exit_code $status + # exit successfully on 130 (ctrl-c/esc) + [ $fzf_exit_code = 130 ] && return 0 + return $fzf_exit_code end function forgit::extract_file --argument-names 'path' @@ -144,6 +149,10 @@ function forgit::diff -d "git diff viewer" --argument-names arg1 arg2 expand -t 8 | env FZF_DEFAULT_OPTS="$opts" fzf + set fzf_exit_code $status + # exit successfully on 130 (ctrl-c/esc) + [ $fzf_exit_code = 130 ] && return 0 + return $fzf_exit_code end # git add selector @@ -347,6 +356,11 @@ function forgit::stash::show -d "git stash viewer" $FORGIT_STASH_FZF_OPTS " git stash list | env FZF_DEFAULT_OPTS="$opts" fzf + + set fzf_exit_code $status + # exit successfully on 130 (ctrl-c/esc) + [ $fzf_exit_code = 130 ] && return 0 + return $fzf_exit_code end # git clean selector diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index a2902dc..b4fbb15 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -53,6 +53,10 @@ forgit::log() { log_format=${FORGIT_GLO_FORMAT:-$forgit_log_format} eval "git log $graph --color=always --format='$log_format' $* $forgit_emojify" | FZF_DEFAULT_OPTS="$opts" fzf + fzf_exit_code=$? + # exit successfully on 130 (ctrl-c/esc) + [[ $fzf_exit_code == 130 ]] && return 0 + return $fzf_exit_code } # git diff viewer @@ -89,6 +93,10 @@ forgit::diff() { eval "git diff --name-status $commits -- ${files[*]} | sed -E 's/^([[:alnum:]]+)[[:space:]]+(.*)$/[\1]\t\2/'" | sed 's/\t/ -> /2' | expand -t 8 | FZF_DEFAULT_OPTS="$opts" fzf + fzf_exit_code=$? + # exit successfully on 130 (ctrl-c/esc) + [[ $fzf_exit_code == 130 ]] && return 0 + return $fzf_exit_code } # git add selector @@ -157,6 +165,10 @@ forgit::stash::show() { $FORGIT_STASH_FZF_OPTS " git stash list | FZF_DEFAULT_OPTS="$opts" fzf + fzf_exit_code=$? + # exit successfully on 130 (ctrl-c/esc) + [[ $fzf_exit_code == 130 ]] && return 0 + return $fzf_exit_code } # git clean selector