diff options
author | Steven Hall <Hallzy.18@gmail.com> | 2015-09-28 22:13:18 -0700 |
---|---|---|
committer | Steven Hall <Hallzy.18@gmail.com> | 2015-10-15 13:00:54 -0700 |
commit | 00f2a8c908e299d08e2efad038da25b2d5446976 (patch) | |
tree | dc2273fe62830da0e8f7fca8d6cc8c1ffbca344e | |
parent | 42135ad00014387b6937242563b920a7cf640866 (diff) | |
download | git-sonar-00f2a8c908e299d08e2efad038da25b2d5446976.tar.gz git-sonar-00f2a8c908e299d08e2efad038da25b2d5446976.zip |
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.
-rwxr-xr-x | fetch.sh | 6 | ||||
-rwxr-xr-x | git-radar | 21 | ||||
-rwxr-xr-x | radar-base.sh | 12 |
3 files changed, 31 insertions, 8 deletions
@@ -10,4 +10,8 @@ dot="$(cd "$(dirname "$([ -L "$0" ] && $READLINK_CMD -f "$0" || echo "$0")")"; p source $dot/radar-base.sh -fetch; +if [[ -z "$1" ]]; then + fetch; +else + fetch $1; +fi @@ -56,10 +56,11 @@ if [[ -z $@ ]]; then echo "usage:" echo " git-radar [--zsh|--bash|--fish] [--fetch]" echo "" - echo " --fetch # Fetches your repo asynchronously in the background every 5 mins" - echo " --zsh # Output prompt using Zsh style color characters" - echo " --bash # Output prompt using Bash style color characters" - echo " --fish # Output prompt using fish style color characters" + echo " --fetch # Fetches your repo asynchronously in the background every 5 mins" + echo " --fetch_t <seconds> # Fetches your repo asynchronously in the background every <seconds> seconds" + echo " --zsh # Output prompt using Zsh style color characters" + echo " --bash # Output prompt using Bash style color characters" + echo " --fish # Output prompt using fish style color characters" echo "" echo "Bash example:" echo " export PS1=\"\\W\\\$(git-radar --bash --fetch) \"" @@ -83,18 +84,30 @@ if [[ -z $@ ]]; then echo " end" echo "" echo " Same as the Bash but for fish." + echo "" + echo "Fetch_t example:" + echo " export PS1=\"\\W\\\$(git-radar --bash --fetch_t 45) \"" exit fi while [[ $# > 0 ]];do command="$1" shift + # Default fetch of 5 min if [[ "$command" == "--fetch" ]]; then nohup $dot/fetch.sh >/dev/null 2>&1 & fi + + # Custom fetch of whatever time interval the user wants + if [[ "$command" == "--fetch_t" ]]; then + # Now $1 is the value of fetch_t + nohup $dot/fetch.sh $1 >/dev/null 2>&1 & + fi + if [[ "$command" == "--zsh" ]]; then $dot/prompt.zsh $args fi + if [[ "$command" == "--bash" || "$command" == "--fish" ]]; then $dot/prompt.bash $args fi 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 |