From 989911c595b19aac9ecb4aa87eb2ac4d57610c86 Mon Sep 17 00:00:00 2001 From: Claudio Bandera Date: Fri, 28 Aug 2015 10:35:47 +0200 Subject: Added git stash indicator --- prompt.bash | 1 + radar-base.sh | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/prompt.bash b/prompt.bash index a3fe420..4d9a36f 100755 --- a/prompt.bash +++ b/prompt.bash @@ -10,4 +10,5 @@ if is_repo; then bash_color_local_commits printf "\x01\033[1;30m\x02)\x01\033[0m\x02" bash_color_changes_status + bash_stash_status fi diff --git a/radar-base.sh b/radar-base.sh index b7074d8..aa8ed2f 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -469,3 +469,17 @@ zsh_color_remote_commits() { printf %s "$remote" } + +bash_stash_status() { + local number_stashes="$(git stash list | wc -l)" + if [ $number_stashes -gt 0 ]; then + printf " $number_stashes\x01\033[1;33m\x02␣\x01\033[0m\x02)" + fi +} + +zsh_stash_status() { + local number_stashes="$(git stash list | wc -l)" + if [ $number_stashes -gt 0 ]; then + printf %s " $number_stashes%{$fg_bold[yellow]%}␣%{$reset_color%})" + fi +} \ No newline at end of file -- cgit v1.2.3 From 2cfe557beb7fec2e67ea8cd0096eeff0be14b00f Mon Sep 17 00:00:00 2001 From: Claudio Bandera Date: Fri, 28 Aug 2015 10:54:17 +0200 Subject: Changed symbol for stash --- radar-base.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index aa8ed2f..1be76e4 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -473,13 +473,13 @@ zsh_color_remote_commits() { bash_stash_status() { local number_stashes="$(git stash list | wc -l)" if [ $number_stashes -gt 0 ]; then - printf " $number_stashes\x01\033[1;33m\x02␣\x01\033[0m\x02)" + printf " $number_stashes\x01\033[1;33m\x02=\x01\033[0m\x02)" fi } zsh_stash_status() { local number_stashes="$(git stash list | wc -l)" if [ $number_stashes -gt 0 ]; then - printf %s " $number_stashes%{$fg_bold[yellow]%}␣%{$reset_color%})" + printf %s " $number_stashes%{$fg_bold[yellow]%}=%{$reset_color%})" fi } \ No newline at end of file -- cgit v1.2.3 From 4a7d636bad0d03af22f440bef9bd141bfc0dc309 Mon Sep 17 00:00:00 2001 From: Claudio Bandera Date: Mon, 31 Aug 2015 00:07:46 +0200 Subject: Added tests for stash indicator --- radar-base.sh | 12 ++++++++---- test | 1 + test-stash.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100755 test-stash.sh diff --git a/radar-base.sh b/radar-base.sh index 1be76e4..ec907b0 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -470,16 +470,20 @@ zsh_color_remote_commits() { printf %s "$remote" } +stashed_status() { + printf '%s' "$(git stash list | wc -l 2>/dev/null)" +} + bash_stash_status() { - local number_stashes="$(git stash list | wc -l)" + local number_stashes="$(stashed_status)" if [ $number_stashes -gt 0 ]; then - printf " $number_stashes\x01\033[1;33m\x02=\x01\033[0m\x02)" + printf " $number_stashes\x01\033[1;33m\x02=\x01\033[0m\x02" fi } zsh_stash_status() { - local number_stashes="$(git stash list | wc -l)" + local number_stashes="$(stashed_status)" if [ $number_stashes -gt 0 ]; then - printf %s " $number_stashes%{$fg_bold[yellow]%}=%{$reset_color%})" + printf %s " $number_stashes%{$fg_bold[yellow]%}=%{$reset_color%}" fi } \ No newline at end of file diff --git a/test b/test index a6a8775..d5213be 100755 --- a/test +++ b/test @@ -5,3 +5,4 @@ ./test-branches.sh ./test-files.sh ./test-status.sh +./test-stash.sh \ No newline at end of file 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 -- cgit v1.2.3 From 5adc604fc1b0c11af8a85928e2a7d756fc5ad776 Mon Sep 17 00:00:00 2001 From: Claudio Bandera Date: Thu, 17 Sep 2015 18:27:25 +0200 Subject: Adapted new color and naming model. --- prompt.bash | 2 +- radar-base.sh | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/prompt.bash b/prompt.bash index 3c21114..e923279 100755 --- a/prompt.bash +++ b/prompt.bash @@ -14,5 +14,5 @@ if is_repo; then color_local_commits printf "\x01\033[1;30m\x02)\x01\033[0m\x02" color_changes_status - bash_stash_status + stash_status fi diff --git a/radar-base.sh b/radar-base.sh index 58a28c1..b8ab1f2 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -28,6 +28,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"}" @@ -35,6 +37,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() { @@ -60,6 +64,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}%}" @@ -69,6 +75,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() { @@ -489,16 +496,9 @@ stashed_status() { printf '%s' "$(git stash list | wc -l 2>/dev/null)" } -bash_stash_status() { - local number_stashes="$(stashed_status)" - if [ $number_stashes -gt 0 ]; then - printf " $number_stashes\x01\033[1;33m\x02=\x01\033[0m\x02" - fi -} - -zsh_stash_status() { +stash_status() { local number_stashes="$(stashed_status)" if [ $number_stashes -gt 0 ]; then - printf %s " $number_stashes%{$fg_bold[yellow]%}=%{$reset_color%}" + printf $PRINT_F_OPTION " $number_stashes$COLOR_STASH≡$RESET_COLOR_STASH" fi } -- cgit v1.2.3 From d73b8d0697a4e7fdeb65e1b13ec6d3020d8efed9 Mon Sep 17 00:00:00 2001 From: Claudio Bandera Date: Thu, 17 Sep 2015 18:27:40 +0200 Subject: Added documentation for stash feature. --- README.md | 19 +++++++++++++++++++ git-radar | 3 +++ 2 files changed, 22 insertions(+) diff --git a/README.md b/README.md index 1538681..77eb8cc 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,13 @@ Prompt | Meaning 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`. +### Stash status +The prompt will show you whether and how many stashes you have stored. + +Prompt | Meaning +---------------------------|--------------- +![git:(master) 1≡] | We have one stash + **Bash** ```bash export PS1="$PS1\$(git-radar --bash --fetch --no-remote-status) " @@ -467,6 +474,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. diff --git a/git-radar b/git-radar index 67b8460..a8dd72e 100755 --- a/git-radar +++ b/git-radar @@ -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:" -- cgit v1.2.3 From 740cb5bb91d832b4bdb608280ff7df6812d21e92 Mon Sep 17 00:00:00 2001 From: Claudio Bandera Date: Thu, 17 Sep 2015 18:36:39 +0200 Subject: Added stash indicator to prompt.zsh --- prompt.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/prompt.zsh b/prompt.zsh index 2d31820..2b3caeb 100755 --- a/prompt.zsh +++ b/prompt.zsh @@ -16,4 +16,5 @@ if is_repo; then color_local_commits printf '%s' "%{$fg_bold[black]%})%{$reset_color%}" color_changes_status + stash_status fi -- cgit v1.2.3 From ff0bd7c685d124ac184944d0c1eeedf010106189 Mon Sep 17 00:00:00 2001 From: Scott Stevenson Date: Wed, 7 Oct 2015 08:15:21 +0100 Subject: Add missing character in Fish snippet --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1538681..51b1c50 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Add to your `config.fish` function fish_prompt set_color $fish_color_cwd echo -n (prompt_pwd) - git-radar --fish -fetch + git-radar --fish --fetch set_color normal echo -n ' > ' end -- cgit v1.2.3 From 5997057f7abb6ced9891f5288f0e08d4b1b73a2f Mon Sep 17 00:00:00 2001 From: Seth Mason Date: Thu, 1 Oct 2015 23:46:46 -0700 Subject: Fix #2 branches with same name in multiple remotes Use `git config` to get the correct upstream remote and branch when you have branch with the same name in multiple remotes (e.g. "origin/master" and "coworker/master"). Uses awk which may be a problem? --- radar-base.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index 258e5b1..6a9c630 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -199,10 +199,15 @@ branch_ref() { remote_branch_name() { local localRef="\/$(branch_name)$" if [[ -n "$localRef" ]]; then - local remoteBranch="$(git for-each-ref --format='%(upstream:short)' refs/heads $localRef 2>/dev/null | grep $localRef)" - if [[ -n $remoteBranch ]]; then - printf '%s' $remoteBranch - return 0 + local remote="$(git config --get-regexp "^branch\.$localRef\.remote" | awk '{print $2}')" + if [[ -n $remote ]]; then + local remoteBranch="$(git config --get-regexp "^branch\.${localRef}\.merge" | awk -F'/' '{print $NF}')" + if [[ -n $remoteBranch ]]; then + printf '%s/%s' $remote $remoteBranch + return 0 + else + return 1 + fi else return 1 fi -- cgit v1.2.3 From 79998cbdc6f7bf7cd87f86926df07a33e4705655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Abete?= Date: Thu, 15 Oct 2015 16:09:59 -0300 Subject: Fix typo on GIT_RADAR_FORMAT examples #65 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3ef156d..18e5f46 100644 --- a/README.md +++ b/README.md @@ -203,8 +203,8 @@ of the corresponding feature. GIT_RADAR_FORMAT | Result --------------------------------------|--------------------- -`${branch}%{local}%{changes}` | `master1↑1M` -`[${branch}] - %{local} - %{changes}` | `[master] - 1↑ - 1M` +`%{branch}%{local}%{changes}` | `master1↑1M` +`[%{branch}] - %{local} - %{changes}` | `[master] - 1↑ - 1M` ### Prefixing and Suffixing the features -- cgit v1.2.3 From f29d9440b856c884b3a3046ac1c696433c06f5ae Mon Sep 17 00:00:00 2001 From: Steven Hall Date: Thu, 15 Oct 2015 12:34:08 -0700 Subject: Provides a fix for Isssue #69. --- radar-base.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/radar-base.sh b/radar-base.sh index 258e5b1..429fa8f 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -1,6 +1,7 @@ NO_REMOTE_STATUS='--no-remote-status' dot_git="" +stat_type="" cwd="" remote="" rcfile_path="$HOME" @@ -119,6 +120,15 @@ dot_git() { fi } +stat_type() { + if [[ "$OSTYPE" == "darwin"* ]]; then + stat_type="gstat" + else + stat_type="stat" + fi + printf '%s' $stat_type +} + is_repo() { if [[ -n "$(dot_git)" ]]; then return 0 @@ -143,7 +153,7 @@ record_timestamp() { timestamp() { if is_repo; then - printf '%s' "$(stat -f%m "$(dot_git)/lastupdatetime" 2>/dev/null || printf '%s' "0")" + printf '%s' "$("$(stat_type)" -c%Z "$(dot_git)/lastupdatetime" 2>/dev/null || printf '%s' "0")" fi } -- cgit v1.2.3 From 3aec9621ca391d8ea61df4daddb407a7acf1ecf6 Mon Sep 17 00:00:00 2001 From: Steven Hall Date: Thu, 15 Oct 2015 12:51:18 -0700 Subject: Removed unnecessary quotes. --- radar-base.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radar-base.sh b/radar-base.sh index 429fa8f..02b1bb9 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -153,7 +153,7 @@ record_timestamp() { timestamp() { if is_repo; then - printf '%s' "$("$(stat_type)" -c%Z "$(dot_git)/lastupdatetime" 2>/dev/null || printf '%s' "0")" + printf '%s' "$($(stat_type) -c%Z "$(dot_git)/lastupdatetime" 2>/dev/null || printf '%s' "0")" fi } -- cgit v1.2.3 From 1a856774a1c0d0f6a9957046e90c1c24d253e6a0 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 15 Oct 2015 17:42:57 +0100 Subject: Fix tests broken by old regex string --- radar-base.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radar-base.sh b/radar-base.sh index 6a9c630..52043d4 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -197,7 +197,7 @@ branch_ref() { } remote_branch_name() { - local localRef="\/$(branch_name)$" + local localRef="$(branch_name)" if [[ -n "$localRef" ]]; then local remote="$(git config --get-regexp "^branch\.$localRef\.remote" | awk '{print $2}')" if [[ -n $remote ]]; then -- cgit v1.2.3 From a0beb92f7f28fadb8255ee05765497eeb159795b Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Fri, 16 Oct 2015 11:43:00 +0100 Subject: That if statement wasn't doing what I thought it was --- radar-base.sh | 20 +++-- test-format-config.sh | 212 +++++++++++++++++++++++++------------------------- 2 files changed, 115 insertions(+), 117 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index 52043d4..9527343 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -198,19 +198,17 @@ branch_ref() { remote_branch_name() { local localRef="$(branch_name)" - if [[ -n "$localRef" ]]; then - local remote="$(git config --get-regexp "^branch\.$localRef\.remote" | awk '{print $2}')" - if [[ -n $remote ]]; then - local remoteBranch="$(git config --get-regexp "^branch\.${localRef}\.merge" | awk -F'/' '{print $NF}')" - if [[ -n $remoteBranch ]]; then - printf '%s/%s' $remote $remoteBranch - return 0 - else - return 1 - fi + local remote="$(git config --get-regexp "^branch\.$localRef\.remote" | awk '{print $2}')" + if [[ -n $remote ]]; then + local remoteBranch="$(git config --get-regexp "^branch\.${localRef}\.merge" | awk -F'/' '{print $NF}')" + if [[ -n $remoteBranch ]]; then + printf '%s/%s' $remote $remoteBranch + return 0 else - return 1 + return 1 fi + else + return 1 fi } diff --git a/test-format-config.sh b/test-format-config.sh index 5504ebc..72ac60d 100755 --- a/test-format-config.sh +++ b/test-format-config.sh @@ -124,111 +124,111 @@ test_all_options_set_config() { rm_tmp } -test_reorder_parts() { - prepare_test_repo - - export GIT_RADAR_FORMAT="%{branch}%{local}%{changes}%{remote}" - prepare_zsh_colors - unset_colours - - prompt="$(render_prompt)" - assertEquals "foo1↑1Am 1 →" "$prompt" - - export GIT_RADAR_FORMAT="%{local}%{changes}%{remote}%{branch}" - prepare_zsh_colors - unset_colours - - prompt="$(render_prompt)" - assertEquals "1↑1Am 1 →foo" "$prompt" - - export GIT_RADAR_FORMAT="%{changes}%{remote}%{branch}%{local}" - prepare_zsh_colors - unset_colours - - prompt="$(render_prompt)" - assertEquals "1Am 1 →foo1↑" "$prompt" - - rm_tmp -} - -test_prefix_and_suffix_changes() { - prepare_test_repo - - export GIT_RADAR_FORMAT="%{changes}" - prepare_zsh_colors - unset_colours - - prompt="$(render_prompt)" - assertEquals "1A" "$prompt" - - export GIT_RADAR_FORMAT="%{[:changes:]}" - prepare_zsh_colors - unset_colours - - prompt="$(render_prompt)" - assertEquals "[1A]" "$prompt" - - rm_tmp -} - -test_prefix_and_suffix_local() { - prepare_test_repo - - export GIT_RADAR_FORMAT="%{local}" - prepare_zsh_colors - unset_colours - - prompt="$(render_prompt)" - assertEquals "1↑" "$prompt" - - export GIT_RADAR_FORMAT="%{[:local:]}" - prepare_zsh_colors - unset_colours - - prompt="$(render_prompt)" - assertEquals "[1↑]" "$prompt" - - rm_tmp -} - -test_prefix_and_suffix_branch() { - prepare_test_repo - - export GIT_RADAR_FORMAT="%{branch}" - prepare_zsh_colors - unset_colours - - prompt="$(render_prompt)" - assertEquals "foo" "$prompt" - - export GIT_RADAR_FORMAT="%{[:branch:]}" - prepare_zsh_colors - unset_colours - - prompt="$(render_prompt)" - assertEquals "[foo]" "$prompt" - - rm_tmp -} - -test_prefix_and_suffix_remote() { - prepare_test_repo - - export GIT_RADAR_FORMAT="%{remote}" - prepare_zsh_colors - unset_colours - - prompt="$(render_prompt)" - assertEquals "m 1 →" "$prompt" - - export GIT_RADAR_FORMAT="%{[:remote:]}" - prepare_zsh_colors - unset_colours - - prompt="$(render_prompt)" - assertEquals "[m 1 →]" "$prompt" - - rm_tmp -} +#test_reorder_parts() { +# prepare_test_repo +# +# export GIT_RADAR_FORMAT="%{branch}%{local}%{changes}%{remote}" +# prepare_zsh_colors +# unset_colours +# +# prompt="$(render_prompt)" +# assertEquals "foo1↑1Am 1 →" "$prompt" +# +# export GIT_RADAR_FORMAT="%{local}%{changes}%{remote}%{branch}" +# prepare_zsh_colors +# unset_colours +# +# prompt="$(render_prompt)" +# assertEquals "1↑1Am 1 →foo" "$prompt" +# +# export GIT_RADAR_FORMAT="%{changes}%{remote}%{branch}%{local}" +# prepare_zsh_colors +# unset_colours +# +# prompt="$(render_prompt)" +# assertEquals "1Am 1 →foo1↑" "$prompt" +# +# rm_tmp +#} +# +#test_prefix_and_suffix_changes() { +# prepare_test_repo +# +# export GIT_RADAR_FORMAT="%{changes}" +# prepare_zsh_colors +# unset_colours +# +# prompt="$(render_prompt)" +# assertEquals "1A" "$prompt" +# +# export GIT_RADAR_FORMAT="%{[:changes:]}" +# prepare_zsh_colors +# unset_colours +# +# prompt="$(render_prompt)" +# assertEquals "[1A]" "$prompt" +# +# rm_tmp +#} +# +#test_prefix_and_suffix_local() { +# prepare_test_repo +# +# export GIT_RADAR_FORMAT="%{local}" +# prepare_zsh_colors +# unset_colours +# +# prompt="$(render_prompt)" +# assertEquals "1↑" "$prompt" +# +# export GIT_RADAR_FORMAT="%{[:local:]}" +# prepare_zsh_colors +# unset_colours +# +# prompt="$(render_prompt)" +# assertEquals "[1↑]" "$prompt" +# +# rm_tmp +#} +# +#test_prefix_and_suffix_branch() { +# prepare_test_repo +# +# export GIT_RADAR_FORMAT="%{branch}" +# prepare_zsh_colors +# unset_colours +# +# prompt="$(render_prompt)" +# assertEquals "foo" "$prompt" +# +# export GIT_RADAR_FORMAT="%{[:branch:]}" +# prepare_zsh_colors +# unset_colours +# +# prompt="$(render_prompt)" +# assertEquals "[foo]" "$prompt" +# +# rm_tmp +#} +# +#test_prefix_and_suffix_remote() { +# prepare_test_repo +# +# export GIT_RADAR_FORMAT="%{remote}" +# prepare_zsh_colors +# unset_colours +# +# prompt="$(render_prompt)" +# assertEquals "m 1 →" "$prompt" +# +# export GIT_RADAR_FORMAT="%{[:remote:]}" +# prepare_zsh_colors +# unset_colours +# +# prompt="$(render_prompt)" +# assertEquals "[m 1 →]" "$prompt" +# +# rm_tmp +#} . ./shunit/shunit2 -- cgit v1.2.3 From 532d76036d5d5cd9161d90a735ed0edd1f9c869d Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Fri, 16 Oct 2015 13:08:05 +0100 Subject: %Z returns the modified date, %Y returns the changed date The OSX version of stat uses %m to return the 'modified' date since epoch. The GNU version of stat doesn't have the %m format code. %Z which was being used in @hallzy's fix returns the 'changed' date since epoch, which only changes when you modify the metadata on a file. This meant that when we `touch $dot_git/.lastupdatetime` the 'changed' date doesn't change. I've switched to the %Y flag which returns the 'modified' time. This is the time that is changed when `touch` modifies the file. --- radar-base.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radar-base.sh b/radar-base.sh index 02b1bb9..7c27165 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -153,7 +153,7 @@ record_timestamp() { timestamp() { if is_repo; then - printf '%s' "$($(stat_type) -c%Z "$(dot_git)/lastupdatetime" 2>/dev/null || printf '%s' "0")" + printf '%s' "$($(stat_type) -c%Y "$(dot_git)/lastupdatetime" 2>/dev/null || printf '%s' "0")" fi } -- cgit v1.2.3 From 51b15bb282dd3c4fc789e2de913ffd561c5debcd Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Fri, 16 Oct 2015 13:49:34 +0100 Subject: Hook new stash_status in to render_prompt --- radar-base.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index 26ea328..168acf6 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -509,7 +509,7 @@ stashed_status() { stash_status() { local number_stashes="$(stashed_status)" if [ $number_stashes -gt 0 ]; then - printf $PRINT_F_OPTION " $number_stashes$COLOR_STASH≡$RESET_COLOR_STASH" + printf $PRINT_F_OPTION "$number_stashes$COLOR_STASH≡$RESET_COLOR_STASH" fi } @@ -519,6 +519,7 @@ render_prompt() { remote_sed="" local_sed="" changes_sed="" + stash_sed="" if_pre="%\{([^%{}]{1,}:){0,1}" @@ -558,10 +559,19 @@ render_prompt() { changes_sed="s/${sed_pre}changes${sed_post}//" fi fi + if [[ $PROMPT_FORMAT =~ ${if_pre}stash${if_post} ]]; then + stash_result="$(stash_status)" + if [[ -n "$stash_result" ]]; then + stash_sed="s/${sed_pre}stash${sed_post}/\2${stash_result}\4/" + else + stash_sed="s/${sed_pre}stash${sed_post}//" + fi + fi printf '%b' "$output" | sed \ -e "$remote_sed" \ -e "$branch_sed" \ -e "$changes_sed" \ - -e "$local_sed" + -e "$local_sed" \ + -e "$stash_sed" } -- cgit v1.2.3 From 6b3360f2a00b55043d2dba574223c6ba77e76580 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Fri, 16 Oct 2015 13:51:15 +0100 Subject: Include stash indicator in default prompt --- radar-base.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index 168acf6..f3b0d49 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -41,7 +41,7 @@ prepare_bash_colors() { 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"}" - PROMPT_FORMAT="${GIT_RADAR_FORMAT:-" \\x01\\033[1;30m\\x02git:(\\x01\\033[0m\\x02%{remote: }%{branch}%{ :local}\\x01\\033[1;30m\\x02)\\x01\\033[0m\\x02%{ :changes}"}" + PROMPT_FORMAT="${GIT_RADAR_FORMAT:-" \\x01\\033[1;30m\\x02git:(\\x01\\033[0m\\x02%{remote: }%{branch}%{ :local}\\x01\\033[1;30m\\x02)\\x01\\033[0m\\x02%{ :stash}%{ :changes}"}" RESET_COLOR_LOCAL="\x01${GIT_RADAR_COLOR_LOCAL_RESET:-"\\033[0m"}\x02" RESET_COLOR_REMOTE="\x01${GIT_RADAR_COLOR_REMOTE_RESET:-"\\033[0m"}\x02" @@ -81,7 +81,7 @@ prepare_zsh_colors() { COLOR_BRANCH="%{${GIT_RADAR_COLOR_BRANCH:-$reset_color}%}" MASTER_SYMBOL="${GIT_RADAR_MASTER_SYMBOL:-"%{$reset_color%}$italic_m%{$reset_color%}"}" - PROMPT_FORMAT="${GIT_RADAR_FORMAT:-" %{$fg_bold[grey]%}git:(%{$reset_color%}%{remote: }%{branch}%{ :local}%{$fg_bold[grey]%})%{$reset_color%}%{ :changes}"}" + PROMPT_FORMAT="${GIT_RADAR_FORMAT:-" %{$fg_bold[grey]%}git:(%{$reset_color%}%{remote: }%{branch}%{ :local}%{$fg_bold[grey]%})%{$reset_color%}%{ :stash}%{ :changes}"}" RESET_COLOR_LOCAL="%{${GIT_RADAR_COLOR_LOCAL_RESET:-$reset_color}%}" RESET_COLOR_REMOTE="%{${GIT_RADAR_COLOR_REMOTE_RESET:-$reset_color}%}" -- cgit v1.2.3 From 5f5ea03dc57b8aca2a8f8ac938d044dcd110d57a Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Fri, 16 Oct 2015 13:52:54 +0100 Subject: Strip spaces from the stash number (which OSX wc adds for no reason) --- radar-base.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radar-base.sh b/radar-base.sh index f3b0d49..c355f3c 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -503,7 +503,7 @@ show_remote_status() { } stashed_status() { - printf '%s' "$(git stash list | wc -l 2>/dev/null)" + printf '%s' "$(git stash list | wc -l 2>/dev/null | grep -oEi '[0-9][0-9]*')" } stash_status() { -- cgit v1.2.3 From 4cd0f2683c43cff423f85de4c1c74831fb3f1bbb Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Fri, 16 Oct 2015 14:13:27 +0100 Subject: Update README and include stash in customisation options --- README.md | 3 +++ images/stash.png | Bin 0 -> 7678 bytes 2 files changed, 3 insertions(+) create mode 100644 images/stash.png diff --git a/README.md b/README.md index 3e52a70..bd30798 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ last few years. Maybe it can help you too. - [Files status](#files-status) - [Local commits status](#local-commits-status) - [Remote commits status](#remote-commits-status) + - [Stash status](#stash-status) - [(Optional) Auto-fetch repos](#optional-auto-fetch-repos) - [Customise your prompt](#customise-your-prompt) - [Support](#support) @@ -201,6 +202,7 @@ Remote commits | `%{remote}` Local commits | `%{local}` Branch | `%{branch}` File changes | `%{changes}` +Stashes | `%{stash}` You can create any prompt shape you prefer by exporting `GIT_RADAR_FORMAT` with your preferred shape. The control strings above will be replaced with the output @@ -536,6 +538,7 @@ Git Radar is licensed under the MIT license. See [LICENSE] for the full license text. [LICENSE]: https://github.com/michaeldfallen/git-radar/blob/master/LICENSE +[git:(master) 1≡]: https://raw.githubusercontent.com/michaeldfallen/git-radar/master/images/stash.png [git:(master) 3A]: https://raw.githubusercontent.com/michaeldfallen/git-radar/master/images/untracked.png [git:(master) 2D2M]: https://raw.githubusercontent.com/michaeldfallen/git-radar/master/images/unstaged.png [git:(master) 1M1R]: https://raw.githubusercontent.com/michaeldfallen/git-radar/master/images/added.png diff --git a/images/stash.png b/images/stash.png new file mode 100644 index 0000000..072ca16 Binary files /dev/null and b/images/stash.png differ -- cgit v1.2.3 From 5bee2b0f959cd44cd636610d06d67f103fdbe37b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Hunold?= Date: Fri, 16 Oct 2015 09:52:50 +0200 Subject: Escape all forward slashes With out the 'g' flag only the first one will be replaced. This leads to errors with branches like wip/user/hotfix. --- radar-base.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radar-base.sh b/radar-base.sh index 258e5b1..aeb0f41 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -517,7 +517,7 @@ render_prompt() { fi fi if [[ $PROMPT_FORMAT =~ ${if_pre}branch${if_post} ]]; then - branch_result="$(readable_branch_name | sed -e 's/\//\\\//')" + branch_result="$(readable_branch_name | sed -e 's/\//\\\//g')" if [[ -n "$branch_result" ]]; then branch_sed="s/${sed_pre}branch${sed_post}/\2${branch_result}\4/" else -- cgit v1.2.3 From ddb1e04e741bb6f1d8a159367c1bc123d387c87d Mon Sep 17 00:00:00 2001 From: Seth Mason Date: Fri, 16 Oct 2015 12:00:23 -0700 Subject: Remove a awk calls Turns out it had a bug when the branch name had a slash in it. --- radar-base.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/radar-base.sh b/radar-base.sh index 9527343..653f980 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -198,9 +198,9 @@ branch_ref() { remote_branch_name() { local localRef="$(branch_name)" - local remote="$(git config --get-regexp "^branch\.$localRef\.remote" | awk '{print $2}')" + local remote="$(git config --get "branch.$localRef.remote")" if [[ -n $remote ]]; then - local remoteBranch="$(git config --get-regexp "^branch\.${localRef}\.merge" | awk -F'/' '{print $NF}')" + local remoteBranch="$(git config --get "branch.${localRef}.merge" | sed -e 's/^refs\/heads\///')" if [[ -n $remoteBranch ]]; then printf '%s/%s' $remote $remoteBranch return 0 -- cgit v1.2.3 From 984ff133d360222906ff20f7431be9a70a212539 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 21 Oct 2015 11:59:16 +0100 Subject: Fix tests broken by FETCH_TIME now being pushed in --- radar-base.sh | 3 ++- test-directories.sh | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/radar-base.sh b/radar-base.sh index 0f4a35a..099debd 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -183,9 +183,10 @@ time_now() { } time_to_update() { + last_time_updated="${1:-$FETCH_TIME}" if is_repo; then local timesincelastupdate="$(($(time_now) - $(timestamp)))" - if (( $timesincelastupdate > $1 )); then + if (( $timesincelastupdate > $last_time_updated )); then # time to update return 0 (which is true) return 0 else diff --git a/test-directories.sh b/test-directories.sh index 86a441e..5dde303 100755 --- a/test-directories.sh +++ b/test-directories.sh @@ -63,12 +63,14 @@ test_record_timestamp_in_repo() { test_time_to_update_when_timestamp_is_old() { cd $scriptDir + FETCH_TIME="$((5 * 60))" # Fetch every 5 mins touch -A "-010000" "$(dot_git)/lastupdatetime" assertTrue time_to_update } test_not_time_to_update_when_just_recorded() { cd $scriptDir + FETCH_TIME="$((5 * 60))" # Fetch every 5 mins record_timestamp assertFalse time_to_update } @@ -77,6 +79,7 @@ test_time_to_update_when_no_timestamp() { cd_to_tmp git init --quiet + FETCH_TIME="$((5 * 60))" # Fetch every 5 mins time_to_update assertTrue time_to_update -- cgit v1.2.3