Skip to content

Instantly share code, notes, and snippets.

@CyberShadow
Last active September 10, 2019 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CyberShadow/28f60687c3bf83d32900cd6074c012cb to your computer and use it in GitHub Desktop.
Save CyberShadow/28f60687c3bf83d32900cd6074c012cb to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eEuo pipefail
# Method 1: a git pre-commit hook
date=$(date +%Y%m%d%H%M)
git diff-index --name-only --cached -z HEAD |
( grep -z '\.el$' || true ) |
while read -r -d '' fn
do
# Patch index
blob_sha1=$(git show :"$fn" |
sed "s/^;; Version: .*/;; Version: $date/" |
git hash-object -w --stdin)
printf '100644 blob %s\t%s\0' "$blob_sha1" "$fn" |
git update-index -z --index-info
# Patch working tree to match index
sed -i "s/^;; Version: .*/;; Version: $date/" "$fn"
done
;; Method 2: an Emacs before-save-hook
(defun d-mode-update-package-version ()
"Update package version timestamp e.g. in d-mode.el."
(interactive)
(when (eq major-mode 'emacs-lisp-mode)
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(when (re-search-forward "^;; Version: [0-9]\\{12\\}$")
(delete-char -12)
(insert (format-time-string "%Y%m%d%H%M" nil t)))))))
(add-hook 'before-save-hook 'd-mode-update-package-version)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment