From 74da533ad8e848d2ad3ea08acc1de6d193baeb12 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Tue, 6 Jun 2023 07:36:34 +0800 Subject: Update sync check --- bin/init/sync.sh | 8 +++++++- bin/wakeup.sh | 2 +- zsh/zshrc | 8 ++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bin/init/sync.sh b/bin/init/sync.sh index 351bb74..413256a 100755 --- a/bin/init/sync.sh +++ b/bin/init/sync.sh @@ -3,7 +3,11 @@ # If git is working in other process, then don't sync again pidof git >/dev/null && exit 0 -# my repo +# Print information about ~/.wakeup +echo 'latest: ' $(date -d @`stat -c %Y ~/.wakeup` --iso-8601=minutes) +echo 'wakeup at: ' $(cat ~/.wakeup | xargs -i date -d @{} --iso-8601=minutes) + +# Sync a repo sync() { cd "$1" || return [ -z "$(git remote -v)" ] && return @@ -13,6 +17,7 @@ sync() { echo "Has trouble when syncing $(pwd)" } +# Read file ~/.repos, and sync sed /^#/d ~/.repos | while read -r repo; do eval "sync $repo &" done @@ -28,5 +33,6 @@ done touch ~/.wakeup + # others repo #check_upstream ~/git/tig || echo in `pwd` >/dev/tty & diff --git a/bin/wakeup.sh b/bin/wakeup.sh index 4ceee6a..083499f 100755 --- a/bin/wakeup.sh +++ b/bin/wakeup.sh @@ -1,3 +1,3 @@ #! /bin/bash -date --iso-8601=minutes >~/.wakeup +date +%s >~/.wakeup diff --git a/zsh/zshrc b/zsh/zshrc index 1e31ecf..74b6b63 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -47,9 +47,9 @@ function _get_context() { fi } -function _sync_after_wakeup() { - latest=$(date -d @`stat -c %Y ~/.wakeup` --iso-8601=minutes) - test ! "$latest" = "$(cat ~/.wakeup)" +function _need_sync_after_wakeup() { + latest=$(date -d @`stat -c %Y ~/.wakeup` +%s) + test "$latest" -ge "$(cat ~/.wakeup)" } autoload -Uz add-zsh-hook @@ -71,7 +71,7 @@ function precmd() { # Show context and git status of tracking repos at right UNSYNC_REPOS=$(NUM=$($SETTING_DIR/bin/git/check-repos.sh -n); (( $NUM != 0 )) && echo $NUM) _get_context - NEED_SYNC=$(_sync_after_wakeup || echo S) + NEED_SYNC=$(_need_sync_after_wakeup || echo S) RPROMPT="%B%K{blue}%F{yellow}${CONTEXT:+ $CONTEXT }%f%k%K{red}%F{black}${UNSYNC_REPOS}${NEED_SYNC}%f%k%b" -- cgit v1.2.3-70-g09d2