|
| 1 | +;;; dashboard-project-status.el --- Display a git project status in a dashboard widget. -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +;; Copyright (C) 2019 Jason Duncan, all rights reserved |
| 4 | + |
| 5 | +;; Author: Jason Duncan <[email protected]> |
| 6 | +;; Version: 0.0.1 |
| 7 | +;; URL: https://github.com/functionreturnfurnction/dashboard-project-status |
| 8 | +;; Package-Requires: ((git "0.1.1")) |
| 9 | + |
| 10 | +;; This program is free software: you can redistribute it and/or modify |
| 11 | +;; it under the terms of the GNU General Public License as published by |
| 12 | +;; the Free Software Foundation, either version 3 of the License, or (at |
| 13 | +;; your option) any later version. |
| 14 | + |
| 15 | +;; This program is distributed in the hope that it will be useful, but |
| 16 | +;; WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | +;; General Public License for more details. |
| 19 | + |
| 20 | +;; You should have received a copy of the GNU General Public License |
| 21 | +;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. |
| 22 | + |
| 23 | +;;; Commentary: |
| 24 | + |
| 25 | +;; Display a git project status in a dashboard widget. |
| 26 | + |
| 27 | +;;; Code: |
| 28 | + |
| 29 | +(require 'git) |
| 30 | + |
| 31 | +(defun git-local-is-behind? () |
| 32 | + (numberp |
| 33 | + (string-match-p |
| 34 | + (regexp-quote "Your branch is behind") |
| 35 | + (git-run "status" "-uno")))) |
| 36 | + |
| 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)))) |
| 48 | + |
| 49 | +(defun dashboard-insert-project-status-heading () |
| 50 | + (insert |
| 51 | + (concat "Project " |
| 52 | + git-repo |
| 53 | + (if (git-local-is-behind?) |
| 54 | + " is behind the remote. (use \"git-pull\" to update)" |
| 55 | + "is up-to-date.")))) |
| 56 | + |
| 57 | +(defun dashboard-insert-project-status-body () |
| 58 | + |
| 59 | + |
| 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)))) |
| 65 | + |
| 66 | +(provide 'dashboard-project-status) |
| 67 | +;;; dashboard-project-status.el ends here |
0 commit comments