From d8e065dc2fbe4d381239fa7db2e0298aa10dbd0f Mon Sep 17 00:00:00 2001 From: Tony Blyler Date: Mon, 2 May 2022 16:22:22 -0400 Subject: [PATCH] Update chezmoi.zsh to have an auto update feature --- chezmoi/dot_zshrc.d/executable_chezmoi.zsh | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/chezmoi/dot_zshrc.d/executable_chezmoi.zsh b/chezmoi/dot_zshrc.d/executable_chezmoi.zsh index 22c45e0..67e628d 100644 --- a/chezmoi/dot_zshrc.d/executable_chezmoi.zsh +++ b/chezmoi/dot_zshrc.d/executable_chezmoi.zsh @@ -1,3 +1,4 @@ +# completion ( set -euo pipefail @@ -16,3 +17,33 @@ chezmoi completion zsh > "$COMPLETION_FILE" chmod +x "$COMPLETION_FILE" ) + +# auto update +( + set -euo pipefail + + # has the chezmoi repo been pulled in the last 24 hours? + if [ "$(date +%s -r "$(chezmoi git rev-parse -- --show-toplevel)/.git/FETCH_HEAD")" -gt $((EPOCHSECONDS-86400)) ]; then + exit 0 + fi + + chezmoi git pull -- --rebase + chezmoi diff + + while true; do + read -r 'APPLY?apply? [y/N] ' + + case "${APPLY:-}" in + 'y'|'Y'|'YES'|'yes'|'Yes') + echo 'applying changes' + chezmoi apply + exit 0 + ;; + + 'n'|'N'|'NO'|'no'|'No'|'') + echo 'not applying changes' + exit 0 + ;; + esac + done +)