diff options
| author | benjamin <benjamin.lindqvist@gmail.com> | 2018-09-14 23:00:46 +0200 |
|---|---|---|
| committer | benjamin <benjamin.lindqvist@gmail.com> | 2018-09-14 23:00:46 +0200 |
| commit | 89ddf31ecad885e5491e8d6b71b48c1591b3faec (patch) | |
| tree | 0815038dd68ce363011ab068b644f0b058af8941 | |
| parent | 7cb5083249ab429ef06b8d68d6f30628600a4cab (diff) | |
use magit's function to obtain git branch
The old method was just incredibly hacky and bad.
If magit is not installed, we still use the old method as fallback (but who doesn't use magit anyway)
| -rw-r--r-- | feebleline.el | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/feebleline.el b/feebleline.el index a62c77a..af4fff9 100644 --- a/feebleline.el +++ b/feebleline.el @@ -115,17 +115,28 @@ FORMAT-ARGS (a list) will be expanded as the rest of `format' arguments. If PROPS is given, it should be a list which will be sent to `add-text-properties'.") -(defun feebleline--git-branch-string () - "Return current git branch as a string, or the empty string if pwd is not in a git repo (or the git command is not found)." - (interactive) +(require 'magit nil t) +(if (fboundp 'magit-get-current-branch) + (defun feebleline--git-branch-string () + "Return current git branch as a string, or the empty string if pwd is not in a git repo (or the git command is not found)." + (interactive) + (require 'esh-ext) + (let ((git-output (magit-get-current-branch))) + (if (> (length git-output) 0) + git-output + "(no branch)"))) + + (message "Warning: Feebleline couldn't find magit! Using hacky version to obtain git branch.") (require 'esh-ext) - (when (and (eshell-search-path "git") - (locate-dominating-file default-directory ".git")) - (let ((git-output (shell-command-to-string (concat "cd " default-directory " && git branch | grep '\\*' | sed -e 's/^\\* //'")))) - (if (> (length git-output) 0) - (substring git-output 0 -1) - ;; (concat " :" (substring git-output 0 -1)) - "(no branch)")))) + (defun feebleline--git-branch-string () + "Return current git branch as a string, or the empty string if pwd is not in a git repo (or the git command is not found)." + (interactive) + (when (and (eshell-search-path "git") + (locate-dominating-file default-directory ".git")) + (let ((git-output (shell-command-to-string (concat "cd " default-directory " && git branch | grep '\\*' | sed -e 's/^\\* //'")))) + (if (> (length git-output) 0) + (substring git-output 0 -1) + "(no branch)"))))) (defvar feebleline--home-dir nil) |
