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. --- README.md | 20 +++++++++++++++----- fetch.sh | 6 +----- git-radar | 21 --------------------- radar-base.sh | 17 ++++++++++++++++- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index c54764f..4f65c9c 100644 --- a/README.md +++ b/README.md @@ -182,13 +182,23 @@ export PROMPT="$PROMPT\$(git-radar --zsh --fetch) " ``` [(note: the `\` escaping the `$` is important)](#ensuring-prompt-execution) -You may also choose to use the `--fetch_t` option to specify your own fetch -times. `--fetch` defaults to fetch automatically every 5 minutes. With -`--fetch_t ` you can choose how often to fetch. +You may also choose to fetch at a customized interval of time. To do so, add +this to your .bashrc, .zshrc: -eg. ```bash -export PS1="$PS1\$(git-radar --bash --fetch_t 30)" +export GIT_RADAR_FETCH_TIME= +``` + +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 diff --git a/fetch.sh b/fetch.sh index 877fa7b..37601e3 100755 --- a/fetch.sh +++ b/fetch.sh @@ -10,8 +10,4 @@ dot="$(cd "$(dirname "$([ -L "$0" ] && $READLINK_CMD -f "$0" || echo "$0")")"; p source $dot/radar-base.sh -if [[ -z "$@" ]]; then - fetch; -else - fetch $1; -fi +fetch; diff --git a/git-radar b/git-radar index a38f00f..07f0a0a 100755 --- a/git-radar +++ b/git-radar @@ -84,37 +84,16 @@ 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 for fetch_t - # If value is not a number produce an error - if ! [[ $1 =~ ^[0-9]+$ ]] ; then - echo "" - echo "Error: fetch_t did not receive a number" - echo "Defaulting to 5 min." - echo " " - nohup $dot/fetch.sh >/dev/null 2>&1 & - else - command="$1" - shift - nohup $dot/fetch.sh $command >/dev/null 2>&1 & - fi - fi - if [[ "$command" == "--zsh" ]]; then $dot/prompt.zsh $args fi 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