Skip to content

Instantly share code, notes, and snippets.

@OliverJAsh
Created August 1, 2019 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OliverJAsh/cb151abe8d46f067b6f48b9dc6a84600 to your computer and use it in GitHub Desktop.
Save OliverJAsh/cb151abe8d46f067b6f48b9dc6a84600 to your computer and use it in GitHub Desktop.
git-pamlog
#!/bin/bash
# https://junegunn.kr/2016/07/fzf-git/
# https://hackernoon.com/be-125-more-efficient-with-git-60556a1ce971
# https://github.com/fcsonline/dotfiles/blob/master/git/gitconfig
# https://github.com/junegunn/fzf/wiki/Examples#git
# TODO: incorporate fix into this?
# TODO: select commits for editing, generate rebase from that
function view () {
# _gitLogLineToHash="echo {} | awk '{ print $1 }'"
_gitLogLineToHash="echo {} | grep -o '[a-f0-9]\{9\}'"
# _gitLogLineToHash="echo {} | grep -o '[a-f0-9]\{9\}' | head -1"
_viewGitLogLine="$_gitLogLineToHash | xargs -I % sh -c 'git show --color=always %'"
# _viewGitLogLine="git show $($_gitLogLineToHash)"
git log --oneline --color=always --decorate "$@" |
fzf --ansi --reverse \
`# When searching, we want to preseve the original log order.` \
--no-sort \
`# Workaround for https://github.com/junegunn/fzf/issues/1567 and https://github.com/junegunn/fzf/issues/1568` \
--no-mouse \
--preview="$_viewGitLogLine" \
--preview-window=down:50% \
--bind="enter:execute:($_viewGitLogLine > /dev/tty)" \
--expect=ctrl-r,ctrl-f
}
function run () {
OUT=($(view "$@"))
KEY=${OUT[0]}
REF=${OUT[1]}
[ -n "$REF" ] && case "$KEY" in
ctrl-r) git rebase --interactive $REF ;;
ctrl-f) git fixit $REF ;;
esac
}
run "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment