Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
[ -z `which emacsclient 2>&1` ] && { echo 'emacsclient not found' >&2; exit 1; }
[ -z `which git 2>&1` ] && { echo 'git not found' >&2; exit 1; }
[ -z `which peco 2>&1` ] && { echo 'peco not found' >&2; exit 1; }
function open_emacsclient {
if [ $# -eq 0 ]; then
TMP_FILE=`mktemp /tmp/emacsclient.XXXXXX`
cat > $TMP_FILE
sexp=$(cat <<EOF
(let ((b (create-file-buffer "*stdin*")))
(switch-to-buffer b)
(insert-file-contents "${TMP_FILE}")
(delete-file "${TMP_FILE}")
(diff-mode))
EOF
)
emacsclient -a emacs -e "$sexp"
fi
}
# copy from https://gist.github.com/fukajun/edea3c4f36e37bf36e8b
hash=`git log --graph --pretty=format:'%d %an: %s %ar %h' | peco | awk -F ' ' '{ print $NF }'`
git show $hash | open_emacsclient
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment