From 00f2a8c908e299d08e2efad038da25b2d5446976 Mon Sep 17 00:00:00 2001 From: Steven Hall Date: Mon, 28 Sep 2015 22:13:18 -0700 Subject: Added feature that let's you specify how often to fetch with --fetch_t you can specify how many seconds to wait before auto fetching. using the --fetch option gives you the default of 5 minutes still. "--fetch_t 45" for example would fetch every 45 seconds. --- radar-base.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 258e5b1..ee5fa00 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -154,8 +154,7 @@ time_now() { time_to_update() { if is_repo; then local timesincelastupdate="$(($(time_now) - $(timestamp)))" - local fiveminutes="$((5 * 60))" - if (( $timesincelastupdate > $fiveminutes )); then + if (( $timesincelastupdate > $1 )); then # time to update return 0 (which is true) return 0 else @@ -168,7 +167,14 @@ time_to_update() { } fetch() { - if time_to_update; then + if [ -z "$1" ]; then + # Default 5 minutes + local timeToUpdate="$((5 * 60))" + else + local timeToUpdate="$1" + fi + + if time_to_update $timeToUpdate; then record_timestamp git fetch --quiet > /dev/null 2>&1 fi -- cgit v1.2.3 From b8797284031edbfd4c22f19f4878418cf4b2ec10 Mon Sep 17 00:00:00 2001 From: Steven Hall Date: Fri, 16 Oct 2015 11:31:21 -0700 Subject: Made changes recommeneded by @michaeldfallen in fetch.sh "if" now checks for $@ instead of just $1 in radar-base.sh there is now a parameter expansion on line 170 instead of the if statements. in git-radar, now there is a shift, and a regex check that the next value is a number. If the next value after --fetch_t is not a number, an error is echo'd and it resorts to the default behaviour of 5 minutes. --- radar-base.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index ee5fa00..886a6e9 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -167,12 +167,7 @@ time_to_update() { } fetch() { - if [ -z "$1" ]; then - # Default 5 minutes - local timeToUpdate="$((5 * 60))" - else - local timeToUpdate="$1" - fi + local timeToUpdate = ${"$1":-"$((5 * 60))"} if time_to_update $timeToUpdate; then record_timestamp -- cgit v1.2.3 From 3bdb43d9dad5766c23a34e438ad3fbd05823b6bd Mon Sep 17 00:00:00 2001 From: Steven Hall Date: Fri, 16 Oct 2015 16:26:11 -0700 Subject: Fixed an error in my parameter subsitution. --- radar-base.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 886a6e9..d639fa0 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -167,7 +167,7 @@ time_to_update() { } fetch() { - local timeToUpdate = ${"$1":-"$((5 * 60))"} + local timeToUpdate=${1:-"$((5 * 60))"} if time_to_update $timeToUpdate; then record_timestamp -- cgit v1.2.3 From 8bef8d80648accd2806ad44e8db6e3aacd92d2e7 Mon Sep 17 00:00:00 2001 From: Steven Hall Date: Sun, 18 Oct 2015 16:27:32 -0700 Subject: Custom Fetch time now uses a variable Set the variable GIT_RADAR_FETCH_TIME in a bashrc, zshrc or gitradarrc file to customize the fetch time. --- radar-base.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index d639fa0..f9d834a 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -13,6 +13,20 @@ timethis() { echo "$1 - $dur" >> $HOME/duration.dat } +get_fetch_time() { + if [ -f "$rcfile_path/.gitradarrc.bash" ]; then + source "$rcfile_path/.gitradarrc.bash" + elif [ -f "$rcfile_path/.gitradarrc.zsh" ]; then + source "$rcfile_path/.gitradarrc.zsh" + elif [ -f "$rcfile_path/.gitradarrc" ]; then + source "$rcfile_path/.gitradarrc" + fi + + FETCH_TIME="${GIT_RADAR_FETCH_TIME:-"$((5 * 60))"}" + echo $FETCH_TIME + +} + prepare_bash_colors() { if [ -f "$rcfile_path/.gitradarrc.bash" ]; then source "$rcfile_path/.gitradarrc.bash" @@ -167,7 +181,8 @@ time_to_update() { } fetch() { - local timeToUpdate=${1:-"$((5 * 60))"} + get_fetch_time + local timeToUpdate=${1:-$FETCH_TIME} if time_to_update $timeToUpdate; then record_timestamp -- cgit v1.2.3 From 40445543f10f4e10cc13ea8a9e4ba0a79cb200db Mon Sep 17 00:00:00 2001 From: Steven Hall Date: Sun, 18 Oct 2015 23:07:31 -0700 Subject: Since a number is no longer taken after --fetch_t we can remove the parameter substitution that has been removed in this commit. --- radar-base.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index f9d834a..538d593 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -181,10 +181,10 @@ time_to_update() { } fetch() { + # Gives $FETCH_TIME a value get_fetch_time - local timeToUpdate=${1:-$FETCH_TIME} - if time_to_update $timeToUpdate; then + if time_to_update $FETCH_TIME; then record_timestamp git fetch --quiet > /dev/null 2>&1 fi -- cgit v1.2.3 From 984ff133d360222906ff20f7431be9a70a212539 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 21 Oct 2015 11:59:16 +0100 Subject: Fix tests broken by FETCH_TIME now being pushed in --- radar-base.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 0f4a35a..099debd 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -183,9 +183,10 @@ time_now() { } time_to_update() { + last_time_updated="${1:-$FETCH_TIME}" if is_repo; then local timesincelastupdate="$(($(time_now) - $(timestamp)))" - if (( $timesincelastupdate > $1 )); then + if (( $timesincelastupdate > $last_time_updated )); then # time to update return 0 (which is true) return 0 else -- cgit v1.2.3