Last active
May 10, 2021 00:50
-
-
Save tttuuu888/de8f4b007a294e0cce198784d4da0983 to your computer and use it in GitHub Desktop.
simple Emacs mode line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun git-tracked-file-p (&optional file-name) | |
(let ((file (or file-name buffer-file-name))) | |
(and file | |
(file-exists-p file) | |
(zerop (process-file "git" nil nil nil | |
"ls-files" "--error-unmatch" | |
(file-name-nondirectory file)))))) | |
(defun git-branch-of-file (file) | |
(when (git-tracked-file-p file) | |
(let* ((default-directory (file-name-directory file)) | |
(branch (shell-command-to-string "git branch --show-current")) | |
(hash (when (equal branch "") | |
(shell-command-to-string "git rev-parse HEAD")))) | |
(if hash | |
(substring hash 0 7) | |
(substring branch 0 (1- (length branch))))))) | |
(defun sk-mode-line () | |
(set-face-attribute 'mode-line nil :box nil) | |
(set-face-attribute 'mode-line-inactive nil :box nil) | |
(setq-default | |
mode-line-format | |
'("%e" | |
(:eval | |
(let* ((evil-info (and (featurep 'evil) evil-mode | |
(concat " " (upcase (symbol-name evil-state))))) | |
(buffer-info (concat " %* %I " current-input-method-title)) | |
(buffer-name (propertize " %b " 'face 'mode-line-emphasis)) | |
(git-branch (git-branch-of-file buffer-file-name)) | |
(vc-info (and git-branch (concat " (" git-branch ") "))) | |
(mode-and-vc (propertize | |
(concat " " | |
(format-mode-line mode-name) | |
vc-info | |
" ") | |
'face 'mode-line-inactive)) | |
(line-info (format-mode-line " %l,%3c ")) | |
(pos-info (format-mode-line "%p%% ")) | |
(right-info (concat line-info pos-info)) | |
(right-length (length right-info)) | |
(center-fill (propertize | |
" " | |
'face 'mode-line-inactive | |
'display | |
`((space :align-to | |
(- (+ right right-fringe right-margin) | |
,right-length)))))) | |
(concat evil-info buffer-info buffer-name mode-and-vc | |
center-fill | |
right-info)))))) | |
(sk-mode-line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment