From 637b5d5534469ebb15826139e1b3df12a1cc9309 Mon Sep 17 00:00:00 2001 From: Reinaldo Colina Date: Thu, 27 Aug 2015 12:14:13 -0700 Subject: issue-17: Add arguments to make the prompt shorter --- README.md | 28 ++++++++++++++++++++++++++++ git-radar | 5 +++-- prompt.bash | 11 +++++++++-- radar-base.sh | 17 +++++++++++++++++ test | 1 + test-radar-base.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 109 insertions(+), 4 deletions(-) create mode 100755 test-radar-base.sh diff --git a/README.md b/README.md index d4bd3dd..f126a21 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,19 @@ Prompt | Meaning ![git:(m 4 → my-branch)] | There are 4 commits on `origin/master` that aren't on `origin/my-branch` ![git:(m 1 ⇄ 2 my-branch)] | `origin/master` and `origin/my-branch` have diverged, we'll need to rebase or merge +If you don't rely on this status, you can always hide this part of the prompt by calling git-radar with `--no-remote-status`. + +**Bash** +```bash +export PS1="$PS1\$(git-radar --bash --fetch --no-remote-status) " +``` +(note: the `\` escaping the `$` is important) + +**Zsh** +```zsh +export PROMPT="$PROMPT$(git-radar --zsh --fetch --no-remote-status) " +``` + ### (Optional) Auto-fetch repos Ensuring your refs are up to date I found can be a pain. To streamline this @@ -124,6 +137,21 @@ export PS1="$PS1\$(git-radar --bash --fetch)" export PROMPT="$PROMPT$(git-radar --zsh --fetch) " ``` +### (Optional) Minimal mode + +If you wish to keep the length of your prompt shorter, you can call git-radar with `--minimal` which will render the new prompt without the `git:` part + +**Bash** +```bash +export PS1="$PS1\$(git-radar --bash --fetch --minimal) " +``` +(note: the `\` escaping the `$` is important) + +**Zsh** +```zsh +export PROMPT="$PROMPT$(git-radar --zsh --fetch --minimal) " +``` + ## License Git Radar is licensed under the MIT license. diff --git a/git-radar b/git-radar index a5cd3c1..67b8460 100755 --- a/git-radar +++ b/git-radar @@ -11,6 +11,7 @@ else fi dot="$(cd "$(dirname "$([ -L "$0" ] && $READLINK_CMD -f "$0" || echo "$0")")"; pwd)" +args=$@ if [[ -z $@ ]]; then _git="\033[1;30mgit:(\033[0m" @@ -92,9 +93,9 @@ while [[ $# > 0 ]];do nohup $dot/fetch.sh >/dev/null 2>&1 & fi if [[ "$command" == "--zsh" ]]; then - $dot/prompt.zsh + $dot/prompt.zsh $args fi if [[ "$command" == "--bash" || "$command" == "--fish" ]]; then - $dot/prompt.bash + $dot/prompt.bash $args fi done diff --git a/prompt.bash b/prompt.bash index a3fe420..1e79cd9 100755 --- a/prompt.bash +++ b/prompt.bash @@ -1,11 +1,18 @@ #! /usr/bin/env bash dot="$(cd "$(dirname "$0")"; pwd)" +git_label="" +args=$@ source "$dot/radar-base.sh" if is_repo; then - printf " \x01\033[1;30m\x02git:(\x01\033[0m\x02" - bash_color_remote_commits + if show_git_label $args; then + git_label="git:" + fi + printf " \x01\033[1;30m\x02$git_label(\x01\033[0m\x02" + if show_remote_status $args; then + bash_color_remote_commits + fi readable_branch_name bash_color_local_commits printf "\x01\033[1;30m\x02)\x01\033[0m\x02" diff --git a/radar-base.sh b/radar-base.sh index b7074d8..a2f5115 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -1,3 +1,6 @@ +IS_MINIMAL='--minimal' +NO_REMOTE_STATUS='--no-remote-status' + dot_git="" cwd="" remote="" @@ -469,3 +472,17 @@ zsh_color_remote_commits() { printf %s "$remote" } + +show_git_label() { + if [[ $@ == *$IS_MINIMAL* ]]; then + return 1 # don't show the git label + fi + return 0 +} + +show_remote_status() { + if [[ $@ == *$NO_REMOTE_STATUS* ]]; then + return 1 # don't show the git remote status + fi + return 0 +} diff --git a/test b/test index a6a8775..831e039 100755 --- a/test +++ b/test @@ -1,5 +1,6 @@ #!/bin/sh +./test-radar-base.sh ./test-directories.sh ./test-commits.sh ./test-branches.sh diff --git a/test-radar-base.sh b/test-radar-base.sh new file mode 100755 index 0000000..ca95136 --- /dev/null +++ b/test-radar-base.sh @@ -0,0 +1,51 @@ +scriptDir="$(cd "$(dirname "$0")"; pwd)" + +source "$scriptDir/radar-base.sh" + +test_show_git_label() { + show_git_label + assertTrue $? + + show_git_label --bash + assertTrue $? + + show_git_label --bash --fetch + assertTrue $? + + show_git_label --bash --minimal --fetch + assertFalse $? + + show_git_label --bash --fetch --minimal + assertFalse $? + + show_git_label --minimal --bash --fetch + assertFalse $? + + show_git_label --bash --fetch --minimal --no-remote-status + assertFalse $? +} + +test_show_remote_status() { + show_remote_status + assertTrue $? + + show_remote_status --bash + assertTrue $? + + show_remote_status --bash --fetch + assertTrue $? + + show_remote_status --bash --no-remote-status --fetch + assertFalse $? + + show_remote_status --bash --fetch --no-remote-status + assertFalse $? + + show_remote_status --no-remote-status --bash --fetch + assertFalse $? + + show_remote_status --bash --fetch --minimal --no-remote-status + assertFalse $? +} + +. ./shunit/shunit2 \ No newline at end of file -- cgit v1.2.3 From 93dad96832a59d3d7f6ac6580cabf0202b387ffe Mon Sep 17 00:00:00 2001 From: Reinaldo Colina Date: Fri, 28 Aug 2015 13:55:37 -0700 Subject: Removing --minimal arg implementation - Dealing with the git: prefix will be done in a separate pull request - The new --no-remote-status arg remains --- README.md | 15 --------------- prompt.bash | 6 +----- radar-base.sh | 9 --------- test-radar-base.sh | 23 ----------------------- 4 files changed, 1 insertion(+), 52 deletions(-) diff --git a/README.md b/README.md index f126a21..b9268ee 100644 --- a/README.md +++ b/README.md @@ -137,21 +137,6 @@ export PS1="$PS1\$(git-radar --bash --fetch)" export PROMPT="$PROMPT$(git-radar --zsh --fetch) " ``` -### (Optional) Minimal mode - -If you wish to keep the length of your prompt shorter, you can call git-radar with `--minimal` which will render the new prompt without the `git:` part - -**Bash** -```bash -export PS1="$PS1\$(git-radar --bash --fetch --minimal) " -``` -(note: the `\` escaping the `$` is important) - -**Zsh** -```zsh -export PROMPT="$PROMPT$(git-radar --zsh --fetch --minimal) " -``` - ## License Git Radar is licensed under the MIT license. diff --git a/prompt.bash b/prompt.bash index 1e79cd9..429c88d 100755 --- a/prompt.bash +++ b/prompt.bash @@ -1,15 +1,11 @@ #! /usr/bin/env bash dot="$(cd "$(dirname "$0")"; pwd)" -git_label="" args=$@ source "$dot/radar-base.sh" if is_repo; then - if show_git_label $args; then - git_label="git:" - fi - printf " \x01\033[1;30m\x02$git_label(\x01\033[0m\x02" + printf " \x01\033[1;30m\x02git:(\x01\033[0m\x02" if show_remote_status $args; then bash_color_remote_commits fi diff --git a/radar-base.sh b/radar-base.sh index a2f5115..d019629 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -1,4 +1,3 @@ -IS_MINIMAL='--minimal' NO_REMOTE_STATUS='--no-remote-status' dot_git="" @@ -472,14 +471,6 @@ zsh_color_remote_commits() { printf %s "$remote" } - -show_git_label() { - if [[ $@ == *$IS_MINIMAL* ]]; then - return 1 # don't show the git label - fi - return 0 -} - show_remote_status() { if [[ $@ == *$NO_REMOTE_STATUS* ]]; then return 1 # don't show the git remote status diff --git a/test-radar-base.sh b/test-radar-base.sh index ca95136..9f7f8ee 100755 --- a/test-radar-base.sh +++ b/test-radar-base.sh @@ -2,29 +2,6 @@ scriptDir="$(cd "$(dirname "$0")"; pwd)" source "$scriptDir/radar-base.sh" -test_show_git_label() { - show_git_label - assertTrue $? - - show_git_label --bash - assertTrue $? - - show_git_label --bash --fetch - assertTrue $? - - show_git_label --bash --minimal --fetch - assertFalse $? - - show_git_label --bash --fetch --minimal - assertFalse $? - - show_git_label --minimal --bash --fetch - assertFalse $? - - show_git_label --bash --fetch --minimal --no-remote-status - assertFalse $? -} - test_show_remote_status() { show_remote_status assertTrue $? -- cgit v1.2.3 From c03a462177bc2ec469a0cdb06234d08f35054966 Mon Sep 17 00:00:00 2001 From: Reinaldo Colina Date: Fri, 28 Aug 2015 20:23:06 -0700 Subject: Added change for issue-17 to prompt.zsh as well --- prompt.zsh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/prompt.zsh b/prompt.zsh index cb1eb91..a5ccba5 100755 --- a/prompt.zsh +++ b/prompt.zsh @@ -1,12 +1,15 @@ #! /usr/bin/env zsh dot="$(cd "$(dirname "$0")"; pwd)" +args=$@ source "$dot/radar-base.sh" if is_repo; then autoload colors && colors printf '%s' "%{$fg_bold[black]%} git:(%{$reset_color%}" - zsh_color_remote_commits + if show_remote_status $args; then + zsh_color_remote_commits + fi readable_branch_name zsh_color_local_commits printf '%s' "%{$fg_bold[black]%})%{$reset_color%}" -- cgit v1.2.3