Skip to content

Commit

Permalink
feat(bash-function): Add fzf_git_diff and gd bash alias
Browse files Browse the repository at this point in the history
  • Loading branch information
musq committed Aug 2, 2020
1 parent 6a32ecf commit 6b83289
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/shell/aliases/bash_aliases
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ alias ff="fzf_find_edit"
alias ffg="fzf_grep_edit"

alias ga="fzf_git_add"
alias gd="fzf_git_diff"
alias gl="fzf_git_log"
alias gpx="fzf_git_log_pickaxe"
alias gr="fzf_git_reset"
Expand Down
24 changes: 24 additions & 0 deletions src/shell/bash_functions
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,30 @@ fzf_git_add() {

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Fuzzy git diff

fzf_git_diff() {

# https://stackoverflow.com/a/45111524

local files=$(
git diff "$@" --name-only |
xargs -I '{}' realpath \
--relative-to=. "$(git rev-parse --show-toplevel)"/'{}' |
fzf --ansi --no-sort --height 100% \
--preview "echo {} |
xargs -I@ sh -c 'git d $* --color=always @'"
)

if [[ -n $files ]]; then
# shellcheck disable=SC2086
git d "$@" $files
fi

}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Fuzzy search in git logs.

fzf_git_log() {
Expand Down

0 comments on commit 6b83289

Please sign in to comment.