Utilize zstat for system stat calls for zshrc

This commit is contained in:
Tony Blyler 2022-05-09 10:58:29 -04:00
parent 204e945b6f
commit cb16297268
2 changed files with 9 additions and 4 deletions

View file

@ -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 \

View file

@ -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