Skip to content

Instantly share code, notes, and snippets.

@sebastiencs
Created June 26, 2017 05:51
Show Gist options
  • Save sebastiencs/f03129ade6a699f7c596e13b0aae31f2 to your computer and use it in GitHub Desktop.
Save sebastiencs/f03129ade6a699f7c596e13b0aae31f2 to your computer and use it in GitHub Desktop.
magit-log
(require 'dash)
(require 's)
(require 'loop)
(require 'icons-in-terminal)
(defun my-char-at-point (&optional p)
"P."
(let ((point (or p (point))))
(if (< point (point-max)) (buffer-substring-no-properties point (1+ point))
"")))
(defun my-magit-log-icon ()
"."
(interactive)
(when (derived-mode-p 'magit-log-mode)
(with-silent-modifications
(loop-for-each-line
(when (and (not (s-equals? " " (my-char-at-point)))
(s-matches? "[*|]" (my-char-at-point (+ (point) 8))))
(right-char 8)
(while (s-matches? "[*|[:space:]]" (my-char-at-point))
(right-char 1))
(pcase (-some-> (word-at-point) downcase)
("merge" (insert (icons-in-terminal 'oct_git_merge :height 1.1 :foreground "#FF5722")))
("fix" (insert (icons-in-terminal 'oct_bug :height 1.1 :foreground "#9C27B0")))
("remove" (insert (icons-in-terminal 'fa_trash_o :height 1.1 :foreground "#FFC107")))
("delete" (insert (icons-in-terminal 'fa_trash_o :height 1.1 :foreground "#FFC107")))
("add" (insert (icons-in-terminal 'md_playlist_add_check :height 1.2 :foreground "#03A9F4")))
(_ (insert (icons-in-terminal 'oct_git_commit :height 1.1 :foreground "#4CAF50"))))
(insert " "))))))
(advice-add #'magit-refresh-buffer :after #'my-magit-log-icon)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment