aboutsummaryrefslogtreecommitdiff
path: root/status
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2024-08-04 00:24:41 -0300
committerSilvio Rhatto <rhatto@riseup.net>2024-08-04 00:24:41 -0300
commitfcc720ae85e710eb4aca4ff8bf48b597aa4ea5fe (patch)
tree94fd761663f0e67d272afc0070d0f35d08d2bb09 /status
parentcb94262779f42533e8fc7cf670484a699543ea52 (diff)
downloadscripts-fcc720ae85e710eb4aca4ff8bf48b597aa4ea5fe.tar.gz
scripts-fcc720ae85e710eb4aca4ff8bf48b597aa4ea5fe.tar.bz2
Fix: status: add function status_run_if_file_older_than
Diffstat (limited to 'status')
-rwxr-xr-xstatus45
1 files changed, 28 insertions, 17 deletions
diff --git a/status b/status
index b357b4e..51f9874 100755
--- a/status
+++ b/status
@@ -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