summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Allen <michael@michaelallen.io>2015-10-27 10:45:42 +0000
committerMichael Allen <michael@michaelallen.io>2015-10-27 10:45:42 +0000
commit47addd8b811e77f3be815fea56bcaeddd89edea0 (patch)
tree611ef993dd3c37aeb510495ce58ddcb41563805c
parent934f6fd5b317476e7680bfd07dc2b685b5c37c4d (diff)
parent225de5490a49e92ea34326226308159e93b6b80d (diff)
downloadgit-sonar-47addd8b811e77f3be815fea56bcaeddd89edea0.tar.gz
git-sonar-47addd8b811e77f3be815fea56bcaeddd89edea0.zip
Merge pull request #70 from hallzy/masterv0.5
Added feature that let's you specify how often to fetch
-rw-r--r--README.md20
-rwxr-xr-xgit-radar2
-rwxr-xr-xradar-base.sh23
-rwxr-xr-xtest-directories.sh3
4 files changed, 45 insertions, 3 deletions
diff --git a/README.md b/README.md
index 2f508a8..7e84317 100644
--- a/README.md
+++ b/README.md
@@ -190,6 +190,25 @@ export PROMPT="$PROMPT\$(git-radar --zsh --fetch) "
```
[(note: the `\` escaping the `$` is important)](#ensuring-prompt-execution)
+You may also choose to fetch at a customized interval of time. To do so, add
+this to your .bashrc, .zshrc:
+
+```bash
+export GIT_RADAR_FETCH_TIME=<seconds>
+```
+
+For example, to fetch every 30 seconds (instead of the default 5 minutes):
+
+```bash
+export GIT_RADAR_FETCH_TIME=30
+```
+
+You can also do this in the gitradarrc file:
+
+```bash
+GIT_RADAR_FETCH_TIME=30
+```
+
## Customise your prompt
Git Radar is highly customisable using a prompt format string. The 4 features
@@ -235,6 +254,7 @@ The default prompt format uses this to add spaces only if the feature would
render. In that way the prompt always looks well spaced out no matter how many
features are rendering.
+
## Support
### Ensuring prompt execution
diff --git a/git-radar b/git-radar
index a8dd72e..f736e41 100755
--- a/git-radar
+++ b/git-radar
@@ -95,9 +95,11 @@ while [[ $# > 0 ]];do
if [[ "$command" == "--fetch" ]]; then
nohup $dot/fetch.sh >/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 f11d3ae..099debd 100755
--- a/radar-base.sh
+++ b/radar-base.sh
@@ -14,6 +14,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"
@@ -169,10 +183,10 @@ time_now() {
}
time_to_update() {
+ last_time_updated="${1:-$FETCH_TIME}"
if is_repo; then
local timesincelastupdate="$(($(time_now) - $(timestamp)))"
- local fiveminutes="$((5 * 60))"
- if (( $timesincelastupdate > $fiveminutes )); then
+ if (( $timesincelastupdate > $last_time_updated )); then
# time to update return 0 (which is true)
return 0
else
@@ -185,7 +199,10 @@ time_to_update() {
}
fetch() {
- if time_to_update; then
+ # Gives $FETCH_TIME a value
+ get_fetch_time
+
+ if time_to_update $FETCH_TIME; then
record_timestamp
git fetch --quiet > /dev/null 2>&1
fi
diff --git a/test-directories.sh b/test-directories.sh
index 86a441e..5dde303 100755
--- a/test-directories.sh
+++ b/test-directories.sh
@@ -63,12 +63,14 @@ test_record_timestamp_in_repo() {
test_time_to_update_when_timestamp_is_old() {
cd $scriptDir
+ FETCH_TIME="$((5 * 60))" # Fetch every 5 mins
touch -A "-010000" "$(dot_git)/lastupdatetime"
assertTrue time_to_update
}
test_not_time_to_update_when_just_recorded() {
cd $scriptDir
+ FETCH_TIME="$((5 * 60))" # Fetch every 5 mins
record_timestamp
assertFalse time_to_update
}
@@ -77,6 +79,7 @@ test_time_to_update_when_no_timestamp() {
cd_to_tmp
git init --quiet
+ FETCH_TIME="$((5 * 60))" # Fetch every 5 mins
time_to_update
assertTrue time_to_update