8000 feat(bash-function): Add fzf_git_diff and gd bash alias · musq/dotfiles@6b83289 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 6b83289

Browse files
committed
feat(bash-function): Add fzf_git_diff and gd bash alias
1 parent 6a32ecf commit 6b83289

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/shell/aliases/bash_aliases

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ alias ff="fzf_find_edit"
5050
alias ffg="fzf_grep_edit"
5151

5252
alias ga="fzf_git_add"
53+
alias gd="fzf_git_diff"
5354
alias gl="fzf_git_log"
5455
alias gpx="fzf_git_log_pickaxe"
5556
alias gr="fzf_git_reset"

src/shell/bash_functions

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,30 @@ fzf_git_add() {
101101

102102
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
103103

104+
# Fuzzy git diff
105+
106+
fzf_git_diff() {
107+
108+
# https://stackoverflow.com/a/45111524
109+
110+
local files=$(
111+
git diff "$@" --name-only |
112+
xargs -I '{}' realpath \
113+
--relative-to=. "$(git rev-parse --show-toplevel)"/'{}' |
114+
fzf --ansi --no-sort --height 100% \
115+
--preview "echo {} |
116+
xargs -I@ sh -c 'git d $* --color=always @'"
117+
)
118+
119+
if [[ -n $files ]]; then
120+
# shellcheck disable=SC2086
121+
git d "$@" $files
122+
fi
123+
124+
}
125+
126+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
127+
104128
# Fuzzy search in git logs.
105129

106130
fzf_git_log() {

0 commit comments

Comments
 (0)
0