|
5 | 5 | ;; Author: Jason Duncan <[email protected]>
|
6 | 6 | ;; Version: 0.0.1
|
7 | 7 | ;; 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")) |
9 | 9 |
|
10 | 10 | ;; This program is free software: you can redistribute it and/or modify
|
11 | 11 | ;; it under the terms of the GNU General Public License as published by
|
|
27 | 27 | ;;; Code:
|
28 | 28 |
|
29 | 29 | (require 'git)
|
| 30 | +(require 'dashboard) |
30 | 31 |
|
31 | 32 | (defun git-local-is-behind? ()
|
| 33 | + "Return non-nil if current `git-repo' is behind its remote." |
32 | 34 | (numberp
|
33 | 35 | (string-match-p
|
34 | 36 | (regexp-quote "Your branch is behind")
|
35 | 37 | (git-run "status" "-uno"))))
|
36 | 38 |
|
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"))) |
48 | 43 |
|
49 | 44 | (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 |
51 | 47 | (concat "Project "
|
52 | 48 | git-repo
|
53 | 49 | (if (git-local-is-behind?)
|
54 | 50 | " 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))))) |
56 | 62 |
|
57 | 63 | (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)) |
59 | 82 |
|
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)))) |
65 | 89 |
|
66 | 90 | (provide 'dashboard-project-status)
|
67 | 91 | ;;; dashboard-project-status.el ends here
|
0 commit comments