git-rebasei/git-rebasei-editor
Georges Dupéron 88516545a1 Special case for EDITOR=emacs, as I found how to load ansi-colored files.
I should use a git config key git-rebasei.color = always + git-rebasei.editor as an alternative to the autodetecton based on the $EDITOR
2018-03-15 23:47:03 +01:00

51 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
tempfile="$(tempfile)"
# how can I get the --graph with only the desired commits?
if [ "$EDITOR" == "emacs" ]; then
force_color=--color=always
else
force_color=""
fi
esccolor="\(\|`printf '\033\[[0-9;]*m\)'`"
cat "$1" \
| sed -n -e '/^pick/ s/pick \([^ ]*\) .*$/\1/ p' \
| tac \
| xargs -n 1 git log -1 --oneline --decorate --graph --name-status $force_color \
| sed -e "s~^\* ~pick ~" \
> "$tempfile"
# with --graph, if there are actually any pipes, use (+ color handling):
# | sed -e 's~^\([ |\\/*]* \)\([0-9a-f][0-9a-f]* \)~\1pick \2~' \
echo >> "$tempfile"
echo "## Originial git rebase -i data:" >> "$tempfile"
cat "$1" | sed -e 's/^/## /' -e "s/^## $//" -e "s/^## #/#/" >> "$tempfile"
if [ "$EDITOR" == "emacs" ]; then
emacs --eval "(with-current-buffer (find-file \"$tempfile\") (require 'ansi-color) (ansi-color-apply-on-region (point-min) (point-max)) (save-buffer))"
else
editor "$tempfile"
fi
# p, pick
# r, reword
# e, edit
# s, squash
# f, fixup
# x, exec
# d, drop
commands='p\|pick\|r\|reword\|e\|edit\|s\|squash\|f\|fixup\|x\|exec\|d\|drop'
cat "$tempfile" \
| grep -v "^#" \
| grep -v "^ *[|\\/][ |\\/]*[^|\\/*]" \
| tac \
| sed -e 's~^\([ |\\/*]* \)\(\('"$commands"'\)[0-9a-f][0-9a-f]* \)~\2~' \
| tee "$1" >&2