commit 88516545a1f37494c6067e58159ffc0b19ba78af
parent 3d2a2f2ba641f5554ad3a1ae91c97f6d855f26d4
Author: Georges Dupéron <georges.duperon@gmail.com>
Date: Thu, 15 Mar 2018 23:46:21 +0100
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
Diffstat:
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/git-rebasei-editor b/git-rebasei-editor
@@ -4,23 +4,33 @@ 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 \
- | sed -e 's~^\* \([0-9a-f][0-9a-f]* \)~pick \1~' \
- > "$tempfile"
+ | 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:
+# 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/^/#/' >> "$tempfile"
-
-echo "# GIT file: $1" >> "$tempfile"
-
-editor "$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