From 2d5412e99be6d9fab50169ad0cf290e022fc6e9b Mon Sep 17 00:00:00 2001 From: James Smith Date: Sat, 19 Mar 2011 17:50:24 -0700 Subject: [PATCH 1/3] Added new function git_remote_status to check if we are ahead, behind or diverged from the remote branch --- lib/git.zsh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/git.zsh b/lib/git.zsh index 8512de8a4..75367f877 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -4,6 +4,7 @@ function git_prompt_info() { echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX" } +# get dirty status of the current working tree parse_git_dirty () { if [[ -n $(git status -s 2> /dev/null) ]]; then echo "$ZSH_THEME_GIT_PROMPT_DIRTY" @@ -12,6 +13,26 @@ parse_git_dirty () { fi } +# get the difference between the local and remote branches +git_remote_status() { + remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} --symbolic-full-name 2>/dev/null)/refs\/remotes\/} + if [[ -n ${remote} ]] ; then + ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l) + behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l) + + if [ $ahead -eq 0 ] && [ $behind -gt 0 ] + then + echo "$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE" + elif [ $ahead -gt 0 ] && [ $behind -eq 0 ] + then + echo "$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE" + elif [ $ahead -gt 0 ] && [ $behind -gt 0 ] + then + echo "$ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE" + fi + fi +} + # get the status of the working tree git_prompt_status() { INDEX=$(git status --porcelain 2> /dev/null) From a15a8c4a98bc1aff024c3ef44dec48309ff4f90b Mon Sep 17 00:00:00 2001 From: James Smith Date: Sat, 19 Mar 2011 17:51:22 -0700 Subject: [PATCH 2/3] New theme 'intheloop' which demonstrates the git_remote_status function --- themes/intheloop.zsh-theme | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 themes/intheloop.zsh-theme diff --git a/themes/intheloop.zsh-theme b/themes/intheloop.zsh-theme new file mode 100644 index 000000000..c4736422d --- /dev/null +++ b/themes/intheloop.zsh-theme @@ -0,0 +1,18 @@ +# ZSH theme by James Smith (http://loopj.com) +# A multiline prompt with username, hostname, full path, return status, git branch, git dirty status, git remote status + +local return_status="%{$fg[red]%}%(?..⏎)%{$reset_color%}" + +PROMPT=' +%{$fg_bold[grey]%}[%{$reset_color%}%{$fg_bold[green]%}%n@%m%{$reset_color%}%{$fg_bold[grey]%}]%{$reset_color%} %{$fg_bold[blue]%}%10c%{$reset_color%} $(git_prompt_info) $(git_remote_status) +%{$fg_bold[cyan]%}❯%{$reset_color%} ' + +RPROMPT='${return_status}%{$reset_color%}' + +ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[grey]%}(%{$fg[red]%}" +ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[grey]%}) %{$fg[yellow]%}⚡%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[grey]%})" +ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE="%{$fg_bold[magenta]%}↓%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE="%{$fg_bold[magenta]%}↑%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE="%{$fg_bold[magenta]%}↕%{$reset_color%}" \ No newline at end of file From 00bff0a9963d4b36e6afc968449781c727bfef3b Mon Sep 17 00:00:00 2001 From: James Smith Date: Thu, 20 Sep 2012 19:35:09 -0700 Subject: [PATCH 3/3] Red prompt for remote hosts --- themes/intheloop.zsh-theme | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/themes/intheloop.zsh-theme b/themes/intheloop.zsh-theme index c4736422d..85b4a4d95 100644 --- a/themes/intheloop.zsh-theme +++ b/themes/intheloop.zsh-theme @@ -3,10 +3,16 @@ local return_status="%{$fg[red]%}%(?..⏎)%{$reset_color%}" +local host_color="green" +if [ -n "$SSH_CLIENT" ]; then + local host_color="red" +fi + PROMPT=' -%{$fg_bold[grey]%}[%{$reset_color%}%{$fg_bold[green]%}%n@%m%{$reset_color%}%{$fg_bold[grey]%}]%{$reset_color%} %{$fg_bold[blue]%}%10c%{$reset_color%} $(git_prompt_info) $(git_remote_status) +%{$fg_bold[grey]%}[%{$reset_color%}%{$fg_bold[${host_color}]%}%n@%m%{$reset_color%}%{$fg_bold[grey]%}]%{$reset_color%} %{$fg_bold[blue]%}%10c%{$reset_color%} $(git_prompt_info) $(git_remote_status) %{$fg_bold[cyan]%}❯%{$reset_color%} ' + RPROMPT='${return_status}%{$reset_color%}' ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[grey]%}(%{$fg[red]%}"