Last active
September 10, 2019 09:46
-
-
Save CyberShadow/28f60687c3bf83d32900cd6074c012cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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