diff options
| -rwxr-xr-x | git-sonar | 73 |
1 files changed, 35 insertions, 38 deletions
@@ -98,19 +98,14 @@ is_repo() { } record_timestamp() { - if is_repo; then - touch "$(dot_git)/lastupdatetime" - fi + touch "$(dot_git)/lastupdatetime" } timestamp() { - if is_repo; then - if [[ $OSTYPE == darwin* ]];then - printf '%s' "$(stat -f%m "$(dot_git)/lastupdatetime" 2>/dev/null || printf '%s' "0")" - else - printf '%s' "$(stat -c %Y "$(dot_git)/lastupdatetime" 2>/dev/null || printf '%s' "0")" - fi; - + if [[ $OSTYPE == darwin* ]]; then + printf '%s' "$(stat -f%m "$(dot_git)/lastupdatetime" 2>/dev/null || printf '%s' "0")" + else + printf '%s' "$(stat -c %Y "$(dot_git)/lastupdatetime" 2>/dev/null || printf '%s' "0")" fi } @@ -120,16 +115,12 @@ time_now() { time_to_update() { last_time_updated="${1:-$FETCH_TIME}" - if is_repo; then - local timesincelastupdate="$(($(time_now) - $(timestamp)))" - if (( $timesincelastupdate > $last_time_updated )); then - # time to update return 0 (which is true) - return 0 - else - # not time to update return 1 (which is false) - return 1 - fi + local timesincelastupdate="$(($(time_now) - $(timestamp)))" + if (( $timesincelastupdate > $last_time_updated )); then + # time to update return 0 (which is true) + return 0 else + # not time to update return 1 (which is false) return 1 fi } @@ -145,9 +136,7 @@ fetch() { } commit_short_sha() { - if is_repo; then - printf '%s' "$(git rev-parse --short HEAD 2>/dev/null)" - fi + printf '%s' "$(git rev-parse --short HEAD 2>/dev/null)" } branch_name() { @@ -424,9 +413,7 @@ color_remote_commits() { } readable_branch_name() { - if is_repo; then - printf $PRINT_F_OPTION "$COLOR_BRANCH$(branch_name || printf '%s' "detached@$(commit_short_sha)")$RESET_COLOR_BRANCH" - fi + printf $PRINT_F_OPTION "$COLOR_BRANCH$(branch_name || printf '%s' "detached@$(commit_short_sha)")$RESET_COLOR_BRANCH" } stashed_status() { @@ -585,23 +572,33 @@ usage() { echo " --zsh # (does nothing - for compatibility with git-radar)" echo " --bash # (does nothing - for compatibility with git-radar)" echo " --fish # (does nothing - for compatibility with git-radar)" -} - -while [[ $# -gt 0 ]]; do - command="$1" + exit +} + +do_fetch="" + +while true; do + case "$1" in + --help) usage ;; + -h) usage ;; + --fetch) do_fetch="true" ;; + -f) do_fetch="true" ;; + --zsh) ;; + --bash) ;; + --fish) ;; + *) break + esac shift - - if [[ "$command" == "-h" ]] || [[ "$command" == "--help" ]]; then - usage - exit - fi - - if [[ "$command" == "-f" ]] || [[ "$command" == "--fetch" ]]; then - fetch >/dev/null 2>&1 - fi done +if [ $# -ne 0 ]; then + printf 'sonar: Unrecognized option given: %s\n' "$1" + exit 1 +fi + +# Guard all active operations by this is_repo check if is_repo; then + [ -n "$do_fetch" ] && fetch >/dev/null 2>&1 prepare_colors render_prompt fi |
