Browse Source

fzgit: fix paging to less

DanielFGray 2 years ago
parent
commit
9a4a6cda62
1 changed files with 8 additions and 10 deletions
  1. 8
    10
      fzgit

+ 8
- 10
fzgit View File

@@ -193,7 +193,7 @@ git_log() { # {{{
193 193
   local show="git show --color=always \"\$(grep -m1 -o \"[a-f0-9]\{7\}\" <<< {})\""
194 194
   fzf --prompt='log' -e --no-sort --tiebreak=index \
195 195
     --preview-window=up \
196
-    --bind="enter:execute:$show" \
196
+    --bind="enter:execute:$show | less -R" \
197 197
     --preview="$show" \
198 198
   < <(git log --graph --color=always \
199 199
     --format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@")
@@ -239,8 +239,9 @@ git_stash() { # {{{
239 239
   header='use ctrl-d to show a diff or ctrl-b to create a new branch'
240 240
   while out=$(git stash list \
241 241
       --pretty="%C(yellow)%h %>(14)%Cgreen%cr %C(blue)%gs" |
242
-    fzf --prompt='stash' --no-sort --header="$header"
242
+    fzf --prompt='stash' --no-sort --header="$header" \
243 243
       --query="$query" --print-query \
244
+      --preview='git diff --color {1}' \
244 245
       --expect=ctrl-d,ctrl-b)
245 246
   do
246 247
     mapfile -t response <<< "$out"
@@ -249,14 +250,11 @@ git_stash() { # {{{
249 250
     sha="${response[-1]}"
250 251
     sha="${sha%% *}"
251 252
     [[ -z "$sha" ]] && continue
252
-    if [[ "$key" == 'ctrl-d' ]]; then
253
-      PAGER='less' git diff "$sha"
254
-    elif [[ "$key" == 'ctrl-b' ]]; then
255
-      git stash branch "stash-$sha" "$sha"
256
-      break;
257
-    else
258
-      PAGER='less' git stash show -p "$sha"
259
-    fi
253
+    case "$key" in
254
+      'ctrl-d') git diff "$sha" --color=always | less -R ;;
255
+      'ctrl-b') git stash branch "stash-$sha" "$sha" ;;
256
+      *) git stash show -p "$sha" --color=always | less -R  ;;
257
+    esac
260 258
   done
261 259
 }
262 260
 # }}}

Loading…
Cancel
Save