More generic "lockfor" system
This commit is contained in:
parent
82e05fc333
commit
01b5af233f
|
@ -203,23 +203,47 @@ function load-extensions {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function dot-lock-wait {
|
function lock-wait {
|
||||||
if test -f "$SYNC_LOCK_FILE"; then
|
local file="$1"
|
||||||
echo "Sync lockfile present at '$SYNC_LOCK_FILE'"
|
local seconds="$2"
|
||||||
echo "Waiting for ongoing sync to finish"
|
local action="$3"
|
||||||
for i in {0..60}; do
|
|
||||||
|
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
|
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
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
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
|
cd "$DOT_DIR" || return 1
|
||||||
dot-lock-wait
|
|
||||||
echo "$$" > "$SYNC_LOCK_FILE"
|
|
||||||
local res
|
local res
|
||||||
if ! git diff --quiet; then
|
if ! git diff --quiet; then
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
|
@ -237,10 +261,13 @@ function pushdot {
|
||||||
sync-history
|
sync-history
|
||||||
push-dconf
|
push-dconf
|
||||||
cd -
|
cd -
|
||||||
rm "$SYNC_LOCK_FILE"
|
|
||||||
return $res
|
return $res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pushdot {
|
||||||
|
lockfor "$SYNC_LOCK_FILE" 90 _pushdot $@
|
||||||
|
}
|
||||||
|
|
||||||
function sync-dconf {
|
function sync-dconf {
|
||||||
if ! command -v dconf &> /dev/null; then
|
if ! command -v dconf &> /dev/null; then
|
||||||
echo "System does not use dconf"
|
echo "System does not use dconf"
|
||||||
|
@ -263,7 +290,7 @@ function sync-dconf {
|
||||||
push-dconf
|
push-dconf
|
||||||
}
|
}
|
||||||
|
|
||||||
function getdot {
|
function _getdot {
|
||||||
if ! command -v scpace &> /dev/null; then
|
if ! command -v scpace &> /dev/null; then
|
||||||
echo "An alias for scpace has not been defined on this device!"
|
echo "An alias for scpace has not been defined on this device!"
|
||||||
return 1
|
return 1
|
||||||
|
@ -279,6 +306,10 @@ function getdot {
|
||||||
cd - > /dev/null
|
cd - > /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getdot {
|
||||||
|
lockfor "$SYNC_LOCK_FILE" 90 _getdot $@
|
||||||
|
}
|
||||||
|
|
||||||
if which starship &> /dev/null; then
|
if which starship &> /dev/null; then
|
||||||
eval "$(starship init zsh)"
|
eval "$(starship init zsh)"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue