diff options
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 |