Skip to content

Commit 1825e94

Browse files
author
Jason Duncan
committed
It appears to work.
1 parent bc2ce94 commit 1825e94

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed

dashboard-project-status.el

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
;; Author: Jason Duncan <[email protected]>
66
;; Version: 0.0.1
77
;; URL: https://github.com/functionreturnfurnction/dashboard-project-status
8-
;; Package-Requires: ((git "0.1.1"))
8+
;; Package-Requires: ((git "0.1.1") (dashboard "1.2.5"))
99

1010
;; This program is free software: you can redistribute it and/or modify
1111
;; it under the terms of the GNU General Public License as published by
@@ -27,41 +27,65 @@
2727
;;; Code:
2828

2929
(require 'git)
30+
(require 'dashboard)
3031

3132
(defun git-local-is-behind? ()
33+
"Return non-nil if current `git-repo' is behind its remote."
3234
(numberp
3335
(string-match-p
3436
(regexp-quote "Your branch is behind")
3537
(git-run "status" "-uno"))))
3638

37-
(defun check-git-project-status (&optional project-dir)
38-
"Update the remote and check the status of PROJECT-DIR."
39-
(let* ((project-dir
40-
(fix-os-path
41-
(concat
42-
(expand-file-name
43-
(or project-dir user-emacs-directory))))))
44-
(with-temp-buffer
45-
(call-process "git" nil nil nil "-C" project-dir "remote" "update")
46-
(call-process "git" nil t nil "-C" project-dir "status" "-uno")
47-
(buffer-string))))
39+
(defun git-unstaged-files ()
40+
"Return list of unstaged files."
41+
(git--lines
42+
(git-run "diff" "--name-only")))
4843

4944
(defun dashboard-insert-project-status-heading ()
50-
(insert
45+
"Insert a heading with project path and whether or not it is behind."
46+
(dashboard-insert-heading
5147
(concat "Project "
5248
git-repo
5349
(if (git-local-is-behind?)
5450
" is behind the remote. (use \"git-pull\" to update)"
55-
"is up-to-date."))))
51+
" is up-to-date.")
52+
hard-newline)))
53+
54+
(reverse
55+
(let ((git-repo user-emacs-directory)
56+
ret)
57+
(dolist (cur '("foo" "bar" "baz") ret)
58+
(setq ret (cons (expand-file-name
59+
(concat (file-name-as-directory git-repo)
60+
cur))
61+
ret)))))
5662

5763
(defun dashboard-insert-project-status-body ()
58-
64+
"Insert lists of untracked, unstaged, and staged files."
65+
(dolist (section `(("Untracked Files" . ,(git-untracked-files))
66+
("Unstaged Files" . ,(git-unstaged-files))
67+
("Staged Files" . ,(git-staged-files))))
68+
(dashboard-insert-recentf-list
69+
(car section)
70+
(reverse
71+
(let (ret)
72+
(dolist (cur (cdr section) ret)
73+
(setq ret (cons (expand-file-name
74+
(concat (file-name-as-directory git-repo) cur))
75+
ret))))))))
76+
77+
(defun dashboard-insert-project-status- (project-dir update)
78+
"Do the actual work for `dashboard-insert-project-status'."
79+
(when update (git-run "remote" "update"))
80+
(dashboard-insert-project-status-heading)
81+
(dashboard-insert-project-status-body))
5982

60-
(defun dashboard-insert-project-status (project-dir)
61-
(let ((git-repo project-dir))
62-
(lambda (list-size)
63-
(dashboard-insert-project-status-heading)
64-
(dashboard-insert-project-status-body))))
83+
(defun dashboard-insert-project-status (project-dir &optional update)
84+
"Return a function which will insert git status for PROJECT-DIR.
85+
If UPDATE is non-nil, update the remote first with 'git remote update'."
86+
`(lambda (list-size)
87+
(let ((git-repo ,project-dir))
88+
(dashboard-insert-project-status- ,project-dir ,update))))
6589

6690
(provide 'dashboard-project-status)
6791
;;; dashboard-project-status.el ends here

0 commit comments

Comments
 (0)