From 5a6981e6f7d49ae03413693224d1bde088dde551 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Fri, 17 Dec 2021 09:58:18 +0530 Subject: [PATCH] fish: functions: Use fzf git browse function for git log --- fish/.config/fish/functions/fbr.fish | 24 ------------------------ fish/.config/fish/functions/gl.fish | 21 +++++++++++++++++++-- fish/.config/fish/functions/glp.fish | 3 --- 3 files changed, 19 insertions(+), 29 deletions(-) delete mode 100644 fish/.config/fish/functions/fbr.fish delete mode 100644 fish/.config/fish/functions/glp.fish diff --git a/fish/.config/fish/functions/fbr.fish b/fish/.config/fish/functions/fbr.fish deleted file mode 100644 index f31d117..0000000 --- a/fish/.config/fish/functions/fbr.fish +++ /dev/null @@ -1,24 +0,0 @@ -function fbr --description 'Git browse commits' - set -l log_line_to_hash "echo {} | grep -o '[a-f0-9]\{7\}' | head -1" - set -l view_commit "$log_line_to_hash | xargs -I % sh -c 'git show --color=always % | bat -ldiff'" - set -l view_commit_nvim "$log_line_to_hash | xargs -I % sh -c 'git show %'" - set -l copy_commit_hash "$log_line_to_hash | wl-copy" - set -l git_checkout "$log_line_to_hash | xargs -I % sh -c 'git checkout %'" - set -l open_cmd "open" - - if test (uname) = Linux - set open_cmd "xdg-open" - end - - set github_open "$log_line_to_hash | xargs -I % sh -c '$open_cmd https://github.\$(git config remote.origin.url | cut -f2 -d. | tr \':\' /)/commit/%'" - - git log --color=always --format='%C(auto)%h%d %s %C(green)%C(bold)%cr% C(blue)%an' | \ - fzf --exact --no-sort --reverse --tiebreak=index --no-multi --ansi \ - --preview="$view_commit" \ - --header="ENTER to view, CTRL-Y to copy hash, CTRL-O to open on GitHub, CTRL-X to checkout, CTRL-C to exit" \ - --bind "enter:execute:$view_commit_nvim | nvim -R -" \ - --bind "ctrl-y:execute:$copy_commit_hash" \ - --bind "ctrl-x:execute:$git_checkout" \ - --bind "ctrl-o:execute:$github_open" \ - --bind "ctrl-d:half-page-down,ctrl-u:half-page-up,ctrl-n:preview-down,ctrl-p:preview-up,ctrl-f:preview-page-down,ctrl-b:preview-page-up" -end diff --git a/fish/.config/fish/functions/gl.fish b/fish/.config/fish/functions/gl.fish index 824c6da..a50605a 100644 --- a/fish/.config/fish/functions/gl.fish +++ b/fish/.config/fish/functions/gl.fish @@ -1,4 +1,21 @@ -function gl - git log --stat -n 100 +function gl --description 'Git browse commits' + set -l log_line_to_hash "echo {} | grep -o '[a-f0-9]\{7\}' | head -1" + set -l view_commit "$log_line_to_hash | xargs -I % sh -c 'git show --color=always % | bat -ldiff'" + set -l view_commit_nvim "$log_line_to_hash | xargs -I % sh -c 'git show %'" + set -l copy_commit_hash "$log_line_to_hash | wl-copy" + set -l git_checkout "$log_line_to_hash | xargs -I % sh -c 'git checkout %'" + set -l open_cmd "xdg-open" + + set github_open "$log_line_to_hash | xargs -I % sh -c '$open_cmd https://github.\$(git config remote.origin.url | cut -f2 -d. | tr \':\' /)/commit/%'" + + git log --color=always --format='%C(auto)%h%d %s %C(green)%C(bold)%cr% C(blue)%an' | \ + fzf --exact --no-sort --reverse --tiebreak=index --no-multi --ansi \ + --preview="$view_commit" \ + --header="ENTER to view, CTRL-Y to copy hash, CTRL-O to open on GitHub, CTRL-X to checkout, CTRL-C to exit" \ + --bind "enter:execute:$view_commit_nvim | nvim -R -" \ + --bind "ctrl-y:execute:$copy_commit_hash" \ + --bind "ctrl-x:execute:$git_checkout" \ + --bind "ctrl-o:execute:$github_open" \ + --bind "ctrl-d:half-page-down,ctrl-u:half-page-up,ctrl-n:preview-down,ctrl-p:preview-up,ctrl-f:preview-page-down,ctrl-b:preview-page-up" end diff --git a/fish/.config/fish/functions/glp.fish b/fish/.config/fish/functions/glp.fish deleted file mode 100644 index ab9a7b2..0000000 --- a/fish/.config/fish/functions/glp.fish +++ /dev/null @@ -1,3 +0,0 @@ -function glp - git log -p --stat -n 100 -end