From d40d2cb78d4c79671b912e9845972ce2cea9ba79 Mon Sep 17 00:00:00 2001 From: Ashley Dev Date: Thu, 2 Jun 2011 10:19:10 -0700 Subject: [PATCH] updates and cleanups to git prompt stuff --- plugins/git-prompt/git-prompt.plugin.zsh | 67 +++++++++--------- themes/ashleydev.zsh-theme | 88 ++++++++++++++---------- 2 files changed, 88 insertions(+), 67 deletions(-) diff --git a/plugins/git-prompt/git-prompt.plugin.zsh b/plugins/git-prompt/git-prompt.plugin.zsh index 46abeded0..23747d26a 100644 --- a/plugins/git-prompt/git-prompt.plugin.zsh +++ b/plugins/git-prompt/git-prompt.plugin.zsh @@ -3,14 +3,14 @@ # This example shows some of the things you in this plugin. This is how the # author uses it: # -# NOTE: make sure to add 'git-prompt' to your list of oh-my-zsh plugins (in your -# .zshrc) otherwise the git prompt info will not show up in your prompt. +# NOTE: make sure to add 'git' to your list of oh-my-zsh plugins (in your +# .zshrc) otherwise this git prompt info will not show up in your prompt. # # ---------------------- SAMPLE THEME FILE ------------------------ # -# # this is a simple example PROMPT with only git info in it: +# # this is a simple example PROMPT with only git +# # info from this plugin in it: # PROMPT='$__GIT_PROMPT_INFO# ' -# # # # Set GIT_PROMPT_SHORTCIRCUIT='off' to turn the # # short-circuit logic off. The short-circuit @@ -19,9 +19,9 @@ # # while the prompt is updating the dirty state # # info. Gathering dirty-state info can take a # # long time on large repositories, so if you -# # find that you're prompt is taking for ever to -# # show up, and you press ctrl-c, the short- -# # circuit logic will turn of the showing of +# # find that your prompt is taking for ever to +# # return, and you press ctrl-c, the short- +# # circuit logic will turn off the showing of # # dirty state for this repository (locally) and # # let you know, that way you won't be slowed # # down waiting for your prompt in large git @@ -30,38 +30,41 @@ # # # GIT_PROMPT_INFO_FUNC must be set to the # # function that defines your prompt info -# # in order to turn the git-prompt plugin on. -# # $ZSH/lib/git-prompt.zsh will cause +# # in order to turn this plugin on. # # $GIT_PROMPT_INFO_FUNC to be called when the -# # git prompt info needs to be updated. +# # git prompt info variable needs to be updated. # GIT_PROMPT_INFO_FUNC='update__GIT_PROMPT_INFO' # # GIT_PROMPT_SHOWUPSTREAM="verbose" # -# # Some color settings for the format +# # Some color settings for my prompt format # # '_C' for color: -# local _Cerror_="%{$fg[yellow]%}" # bad (empty) .git/ directory -# local _Cb_new_repo_="%{$fg_bold[default]%}" # branch color of new repo -# local _Cb_clean_="%{$fg_no_bold[green]%}" # branch color when clean -# local _Cb_dirty_="%{$fg_no_bold[red]%}" # branch color when dirty -# local _Cr_="%{$bold_color$fg[yellow]%}" # rebase info -# local _Ci_="%{$bold_color$fg[red]%}" # index info -# local _Cu_clean_="" # untracked files state when clean -# local _Cu_dirty_="%{$fg_bold[red]%}" # untracked files state when dirty -# local _Cp_="%{${fg[cyan]}%}" # upstream info -# local _Cs_="" # stash state -# # 'R'eset formating -# local R="%{$terminfo[sgr0]%}" +# if [[ "$DISABLE_COLOR" != "true" ]]; then +# local _Cerror_="%{$fg[yellow]%}" # bad (empty) .git/ directory +# local _Cb_new_repo_="%{$fg_bold[default]%}" # branch color of new repo +# local _Cb_clean_="%{$fg_no_bold[green]%}" # branch color when clean +# local _Cb_dirty_="%{$fg_no_bold[red]%}" # branch color when dirty +# local _Cr_="%{$bold_color$fg[yellow]%}" # rebase info +# local _Ci_="%{$bold_color$fg[red]%}" # index info +# local _Cu_clean_="" # untracked files state when clean +# local _Cu_dirty_="%{$fg_bold[red]%}" # untracked files state when dirty +# local _Cp_="%{${fg[cyan]}%}" # upstream info +# local _Cs_="" # stash state +# # 'R'eset formating +# local R="%{$terminfo[sgr0]%}" +# fi # # # This function creates the format and content -# # of the git prompt info. It shows some of the -# # ways you can set up your prompt with this -# # plugin. +# # of the git prompt info and puts the result +# # in $__GIT_PROMPT_INFO. Which you can use in +# # your $PROMPT (see above). This is an +# # example of some of the ways you can set up +# # your prompt with this plugin. # # -# # This function must set a global variable (with -# # the your git prompt format) that you include in -# # your PROMPT string. -# # NOTE: it cannot echo this info as in: +# # NOTE: This function must set a global variable +# # (with the your git prompt format) that you +# # include in your PROMPT string. +# # It cannot echo this info as in: # # PROMPT="$(update__GIT_PROMPT_INFO)" # # or the short-circuit logic will not work. # # @@ -69,6 +72,7 @@ # update__GIT_PROMPT_INFO () # { # local g="$(_git_promt__git_dir)" +# # short circuit if we're not in a git repo: # if [ -z "$g" ]; then # __GIT_PROMPT_INFO='' # return @@ -154,7 +158,8 @@ # # _git_promt__git_dir accepts 0 or 1 arguments (i.e., location) -# echos location of .git repo +# echos the location of .git repo. +# Useful for quickly figuring out if cwd is under a git repo. _git_promt__git_dir () { if [ -z "${1-}" ]; then diff --git a/themes/ashleydev.zsh-theme b/themes/ashleydev.zsh-theme index 992940b43..68fa48d14 100644 --- a/themes/ashleydev.zsh-theme +++ b/themes/ashleydev.zsh-theme @@ -1,52 +1,48 @@ -# NOTE: make sure to add 'git-prompt' to your list of oh-my-zsh plugins (in your +# NOTE: make sure to add 'git' to your list of oh-my-zsh plugins (in your # ~/.zshrc), otherwise the git prompt info will not be shown. -# -#-------------------- PROMPT definition: ---------------------- -# Set the prompt. -# Reset formating -local R="%{$terminfo[sgr0]%}" +#-------------------- Colors ---------------------- +# Colors ('_C' for color): +if [[ "$DISABLE_COLOR" != "true" ]]; then + # git prompt info colors: + local _Cerror_="%{$fg[yellow]%}" # bad (empty) .git/ directory + local _Cb_new_repo_="%{$fg_bold[default]%}" # branch color of new repo + local _Cb_clean_="%{$fg_no_bold[green]%}" # branch color when clean + local _Cb_dirty_="%{$fg_no_bold[red]%}" # branch color when dirty + local _Cr_="%{$bold_color$fg[yellow]%}" # rebase info + local _Ci_="%{$bold_color$fg[red]%}" # index info + local _Cu_clean_="" # untracked files state when clean + local _Cu_dirty_="%{$fg_bold[red]%}" # untracked files state when dirty + local _Cp_="%{${fg[cyan]}%}" # upstream info + local _Cs_="" # stash state -# special colors for privileged users (root) -local user_="%(!.%{$fg_bold[yellow]$bg[red]%}.%{$fg_bold[cyan]%})%n$R" -local host_="%(!.%{$fg[red]%}.%{$fg_bold[blue]%})%m$R" -local path_="%(!.%{$fg_bold[white]%}.%{$fg_bold[white]%})%~$R" -local jobs_="%(1j.%{$fg[blue]%}%j$R.)" + # Reset formating: + local R="%{$terminfo[sgr0]%}" -PROMPT='$user_$host_$path_ $__GIT_PROMPT_INFO$jobs_# ' + # PROMPT colors: + local _Cuser_root_="%{$fg_bold[yellow]$bg[red]%}" + local _Chost_root_="%{$fg[red]%}" + local _Cpath_root_="%{$fg_bold[white]%}" + local _Cuser_="%{$fg_bold[cyan]%}" + local _Chost_="%{$fg_bold[blue]%}" + local _Cpath_="%{$fg_bold[white]%}" + local _Cjobs_="%{$fg[blue]%}" -local date_format_="%D{%a %b %d}, %*" -local date_="%{$fg[green]%}[$date_format_]" -local return_code_="%(?..%{$fg[red]%}%? ↵ )" + # RPROMPT colors: + local _Cdate_="%{$fg[green]%}" + local _Creturn_code_="%{$fg[red]%}" + local _Cvi_mode_="%{$fg_bold[cyan]%}" +fi -RPROMPT='$return_code_$R$date_$R' - -# use the vi-mode oh-my-zsh plugin to get this: -MODE_INDICATOR="%{$fg_bold[cyan]%}-- CMD MODE -- $R" - -# #----------------------------------------------------- # git prompt info: -# The git-prompt plugin will cause $GIT_PROMPT_INFO_FUNC to be called -# when the git prompt info needs to be updated. +# The git prompt plugin will cause $GIT_PROMPT_INFO_FUNC to be called +# when $__GIT_PROMPT_INFO needs to be updated. GIT_PROMPT_INFO_FUNC="update__GIT_PROMPT_INFO" - GIT_PROMPT_SHOWUPSTREAM="verbose" GIT_PROMPT_SHORTCIRCUIT='on' -# git_prompt_info colors ('_C' for color): -local _Cerror_="%{$fg[yellow]%}" # bad (empty) .git/ directory -local _Cb_new_repo_="%{$fg_bold[default]%}" # branch color of new repo -local _Cb_clean_="%{$fg_no_bold[green]%}" # branch color when clean -local _Cb_dirty_="%{$fg_no_bold[red]%}" # branch color when dirty -local _Cr_="%{$bold_color$fg[yellow]%}" # rebase info -local _Ci_="%{$bold_color$fg[red]%}" # index info -local _Cu_clean_="" # untracked files state when clean -local _Cu_dirty_="%{$fg_bold[red]%}" # untracked files state when dirty -local _Cp_="%{${fg[cyan]}%}" # upstream info -local _Cs_="" # stash state - local __GIT_PROMPT_INFO='' # will set __GIT_PROMPT_INFO update__GIT_PROMPT_INFO () @@ -126,3 +122,23 @@ update__GIT_PROMPT_INFO () __GIT_PROMPT_INFO="$R$_prompt$R" } + + +#-------------------- PROMPT definition: ---------------------- +# +local user_="%(!.$_Cuser_root_.$_Cuser_)%n$R" +local host_="%(!.$_Chost_root_.$_Chost_)%m$R" +local path_="%(!.$_Cpath_root_.$_Cpath_)%~$R" +local jobs_="%(1j.$_Cjobs_%j$R.)" + +PROMPT='$user_$host_$path_ $__GIT_PROMPT_INFO$jobs_# ' + +local date_format_='%D{%a %b %d}, %*' +local date_="${_Cdate_}[$date_format_]$R" +local return_code_="%(?..$_Creturn_code_%? ↵ )$R" + +RPROMPT='$return_code_$date_' + +# use the vi-mode oh-my-zsh plugin to get this: +MODE_INDICATOR="${_Cvi_mode_}-- CMD MODE -- $R" +