From d7f8bee3f06566847036c561c1cdf2b05ebafc5a Mon Sep 17 00:00:00 2001 From: Malfurious Date: Tue, 24 Aug 2021 05:08:11 -0400 Subject: Add explicit --help output -h or --help will now display the usage information on the command-line. Additionally, -f is offered as a short form of --fetch. As a consequence of this, it is no longer necessary to specify --bash/--fish/etc. to get the prompt to render. (However, these options will continue to be recognized by the script, for compatibility with git-radar.) The content of the help text is also updated for accuracy. Shell specific examples are removed (see the README). Signed-off-by: Malfurious --- git-sonar | 49 +++++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/git-sonar b/git-sonar index 3fd4a09..a6fc57a 100755 --- a/git-sonar +++ b/git-sonar @@ -518,8 +518,7 @@ render_prompt() { ################################################################################ # Original main ################################################################################ - -if [[ -z "$*" ]]; then +usage() { _git="\033[1;30mgit:(\033[0m" _master="\033[0;37mmaster\033[0m" _my_branch="\033[0;37mmy-branch\033[0m" @@ -563,43 +562,25 @@ if [[ -z "$*" ]]; then echo "" echo "usage:" - echo " git-sonar [--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 "" - echo "Bash example:" - echo " export PS1=\"\\W\\\$(git-sonar --bash --fetch) \"" - echo "" - echo " This will show your current directory and the full git-sonar." - echo " As an added benefit, if you are in a repo, it will asynchronously" - echo " run \`git fetch\` every 5 mins, so that you are never out of date." - echo "" - echo "Zsh example:" - echo " export PROMPT=\"%1/%\\\$(git-sonar --zsh --fetch) \"" - echo "" - echo " Same as the Bash but for Zsh." + echo " git-sonar [-h|--help] [-f|--fetch] [--zsh|--bash|--fish]" echo "" - echo "fish example:" - echo " function fish_prompt" - echo " set_color \$fish_color_cwd" - echo " echo -n (prompt_pwd)" - echo " git-sonar --fish -fetch" - echo " set_color normal" - echo " echo -n ' > '" - echo " end" - echo "" - echo " Same as the Bash but for fish." - exit -fi + echo " -h --help # Display this text" + echo " -f --fetch # Periodically fetch your repo asynchronously in the background" + 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 +while [[ $# -gt 0 ]]; do command="$1" shift - if [[ "$command" == "--fetch" ]]; then + if [[ "$command" == "-h" ]] || [[ "$command" == "--help" ]]; then + usage + exit + fi + + if [[ "$command" == "-f" ]] || [[ "$command" == "--fetch" ]]; then fetch >/dev/null 2>&1 fi done -- cgit v1.2.3