From 3ad455fe206c705f4858ea2bc42af8cd6da2553a Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Sat, 15 Aug 2020 23:11:18 +1200 Subject: [PATCH] add counter restart feature --- run.fish | 13 ++++++++++--- utils/helpers.fish | 11 +++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/run.fish b/run.fish index 9110c7e..ef6828b 100755 --- a/run.fish +++ b/run.fish @@ -24,6 +24,13 @@ end set pull_interval 10m set update_applied false +set should_auto_restart (count $argv[1] >/dev/null; and echo true; or echo false) +set auto_restart_cycles $argv[1] +set auto_restart_countdown $auto_restart_cycles + +function do_restart_countdown + $should_auto_restart; and test (quick_math auto_restart_countdown - 1) -le 0 +end cd bibliogram/src/site @@ -37,15 +44,15 @@ while true set update_applied false echo '' | node server.js & - set -l b_pid (jobs -p) while not $update_applied sleep $pull_interval - if do_update + if do_update; or do_restart_countdown npm install --no-optional set update_applied true - kill $b_pid + set auto_restart_countdown $auto_restart_cycles + kill (jobs -p) else echo '[ ] ['(date +%H%M%S)'] [UPD] No updates available yet.' end diff --git a/utils/helpers.fish b/utils/helpers.fish index ae349ef..f0a6d0d 100644 --- a/utils/helpers.fish +++ b/utils/helpers.fish @@ -36,3 +36,14 @@ function update_origin_url git fetch --quiet; or return 1 end end + +# Alter a variable with math. +# argv[1]: the variable to alter. +# argv[2...]: arguments to math. +# text: the new value of the variable. +function quick_math + set -l variable $argv[1] + set -l math_args $argv[2..-1] + set $variable (math $$variable $math_args) + echo $$variable +end -- 2.26.2