From b9b9c432fab49de44006aae2bff973ad98818c53 Mon Sep 17 00:00:00 2001 From: sonnym Date: Wed, 21 Mar 2012 14:59:08 -0400 Subject: [PATCH 1/5] add theme --- themes/hybrid.zsh-theme | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 themes/hybrid.zsh-theme diff --git a/themes/hybrid.zsh-theme b/themes/hybrid.zsh-theme new file mode 100644 index 000000000..26d925ec5 --- /dev/null +++ b/themes/hybrid.zsh-theme @@ -0,0 +1,6 @@ +# Theme with full path names and hostname +# Handy if you work on different servers all the time; +PROMPT='%{$fg[cyan]%}%n%{$reset_color%}@%{$fg[yellow]%}%M:%{$fg[green]%}${PWD/#$HOME/~}%{$reset_color%} $(git_prompt_info) %(!.#.$) ' + +ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[cyan]%}git:(" +ZSH_THEME_GIT_PROMPT_SUFFIX=")%{$reset_color%}" From 30c560cfb4b936207090d48b0db895a81f273969 Mon Sep 17 00:00:00 2001 From: sonnym Date: Sun, 25 Mar 2012 16:10:32 -0400 Subject: [PATCH 2/5] make git_prompt_info aware of detached HEAD this commit also checks for tag names once the repository has been determined to be in a detached HEAD state --- lib/git.zsh | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/git.zsh b/lib/git.zsh index fb4ad8ca6..86f46ed5d 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -1,23 +1,41 @@ # get the name of the branch we are on function git_prompt_info() { - ref=$(git symbolic-ref HEAD 2> /dev/null) || return + ref=$(git symbolic-ref HEAD 2> /dev/null) + if [ -z $ref ]; then + # check if in detached HEAD mode + branch_name=$(git status -sb $(git_submodule_syntax) 2> /dev/null) + if [ $branch_name = "## HEAD (no branch)" ]; then + # set tag name if found + tag_name=$(git name-rev --name-only $(git --no-pager show --stat 2> /dev/null | head -n 1 | awk '{ print $2 }') 2> /dev/null) + if [ -z $tag_name ]; then + ref="detached HEAD" + else + ref=$tag_name + fi + else + return + fi + fi echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX" } # Checks if working tree is dirty parse_git_dirty() { - local SUBMODULE_SYNTAX='' - if [[ $POST_1_7_2_GIT -gt 0 ]]; then - SUBMODULE_SYNTAX="--ignore-submodules=dirty" - fi - if [[ -n $(git status -s ${SUBMODULE_SYNTAX} 2> /dev/null) ]]; then + if [[ -n $(git status -s $(git_submodule_syntax) 2> /dev/null) ]]; then echo "$ZSH_THEME_GIT_PROMPT_DIRTY" else echo "$ZSH_THEME_GIT_PROMPT_CLEAN" fi } +git_submodule_syntax() { + if [[ $POST_1_7_2_GIT -gt 0 ]]; then + echo "--ignore-submodules=dirty" + else + echo "" + fi +} # Checks if there are commits ahead from remote function git_prompt_ahead() { From 64e69f6ab2fd5f4fcdf7d191e5a8fb13d2d3f3f9 Mon Sep 17 00:00:00 2001 From: sonnym Date: Mon, 26 Mar 2012 10:52:58 -0400 Subject: [PATCH 3/5] update theme to include ruby --- themes/hybrid.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/hybrid.zsh-theme b/themes/hybrid.zsh-theme index 26d925ec5..3dadfd9a5 100644 --- a/themes/hybrid.zsh-theme +++ b/themes/hybrid.zsh-theme @@ -1,6 +1,6 @@ # Theme with full path names and hostname # Handy if you work on different servers all the time; -PROMPT='%{$fg[cyan]%}%n%{$reset_color%}@%{$fg[yellow]%}%M:%{$fg[green]%}${PWD/#$HOME/~}%{$reset_color%} $(git_prompt_info) %(!.#.$) ' +PROMPT='%{$fg[cyan]%}%n%{$reset_color%}@%{$fg[yellow]%}%M:%{$fg[green]%}${PWD/#$HOME/~}%{$reset_color%} %{$fg[red]%}rb:($(rbenv_prompt_info))%{$reset_color%}$(git_prompt_info) %(!.#.$) ' ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[cyan]%}git:(" ZSH_THEME_GIT_PROMPT_SUFFIX=")%{$reset_color%}" From ef785d46b8d1cb3078609fb1925e3f2a2c33721f Mon Sep 17 00:00:00 2001 From: sonnym Date: Fri, 30 Mar 2012 13:25:39 -0400 Subject: [PATCH 4/5] fix broken equality check when outside git repo --- lib/git.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git.zsh b/lib/git.zsh index 86f46ed5d..915575246 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -4,7 +4,7 @@ function git_prompt_info() { if [ -z $ref ]; then # check if in detached HEAD mode branch_name=$(git status -sb $(git_submodule_syntax) 2> /dev/null) - if [ $branch_name = "## HEAD (no branch)" ]; then + if [ "$branch_name" = "## HEAD (no branch)" ]; then # set tag name if found tag_name=$(git name-rev --name-only $(git --no-pager show --stat 2> /dev/null | head -n 1 | awk '{ print $2 }') 2> /dev/null) if [ -z $tag_name ]; then From 0887040c871983148db8e32bd836bcc5a7c2e18d Mon Sep 17 00:00:00 2001 From: sonnym Date: Tue, 10 Apr 2012 17:35:19 -0400 Subject: [PATCH 5/5] ignore subsequent lines of git status as they may break the equality check by including changes to the repository --- lib/git.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git.zsh b/lib/git.zsh index 915575246..b0d99bd2b 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -3,7 +3,7 @@ function git_prompt_info() { ref=$(git symbolic-ref HEAD 2> /dev/null) if [ -z $ref ]; then # check if in detached HEAD mode - branch_name=$(git status -sb $(git_submodule_syntax) 2> /dev/null) + branch_name=$(git status -sb $(git_submodule_syntax) 2> /dev/null | head -n 1) if [ "$branch_name" = "## HEAD (no branch)" ]; then # set tag name if found tag_name=$(git name-rev --name-only $(git --no-pager show --stat 2> /dev/null | head -n 1 | awk '{ print $2 }') 2> /dev/null)