From cb162972686dd7f2cbd9e679e60ef4ebd7e1330a Mon Sep 17 00:00:00 2001 From: Tony Blyler Date: Mon, 9 May 2022 10:58:29 -0400 Subject: [PATCH] Utilize zstat for system stat calls for zshrc --- chezmoi/dot_zshrc | 3 +++ chezmoi/dot_zshrc.d/executable_chezmoi.zsh | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/chezmoi/dot_zshrc b/chezmoi/dot_zshrc index bae771d..dfd1502 100644 --- a/chezmoi/dot_zshrc +++ b/chezmoi/dot_zshrc @@ -1,6 +1,9 @@ #!/usr/bin/zsh zmodload zsh/datetime +# load the stat module but only with the `zstat` command +# leave `stat` to the system's stat command +zmodload -F zsh/stat b:zstat autoload -Uz \ colors \ diff --git a/chezmoi/dot_zshrc.d/executable_chezmoi.zsh b/chezmoi/dot_zshrc.d/executable_chezmoi.zsh index 67e628d..92ac88c 100644 --- a/chezmoi/dot_zshrc.d/executable_chezmoi.zsh +++ b/chezmoi/dot_zshrc.d/executable_chezmoi.zsh @@ -6,10 +6,10 @@ COMPLETION_FILE="${ZSH_COMPLETIONS_DIR}/_chezmoi" if [ -r "$COMPLETION_FILE" ]; then - COMPLETION_FILE_CTIME="$(stat -c %Z "$COMPLETION_FILE")" - CHEZMOI_FILE_CTIME="$(stat -c %Z "${CHEZMOI_PATH}")" + zstat -H COMPLETION_FILE_STAT "$COMPLETION_FILE" + zstat -H CHEZMOI_FILE_STAT "${CHEZMOI_PATH}" - if [ "$COMPLETION_FILE_CTIME" -ge "$CHEZMOI_FILE_CTIME" ]; then + if [ "${COMPLETION_FILE_STAT[ctime]}" -ge "${CHEZMOI_FILE_STAT[ctime]}" ]; then exit 0 fi fi @@ -22,8 +22,10 @@ ( set -euo pipefail + zstat -H LAST_PULL_STAT "$(chezmoi git rev-parse -- --show-toplevel)/.git/FETCH_HEAD" + # 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 + if [ "${LAST_PULL_STAT[ctime]}" -gt $((EPOCHSECONDS-86400)) ]; then exit 0 fi