diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2024-08-04 00:24:41 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2024-08-04 00:24:41 -0300 |
commit | fcc720ae85e710eb4aca4ff8bf48b597aa4ea5fe (patch) | |
tree | 94fd761663f0e67d272afc0070d0f35d08d2bb09 /status | |
parent | cb94262779f42533e8fc7cf670484a699543ea52 (diff) | |
download | scripts-fcc720ae85e710eb4aca4ff8bf48b597aa4ea5fe.tar.gz scripts-fcc720ae85e710eb4aca4ff8bf48b597aa4ea5fe.tar.bz2 |
Fix: status: add function status_run_if_file_older_than
Diffstat (limited to 'status')
-rwxr-xr-x | status | 45 |
1 files changed, 28 insertions, 17 deletions
@@ -72,6 +72,33 @@ function status_file_changed_delta { echo $(( timestamp - file_timestamp )) } +# Run command if a file is older than a given number of seconds +function status_run_if_file_older_than { + local file="$1" + local interval="$2" + local run="0" + + shift 2 + + # Run command if there's still no file to test + if [ ! -e "$file" ]; then + run="1" + else + local age="`status_file_changed_delta $file`" + local interval="3600" + + # Run command only when file is older or equal the interval + if (( $age >= $interval )); then + run="1" + fi + fi + + # Run if criteria matches + if [ "$run" == "1" ]; then + $* + fi +} + # Run status function status_run { if [ ! -z "$PROJECT" ]; then @@ -92,24 +119,8 @@ function status_run { # Update your mrconfig and check all registered repositories if which mr &> /dev/null; then local mrconfig="$HOME/.custom/mrconfig-automatic" - local mrconfig_run="0" - - # Run mrconfig-updater if there's still no config - if [ ! -e "$mrconfig" ]; then - mrconfig_run="1" - else - local mrconfig_age="`status_file_changed_delta $mrconfig`" - local mrconfig_interval="3600" - - # Run mrconfig-updater only every hour or so - if (( $mrconfig_age >= $mrconfig_interval )); then - mrconfig_run="1" - fi - fi - if [ "$mrconfig_run" == "1" ]; then - mrconfig-updater - fi + status_run_if_file_older_than $mrconfig 3600 mrconfig-updater # Pipe through cat so we don't have to deal with mr's dynamic output weirdness #mr -m status | cat |