diff options
-rw-r--r-- | README.md | 19 | ||||
-rwxr-xr-x | git-radar | 3 | ||||
-rwxr-xr-x | radar-base.sh | 18 | ||||
-rwxr-xr-x | test | 1 | ||||
-rwxr-xr-x | test-stash.sh | 50 |
5 files changed, 91 insertions, 0 deletions
@@ -156,6 +156,13 @@ Prompt | Meaning The use of feature is controlled by the `GIT_RADAR_FORMAT` environment variable. See [Customise your prompt](#customise-your-prompt) for how to personalise this. +### Stash status +The prompt will show you whether and how many stashes you have stored. + +Prompt | Meaning +---------------------------|--------------- +![git:(master) 1≡] | We have one stash + If you don't rely on this status, you can always hide this part of the prompt by [customising your prompt](#customise-your-prompt) @@ -510,6 +517,18 @@ tracked by git. It is unset by `GIT_RADAR_COLOR_CHANGES_RESET` which you can set if you want a different background colour to return to. +##### Colouring the stash status + +**GIT_RADAR_COLOR_STASH='[colour code]'** +``` +git:(my-branch) 1≡ + ^ +``` +The colour to use for the lines that indicates how many stashes you have stored. + +It is unset by `GIT_RADAR_COLOR_STASH_RESET` which you can set if you want +a different background colour to return to. + ## License Git Radar is licensed under the MIT license. @@ -30,6 +30,7 @@ if [[ -z $@ ]]; then _conflicted_them="\033[1;33mT\033[0m" _ahead_master="\xF0\x9D\x98\xAE \033[1;32m←\033[0m" _local_diverged="\033[1;33m⇵\033[0m" + _stash="\033[1;33m≡\033[0m" echo "git-radar - a heads up display for git" echo "" echo "examples:" @@ -51,6 +52,8 @@ if [[ -z $@ ]]; then echo " # rebase complete, our rewritten commits now need pushed up" printf " $_git$_ahead_master 3 $_my_branch$_endgit" echo " # origin/my-branch is up to date with master and has our 3 commits waiting merge" + printf " $_git$_master$_endgit 3$_stash" + echo " # You have 3 stashes stored" echo "" echo "usage:" diff --git a/radar-base.sh b/radar-base.sh index 258e5b1..26ea328 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -36,6 +36,8 @@ prepare_bash_colors() { COLOR_CHANGES_CONFLICTED="\x01${GIT_RADAR_COLOR_CHANGES_CONFLICTED:-"\\033[1;33m"}\x02" COLOR_CHANGES_UNTRACKED="\x01${GIT_RADAR_COLOR_CHANGES_UNTRACKED:-"\\033[1;37m"}\x02" + COLOR_STASH="\x01${GIT_RADAR_COLOR_STASH:-"\\033[1;33m"}\x02" + COLOR_BRANCH="\x01${GIT_RADAR_COLOR_BRANCH:-"\\033[0m"}\x02" MASTER_SYMBOL="${GIT_RADAR_MASTER_SYMBOL:-"\\x01\\033[0m\\x02\\xF0\\x9D\\x98\\xAE\\x01\\033[0m\\x02"}" @@ -45,6 +47,8 @@ prepare_bash_colors() { RESET_COLOR_REMOTE="\x01${GIT_RADAR_COLOR_REMOTE_RESET:-"\\033[0m"}\x02" RESET_COLOR_CHANGES="\x01${GIT_RADAR_COLOR_CHANGES_RESET:-"\\033[0m"}\x02" RESET_COLOR_BRANCH="\x01${GIT_RADAR_COLOR_BRANCH_RESET:-"\\033[0m"}\x02" + RESET_COLOR_STASH="\x01${GIT_RADAR_COLOR_STASH:-"\\033[0m"}\x02" + } prepare_zsh_colors() { @@ -70,6 +74,8 @@ prepare_zsh_colors() { COLOR_CHANGES_CONFLICTED="%{${GIT_RADAR_COLOR_CHANGES_CONFLICTED:-$fg_bold[yellow]}%}" COLOR_CHANGES_UNTRACKED="%{${GIT_RADAR_COLOR_CHANGES_UNTRACKED:-$fg_bold[white]}%}" + COLOR_STASH="%{${GIT_RADAR_COLOR_STASH:-$fg_bold[yellow]}%}" + local italic_m="$(printf '\xF0\x9D\x98\xAE')" COLOR_BRANCH="%{${GIT_RADAR_COLOR_BRANCH:-$reset_color}%}" @@ -81,6 +87,7 @@ prepare_zsh_colors() { RESET_COLOR_REMOTE="%{${GIT_RADAR_COLOR_REMOTE_RESET:-$reset_color}%}" RESET_COLOR_CHANGES="%{${GIT_RADAR_COLOR_CHANGES_RESET:-$reset_color}%}" RESET_COLOR_BRANCH="%{${GIT_RADAR_COLOR_BRANCH_RESET:-$reset_color}%}" + RESET_COLOR_STASH="%{${GIT_RADAR_COLOR_STASH:-$reset_color}%}" } in_current_dir() { @@ -495,6 +502,17 @@ show_remote_status() { return 0 } +stashed_status() { + printf '%s' "$(git stash list | wc -l 2>/dev/null)" +} + +stash_status() { + local number_stashes="$(stashed_status)" + if [ $number_stashes -gt 0 ]; then + printf $PRINT_F_OPTION " $number_stashes$COLOR_STASH≡$RESET_COLOR_STASH" + fi +} + render_prompt() { output="$PROMPT_FORMAT" branch_sed="" @@ -6,5 +6,6 @@ ./test-branches.sh ./test-files.sh ./test-status.sh +./test-stash.sh ./test-colors.sh ./test-format-config.sh diff --git a/test-stash.sh b/test-stash.sh new file mode 100755 index 0000000..aecd83c --- /dev/null +++ b/test-stash.sh @@ -0,0 +1,50 @@ +#!/bin/bash +scriptDir="$(cd "$(dirname "$0")"; pwd)" + +source "$scriptDir/radar-base.sh" + +tmpfile="" + +cd_to_tmp() { + tmpfile="/tmp/git-prompt-tests-$(time_now)$1" + mkdir -p "$tmpfile" + cd "$tmpfile" +} + +rm_tmp() { + cd $scriptDir + rm -rf /tmp/git-prompt-tests* +} + +test_unstashed_status() { + cd_to_tmp + git init --quiet + + assertEquals "0" "$(stashed_status)" + + rm_tmp +} + +test_stashed_status() { + cd_to_tmp + git init --quiet + + touch foo + git add --all + git commit -m "Initial commit" >/dev/null + echo "test">foo + git stash > /dev/null + assertEquals "1" "$(stashed_status)" + + echo "test2">foo + git stash > /dev/null + assertEquals "2" "$(stashed_status)" + + git stash drop > /dev/null + assertEquals "1" "$(stashed_status)" + + + rm_tmp +} + +. ./shunit/shunit2 |