diff --git a/fake_home/.zshrc b/fake_home/.zshrc index b5e030b..7336871 100644 --- a/fake_home/.zshrc +++ b/fake_home/.zshrc @@ -203,23 +203,47 @@ function load-extensions { done } -function dot-lock-wait { - if test -f "$SYNC_LOCK_FILE"; then - echo "Sync lockfile present at '$SYNC_LOCK_FILE'" - echo "Waiting for ongoing sync to finish" - for i in {0..60}; do +function lock-wait { + local file="$1" + local seconds="$2" + local action="$3" + + if test -f "$file"; then + echo "Sync lockfile present at '$file'" + echo "Watching its output:" + tail -f "$file" & + tail_pid=$! + [[ "$action" == "" ]] || echo "Waiting for $action to finish" + for i in {0..$seconds}; do sleep 1 - if ! test -f "$SYNC_LOCK_FILE"; then + if ! test -f "$file"; then + kill $tail_pid &> /dev/null + echo + echo "Lock file at '$file' freed." + echo break fi done fi } -function pushdot { +function lockfor { + local file="$1" + local seconds="$2" + + lock-wait "$file" "$seconds" + touch "$file" + $3 $4 $5 $6 $7 $8 $9 $10 | tee -a "$file" + rm "$file" +} + + +function dot-lock-wait { + lock-wait "$SYNC_LOCK_FILE" 90 "Waiting for ongoing sync to finish" +} + +function _pushdot { cd "$DOT_DIR" || return 1 - dot-lock-wait - echo "$$" > "$SYNC_LOCK_FILE" local res if ! git diff --quiet; then if [ $# -eq 0 ]; then @@ -237,10 +261,13 @@ function pushdot { sync-history push-dconf cd - - rm "$SYNC_LOCK_FILE" return $res } +function pushdot { + lockfor "$SYNC_LOCK_FILE" 90 _pushdot $@ +} + function sync-dconf { if ! command -v dconf &> /dev/null; then echo "System does not use dconf" @@ -263,7 +290,7 @@ function sync-dconf { push-dconf } -function getdot { +function _getdot { if ! command -v scpace &> /dev/null; then echo "An alias for scpace has not been defined on this device!" return 1 @@ -279,6 +306,10 @@ function getdot { cd - > /dev/null } +function getdot { + lockfor "$SYNC_LOCK_FILE" 90 _getdot $@ +} + if which starship &> /dev/null; then eval "$(starship init zsh)" fi