Skip to content

Commit

Permalink
Merge branch 'master' of github.com:michaeldfallen/git-radar into hal…
Browse files Browse the repository at this point in the history
…lzy_#70
  • Loading branch information
michaeldfallen committed Oct 21, 2015
2 parents 4044554 + 934f6fd commit 13110ae
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 119 deletions.
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -77,7 +78,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
Expand Down Expand Up @@ -156,6 +157,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)

Expand Down Expand Up @@ -213,6 +221,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
Expand All @@ -222,8 +231,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

Expand Down Expand Up @@ -530,13 +539,26 @@ 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.

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
Expand Down
3 changes: 3 additions & 0 deletions git-radar
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand All @@ -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:"
Expand Down
Binary file added images/stash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 51 additions & 10 deletions radar-base.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
NO_REMOTE_STATUS='--no-remote-status'

dot_git=""
stat_type=""
cwd=""
remote=""
rcfile_path="$HOME"
Expand Down Expand Up @@ -50,15 +51,19 @@ 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"}"

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"
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() {
Expand All @@ -84,17 +89,20 @@ 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}%}"
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}%}"
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() {
Expand Down Expand Up @@ -133,6 +141,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
Expand All @@ -157,7 +174,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%Y "$(dot_git)/lastupdatetime" 2>/dev/null || printf '%s' "0")"
fi
}

Expand Down Expand Up @@ -213,15 +230,18 @@ 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)"
local localRef="$(branch_name)"
local remote="$(git config --get "branch.$localRef.remote")"
if [[ -n $remote ]]; then
local remoteBranch="$(git config --get "branch.${localRef}.merge" | sed -e 's/^refs\/heads\///')"
if [[ -n $remoteBranch ]]; then
printf '%s' $remoteBranch
printf '%s/%s' $remote $remoteBranch
return 0
else
return 1
return 1
fi
else
return 1
fi
}

Expand Down Expand Up @@ -511,12 +531,24 @@ show_remote_status() {
return 0
}

stashed_status() {
printf '%s' "$(git stash list | wc -l 2>/dev/null | grep -oEi '[0-9][0-9]*')"
}

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=""
remote_sed=""
local_sed=""
changes_sed=""
stash_sed=""


if_pre="%\{([^%{}]{1,}:){0,1}"
Expand All @@ -533,7 +565,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
Expand All @@ -556,10 +588,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"
}
1 change: 1 addition & 0 deletions test
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
./test-branches.sh
./test-files.sh
./test-status.sh
./test-stash.sh
./test-colors.sh
./test-format-config.sh
Loading

0 comments on commit 13110ae

Please sign in to comment.