diff --git a/aliases.sh b/aliases.sh index 7c33ffd..cd12369 100755 --- a/aliases.sh +++ b/aliases.sh @@ -83,7 +83,6 @@ alias venv='source .venv/bin/activate' # Run fzf with file preview alias pf="fzf --preview='BAT_STYLE='header,changes' bat --color=always {}' --bind shift-up:preview-page-up,shift-down:preview-page-down" -alias fgitlog="git log --oneline | fzf --multi --preview 'git -p show --color=always {+1}'" # dvc alias dst='dvc status' diff --git a/functions.sh b/functions.sh index b8e9961..3db0875 100755 --- a/functions.sh +++ b/functions.sh @@ -300,6 +300,28 @@ function retry() { # Creats a gitignore for the given argument (e.g. python, cpp, etc) function gi() { curl -sL https://www.toptal.com/developers/gitignore/api/$@; } +# Runs git log with fzf with preview +compdef _git fgitlog=git-log +function fgitlog() { + git log --oneline $@ | fzf --multi --preview 'git -p show --color=always {+1}' --preview-window=right,60% +} + +compdef _git fgitlog=git-log +git-commit-show() { + git log --graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr" | + fzf --ansi --no-sort --reverse --tiebreak=index --preview \ + 'f() { + set -- $(echo -- "$@" | grep -o "[a-f0-9]\{7\}") + [ $# -eq 0 ] || git show --color=always $1 + } + f {}' \ + --bind "j:down,k:up,alt-j:preview-down,alt-k:preview-up,ctrl-f:preview-page-down,ctrl-b:preview-page-up,q:abort,ctrl-m:execute: + (grep -o '[a-f0-9]\{7\}' | head -1 | + xargs -I % sh -c 'git show --color=always % | less -R') << 'FZF-EOF' + {} FZF-EOF" \ + --preview-window=right:60% +} + # dotfiles user functions if [[ -f $HOME/.dotfiles_functions ]]; then source "$HOME/.dotfiles_functions"