From 8c7bb10e56350e015f4214199063b1f53b2d16fc Mon Sep 17 00:00:00 2001 From: Mikhail Pogretskiy Date: Wed, 11 Mar 2020 13:56:28 +0700 Subject: [PATCH] rc git: Make git next/prev-hunk behavior consistent with search command --- rc/tools/git.kak | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/rc/tools/git.kak b/rc/tools/git.kak index 9ddcfce8..e355370d 100644 --- a/rc/tools/git.kak +++ b/rc/tools/git.kak @@ -196,6 +196,7 @@ define-command -params 1.. \ shift if [ $# -lt 1 ]; then + echo "fail 'no git hunks found'" exit fi @@ -212,6 +213,7 @@ define-command -params 1.. \ prev_line="$line" done echo "set-option buffer git_hunk_list $hunks" + hunks=${hunks#* } else hunks=${kak_opt_git_hunk_list#* } fi @@ -227,10 +229,26 @@ define-command -params 1.. \ fi done - if [ "$direction" = "next" ] && [ -n "$next_hunk" ]; then - echo "select $next_hunk.1,$next_hunk.1" - elif [ "$direction" = "prev" ] && [ -n "$prev_hunk" ]; then - echo "select $prev_hunk.1,$prev_hunk.1" + if [ "$direction" = "next" ]; then + if [ -z "$next_hunk" ]; then + next_hunk=${hunks%% *} + wrapped=true + fi + if [ -n "$next_hunk" ]; then + echo "select $next_hunk.1,$next_hunk.1" + fi + elif [ "$direction" = "prev" ]; then + if [ -z "$prev_hunk" ]; then + wrapped=true + prev_hunk=${hunks##* } + fi + if [ -n "$prev_hunk" ]; then + echo "select $prev_hunk.1,$prev_hunk.1" + fi + fi + + if [ "$wrapped" = true ]; then + echo "echo -markup '{Information}git hunk search wrapped around buffer'" fi }