diff options
author | Toby Vincent <tobyv13@gmail.com> | 2021-06-26 15:29:40 -0500 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2021-06-26 15:29:40 -0500 |
commit | 4ebbfb0874c59ff0144ffee47c252b5eed167012 (patch) | |
tree | d12b687d4e975321e460ad3394cfea98a62b276e /bat/shell | |
parent | f1385c8594e303e0cd11adfec81acbc701f85e86 (diff) |
feat: added bat
Diffstat (limited to 'bat/shell')
-rw-r--r-- | bat/shell/keybindings.bash | 65 | ||||
-rw-r--r-- | bat/shell/keybindings.zsh | 77 |
2 files changed, 142 insertions, 0 deletions
diff --git a/bat/shell/keybindings.bash b/bat/shell/keybindings.bash new file mode 100644 index 0000000..c227c29 --- /dev/null +++ b/bat/shell/keybindings.bash @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +is_in_git_repo() { + git rev-parse HEAD > /dev/null 2>&1 +} + +fzf-down() { + fzf --height 50% --min-height 20 --border --bind ctrl-/:toggle-preview "$@" +} + +_gf() { + is_in_git_repo || return + git -c color.status=always status --short | + fzf-down -m --ansi --nth 2..,.. \ + --preview '(git diff --color=always -- {-1} | sed 1,4d; cat {-1})' | + cut -c4- | sed 's/.* -> //' +} + +_gb() { + is_in_git_repo || return + git branch -a --color=always | grep -v '/HEAD\s' | sort | + fzf-down --ansi --multi --tac --preview-window right:70% \ + --preview 'git log --oneline --graph --date=short --color=always --pretty="format:%C(auto)%cd %h%d %s" $(sed s/^..// <<< {} | cut -d" " -f1)' | + sed 's/^..//' | cut -d' ' -f1 | + sed 's#^remotes/##' +} + +_gt() { + is_in_git_repo || return + git tag --sort -version:refname | + fzf-down --multi --preview-window right:70% \ + --preview 'git show --color=always {}' +} + +_gh() { + is_in_git_repo || return + git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --graph --color=always | + fzf-down --ansi --no-sort --reverse --multi --bind 'ctrl-s:toggle-sort' \ + --header 'Press CTRL-S to toggle sort' \ + --preview 'grep -o "[a-f0-9]\{7,\}" <<< {} | xargs git show --color=always' | + grep -o "[a-f0-9]\{7,\}" +} + +_gr() { + is_in_git_repo || return + git remote -v | awk '{print $1 "\t" $2}' | uniq | + fzf-down --tac \ + --preview 'git log --oneline --graph --date=short --pretty="format:%C(auto)%cd %h%d %s" {1}' | + cut -d$'\t' -f1 +} + +_gs() { + is_in_git_repo || return + git stash list | fzf-down --reverse -d: --preview 'git show --color=always {1}' | + cut -d: -f1 +} + +if [[ $- =~ i ]]; then + bind '"\er": redraw-current-line' + bind '"\C-g\C-f": "$(_gf)\e\C-e\er"' + bind '"\C-g\C-b": "$(_gb)\e\C-e\er"' + bind '"\C-g\C-t": "$(_gt)\e\C-e\er"' + bind '"\C-g\C-h": "$(_gh)\e\C-e\er"' + bind '"\C-g\C-r": "$(_gr)\e\C-e\er"' + bind '"\C-g\C-s": "$(_gs)\e\C-e\er"' +fi
\ No newline at end of file diff --git a/bat/shell/keybindings.zsh b/bat/shell/keybindings.zsh new file mode 100644 index 0000000..0a6c631 --- /dev/null +++ b/bat/shell/keybindings.zsh @@ -0,0 +1,77 @@ +#!/usr/bin/env zsh + +### Key bindings for git with fzf (https://junegunn.kr/2016/07/fzf-git/) + +is_in_git_repo() { + git rev-parse HEAD > /dev/null 2>&1 +} + +fzf-down() { + fzf --height 50% --min-height 20 --border --bind ctrl-/:toggle-preview "$@" +} + +_gf() { + is_in_git_repo || return + git -c color.status=always status --short | + fzf-down -m --ansi --nth 2..,.. \ + --preview '(git diff --color=always -- {-1} | sed 1,4d; cat {-1})' | + cut -c4- | sed 's/.* -> //' +} + +_gb() { + is_in_git_repo || return + git branch -a --color=always | grep -v '/HEAD\s' | sort | + fzf-down --ansi --multi --tac --preview-window right:70% \ + --preview 'git log --oneline --graph --date=short --color=always --pretty="format:%C(auto)%cd %h%d %s" $(sed s/^..// <<< {} | cut -d" " -f1)' | + sed 's/^..//' | cut -d' ' -f1 | + sed 's#^remotes/##' +} + +_gt() { + is_in_git_repo || return + git tag --sort -version:refname | + fzf-down --multi --preview-window right:70% \ + --preview 'git show --color=always {}' +} + +_gh() { + is_in_git_repo || return + git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --graph --color=always | + fzf-down --ansi --no-sort --reverse --multi --bind 'ctrl-s:toggle-sort' \ + --header 'Press CTRL-S to toggle sort' \ + --preview 'grep -o "[a-f0-9]\{7,\}" <<< {} | xargs git show --color=always' | + grep -o "[a-f0-9]\{7,\}" +} + +_gr() { + is_in_git_repo || return + git remote -v | awk '{print $1 "\t" $2}' | uniq | + fzf-down --tac \ + --preview 'git log --oneline --graph --date=short --pretty="format:%C(auto)%cd %h%d %s" {1}' | + cut -d$'\t' -f1 +} + +_gs() { + is_in_git_repo || return + git stash list | fzf-down --reverse -d: --preview 'git show --color=always {1}' | + cut -d: -f1 +} + +join-lines() { + local item + while read item; do + echo -n "${(q)item} " + done +} + +bind-git-helper() { + local c + for c in $@; do + eval "fzf-g$c-widget() { local result=\$(_g$c | join-lines); zle reset-prompt; LBUFFER+=\$result }" + eval "zle -N fzf-g$c-widget" + eval "bindkey '^g^$c' fzf-g$c-widget" + done +} + +bind-git-helper f b t r h s +unset -f bind-git-helper
\ No newline at end of file |