Add gist to store the Git revision of the Emacs config in a constant

This commit is contained in:
Bram Schoenmakers 2023-01-06 08:47:10 +01:00
parent e4c92482b8
commit 421dcf67e5
2 changed files with 41 additions and 0 deletions

View File

@ -361,6 +361,29 @@ Used [[https://github.com/purcell/emacs.d/blob/master/lisp/init-paredit.el][Purc
(bind-key (kbd "RET") #'paredit-newline paredit-mode-map)))
#+end_src
* Store revision of Emacs configuration in a constant
#+begin_src elisp :tangle gists/store-configuration-revision-in-constant.el
;; Store the Git revision of your Emacs configuration at the moment
;; Emacs started.
(defconst my/has-git-p (if (executable-find "git") t nil)
"Indicates if git is in your PATH.")
(defun my/configuration-revision ()
"Retrieve the current Git revision of the Emacs configuration."
(when my/has-git-p
(with-temp-buffer
(cd user-emacs-directory)
(when (eql 0 (call-process "git" nil (current-buffer) nil
"describe" "--all" "--long" "--dirty"))
(string-trim (buffer-string))))))
(defconst my/configuration-revision
(my/configuration-revision)
"Contains the Git revision of the configuration at the moment Emacs started.")
#+end_src
* Meta
** License

View File

@ -0,0 +1,18 @@
;; Store the Git revision of your Emacs configuration at the moment
;; Emacs started.
(defconst my/has-git-p (if (executable-find "git") t nil)
"Indicates if git is in your PATH.")
(defun my/configuration-revision ()
"Retrieve the current Git revision of the Emacs configuration."
(when my/has-git-p
(with-temp-buffer
(cd user-emacs-directory)
(when (eql 0 (call-process "git" nil (current-buffer) nil
"describe" "--all" "--long" "--dirty"))
(string-trim (buffer-string))))))
(defconst my/configuration-revision
(my/configuration-revision)
"Contains the Git revision of the configuration at the moment Emacs started.")