From c24936ece51940536f3e62fc9e458b74c2affe68 Mon Sep 17 00:00:00 2001 From: steeef Date: Thu, 30 Sep 2010 19:56:56 -0700 Subject: [PATCH 01/64] added steeef theme --- themes/steeef.zsh-theme | 68 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 themes/steeef.zsh-theme diff --git a/themes/steeef.zsh-theme b/themes/steeef.zsh-theme new file mode 100644 index 000000000..a54cdce14 --- /dev/null +++ b/themes/steeef.zsh-theme @@ -0,0 +1,68 @@ +# prompt style and colors based on Steve Losh's Prose theme: +# http://github.com/sjl/oh-my-zsh/blob/master/themes/prose.zsh-theme +# +# vcs_info modifications from Bart Trojanowski's zsh prompt: +# http://www.jukie.net/bart/blog/pimping-out-zsh-prompt + +function virtualenv_info { + [ $VIRTUAL_ENV ] && echo '('`basename $VIRTUAL_ENV`') ' +} +PR_GIT_UPDATE=1 + +setopt prompt_subst +autoload colors +colors + +autoload -U add-zsh-hook +autoload -Uz vcs_info + + +# check-for-changes can be really slow. +# you should disable it, if you work with large repositories +zstyle ':vcs_info:*:prompt:*' check-for-changes true + +# set formats +# %b - branchname +# %u - unstagedstr (see below) +# %c - stagedstr (see below) +# %a - action (e.g. rebase-i) +# %R - repository path +# %S - path in the repository +PR_RST="%{${reset_color}%}" +FMT_BRANCH="(%{$fg[magenta]%}%b%u%c${PR_RST})" +FMT_ACTION="(%{$fg[green]%}%a${PR_RST})" +FMT_UNSTAGED="%{$fg[yellow]%}!" +FMT_STAGED="%{$fg[yellow]%}?" + +zstyle ':vcs_info:*:prompt:*' unstagedstr "${FMT_UNSTAGED}" +zstyle ':vcs_info:*:prompt:*' stagedstr "${FMT_STAGED}" +zstyle ':vcs_info:*:prompt:*' actionformats "${FMT_BRANCH}${FMT_ACTION}" +zstyle ':vcs_info:*:prompt:*' formats "${FMT_BRANCH}" +zstyle ':vcs_info:*:prompt:*' nvcsformats "" + + +function steeef_preexec { + case "$(history $HISTCMD)" in + *git*) + PR_GIT_UPDATE=1 + ;; + esac +} +add-zsh-hook preexec steeef_preexec + +function steeef_chpwd { + PR_GIT_UPDATE=1 +} +add-zsh-hook chpwd steeef_chpwd + +function steeef_precmd { + if [[ -n "$PR_GIT_UPDATE" ]] ; then + vcs_info 'prompt' + PR_GIT_UPDATE= + fi +} +add-zsh-hook precmd steeef_precmd + +PROMPT=$' +%{$fg[magenta]%}%n%{$reset_color%} at %{$fg[yellow]%}%m%{$reset_color%} in %{$fg_bold[green]%}%~%{$reset_color%} $vcs_info_msg_0_ +$(virtualenv_info)$ ' From 7fb0b210e88bcbdb71d2cb0022c35b2cc3810327 Mon Sep 17 00:00:00 2001 From: steeef Date: Fri, 1 Oct 2010 14:11:53 -0700 Subject: [PATCH 02/64] merge steeef.zsh-theme from master --- themes/steeef.zsh-theme | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/themes/steeef.zsh-theme b/themes/steeef.zsh-theme index a54cdce14..abb8f2994 100644 --- a/themes/steeef.zsh-theme +++ b/themes/steeef.zsh-theme @@ -3,6 +3,9 @@ # # vcs_info modifications from Bart Trojanowski's zsh prompt: # http://www.jukie.net/bart/blog/pimping-out-zsh-prompt +# +# git untracked files modification from Brian Carper: +# http://briancarper.net/blog/570/git-info-in-your-zsh-prompt function virtualenv_info { [ $VIRTUAL_ENV ] && echo '('`basename $VIRTUAL_ENV`') ' @@ -17,6 +20,9 @@ autoload -U add-zsh-hook autoload -Uz vcs_info +# enable VCS systems you use +zstyle ':vcs_info:*' enable git svn + # check-for-changes can be really slow. # you should disable it, if you work with large repositories zstyle ':vcs_info:*:prompt:*' check-for-changes true @@ -31,8 +37,8 @@ zstyle ':vcs_info:*:prompt:*' check-for-changes true PR_RST="%{${reset_color}%}" FMT_BRANCH="(%{$fg[magenta]%}%b%u%c${PR_RST})" FMT_ACTION="(%{$fg[green]%}%a${PR_RST})" -FMT_UNSTAGED="%{$fg[yellow]%}!" -FMT_STAGED="%{$fg[yellow]%}?" +FMT_UNSTAGED="%{$fg[yellow]%}●" +FMT_STAGED="%{$fg[green]%}●" zstyle ':vcs_info:*:prompt:*' unstagedstr "${FMT_UNSTAGED}" zstyle ':vcs_info:*:prompt:*' stagedstr "${FMT_STAGED}" @@ -46,6 +52,9 @@ function steeef_preexec { *git*) PR_GIT_UPDATE=1 ;; + *svn*) + PR_GIT_UPDATE=1 + ;; esac } add-zsh-hook preexec steeef_preexec @@ -56,6 +65,15 @@ function steeef_chpwd { add-zsh-hook chpwd steeef_chpwd function steeef_precmd { + # check for untracked files or updated submodules, since vcs_info doesn't + if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) || -n $(git ls-files -m --exclude-standard 2> /dev/null) ]]; then + PR_GIT_UPDATE=1 + FMT_BRANCH="(%{$fg[magenta]%}%b%u%c%{$fg[red]%}●${PR_RST})" + else + FMT_BRANCH="(%{$fg[magenta]%}%b%u%c${PR_RST})" + fi + zstyle ':vcs_info:*:prompt:*' formats "${FMT_BRANCH}" + if [[ -n "$PR_GIT_UPDATE" ]] ; then vcs_info 'prompt' PR_GIT_UPDATE= From 6fcf9393c31a51cef688b591de73817c5988c405 Mon Sep 17 00:00:00 2001 From: steeef Date: Fri, 1 Oct 2010 14:17:13 -0700 Subject: [PATCH 03/64] merge steeef.zsh-theme from master (removed submodule check) --- themes/steeef.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/steeef.zsh-theme b/themes/steeef.zsh-theme index abb8f2994..a43192743 100644 --- a/themes/steeef.zsh-theme +++ b/themes/steeef.zsh-theme @@ -66,7 +66,7 @@ add-zsh-hook chpwd steeef_chpwd function steeef_precmd { # check for untracked files or updated submodules, since vcs_info doesn't - if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) || -n $(git ls-files -m --exclude-standard 2> /dev/null) ]]; then + if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then PR_GIT_UPDATE=1 FMT_BRANCH="(%{$fg[magenta]%}%b%u%c%{$fg[red]%}●${PR_RST})" else From 7405f5d9ff29f42e934fa5f3c87401437c16aedd Mon Sep 17 00:00:00 2001 From: steeef Date: Fri, 1 Oct 2010 14:40:06 -0700 Subject: [PATCH 04/64] fix untracked files checking --- themes/steeef.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/steeef.zsh-theme b/themes/steeef.zsh-theme index a43192743..8c4c80265 100644 --- a/themes/steeef.zsh-theme +++ b/themes/steeef.zsh-theme @@ -66,7 +66,7 @@ add-zsh-hook chpwd steeef_chpwd function steeef_precmd { # check for untracked files or updated submodules, since vcs_info doesn't - if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then + if [[ ! -z $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then PR_GIT_UPDATE=1 FMT_BRANCH="(%{$fg[magenta]%}%b%u%c%{$fg[red]%}●${PR_RST})" else From f2f49f9571cf56b2fa672f16260c000050f9349b Mon Sep 17 00:00:00 2001 From: atom smith Date: Sun, 3 Oct 2010 17:41:45 -0400 Subject: [PATCH 05/64] adding my zsh-theme --- themes/re5et.zsh-theme | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 themes/re5et.zsh-theme diff --git a/themes/re5et.zsh-theme b/themes/re5et.zsh-theme new file mode 100644 index 000000000..fadb1fef8 --- /dev/null +++ b/themes/re5et.zsh-theme @@ -0,0 +1,15 @@ +if [ "$(whoami)" = "root" ]; then CARETCOLOR="red"; else CARETCOLOR="magenta"; fi + +local return_code="%(?..%{$fg_bold[red]%}:( %?%{$reset_color%})" + +PROMPT=' +%{$fg_bold[cyan]%}%n%{$reset_color%}%{$fg[yellow]%}@%{$reset_color%}%{$fg_bold[blue]%}%m%{$reset_color%}:%{${fg_bold[green]}%}%~%{$reset_color%}$(git_prompt_info) +%{${fg[$CARETCOLOR]}%}%# %{${reset_color}%}' + +RPS1='${return_code} %D - %*' + +ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[magenta]%}^%{$reset_color%}%{$fg_bold[yellow]%}" +ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg_bold[red]%} ±" +ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%} ?" +ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[red]%} ♥" \ No newline at end of file From ba9ae6a1e5fe1b45a58e655ab3413bb95a82573e Mon Sep 17 00:00:00 2001 From: atom smith Date: Sun, 3 Oct 2010 17:42:57 -0400 Subject: [PATCH 06/64] should have newline at end of file. --- themes/re5et.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/re5et.zsh-theme b/themes/re5et.zsh-theme index fadb1fef8..5bded76a3 100644 --- a/themes/re5et.zsh-theme +++ b/themes/re5et.zsh-theme @@ -12,4 +12,4 @@ ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[magenta]%}^%{$reset_color%}%{$fg_bold[ye ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg_bold[red]%} ±" ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%} ?" -ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[red]%} ♥" \ No newline at end of file +ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[red]%} ♥" From 6d5e4eaebcde1c48413f89b4554983f489e4b017 Mon Sep 17 00:00:00 2001 From: steeef Date: Mon, 4 Oct 2010 18:05:01 -0700 Subject: [PATCH 07/64] use 256 colors, if available --- themes/steeef.zsh-theme | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/themes/steeef.zsh-theme b/themes/steeef.zsh-theme index 8c4c80265..d8f9306cd 100644 --- a/themes/steeef.zsh-theme +++ b/themes/steeef.zsh-theme @@ -19,6 +19,20 @@ colors autoload -U add-zsh-hook autoload -Uz vcs_info +#use extended color pallete if available +if [ $TERM = "xterm-256color" ]; then + turquoise="%F{81}" + orange="%F{166}" + purple="%F{135}" + hotpink="%F{161}" + limegreen="%F{118}" +else + turquoise="$fg[cyan]" + orange="$fg[yellow]" + purple="$fg[magenta]" + hotpink="$fg[red]" + limegreen="$fg[green]" +fi # enable VCS systems you use zstyle ':vcs_info:*' enable git svn @@ -35,10 +49,10 @@ zstyle ':vcs_info:*:prompt:*' check-for-changes true # %R - repository path # %S - path in the repository PR_RST="%{${reset_color}%}" -FMT_BRANCH="(%{$fg[magenta]%}%b%u%c${PR_RST})" -FMT_ACTION="(%{$fg[green]%}%a${PR_RST})" -FMT_UNSTAGED="%{$fg[yellow]%}●" -FMT_STAGED="%{$fg[green]%}●" +FMT_BRANCH="(%{$turquoise%}%b%u%c${PR_RST})" +FMT_ACTION="(%{$limegreen%}%a${PR_RST})" +FMT_UNSTAGED="%{$orange%}●" +FMT_STAGED="%{$limegreen%}●" zstyle ':vcs_info:*:prompt:*' unstagedstr "${FMT_UNSTAGED}" zstyle ':vcs_info:*:prompt:*' stagedstr "${FMT_STAGED}" @@ -68,9 +82,9 @@ function steeef_precmd { # check for untracked files or updated submodules, since vcs_info doesn't if [[ ! -z $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then PR_GIT_UPDATE=1 - FMT_BRANCH="(%{$fg[magenta]%}%b%u%c%{$fg[red]%}●${PR_RST})" + FMT_BRANCH="(%{$turquoise%}%b%u%c%{$hotpink%}●${PR_RST})" else - FMT_BRANCH="(%{$fg[magenta]%}%b%u%c${PR_RST})" + FMT_BRANCH="(%{$turquoise%}%b%u%c${PR_RST})" fi zstyle ':vcs_info:*:prompt:*' formats "${FMT_BRANCH}" @@ -82,5 +96,5 @@ function steeef_precmd { add-zsh-hook precmd steeef_precmd PROMPT=$' -%{$fg[magenta]%}%n%{$reset_color%} at %{$fg[yellow]%}%m%{$reset_color%} in %{$fg_bold[green]%}%~%{$reset_color%} $vcs_info_msg_0_ +%{$purple%}%n%{$reset_color%} at %{$orange%}%m%{$reset_color%} in %{$limegreen%}%~%{$reset_color%} $vcs_info_msg_0_ $(virtualenv_info)$ ' From c6b339f532b05e907b0c554000643db5e896a75f Mon Sep 17 00:00:00 2001 From: steeef Date: Mon, 4 Oct 2010 22:08:38 -0700 Subject: [PATCH 08/64] merge master --- themes/steeef.zsh-theme | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/themes/steeef.zsh-theme b/themes/steeef.zsh-theme index d8f9306cd..a5cf0f9a1 100644 --- a/themes/steeef.zsh-theme +++ b/themes/steeef.zsh-theme @@ -79,16 +79,16 @@ function steeef_chpwd { add-zsh-hook chpwd steeef_chpwd function steeef_precmd { - # check for untracked files or updated submodules, since vcs_info doesn't - if [[ ! -z $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then - PR_GIT_UPDATE=1 - FMT_BRANCH="(%{$turquoise%}%b%u%c%{$hotpink%}●${PR_RST})" - else - FMT_BRANCH="(%{$turquoise%}%b%u%c${PR_RST})" - fi - zstyle ':vcs_info:*:prompt:*' formats "${FMT_BRANCH}" - if [[ -n "$PR_GIT_UPDATE" ]] ; then + # check for untracked files or updated submodules, since vcs_info doesn't + if [[ ! -z $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then + PR_GIT_UPDATE=1 + FMT_BRANCH="(%{$turquoise%}%b%u%c%{$hotpink%}●${PR_RST})" + else + FMT_BRANCH="(%{$turquoise%}%b%u%c${PR_RST})" + fi + zstyle ':vcs_info:*:prompt:*' formats "${FMT_BRANCH}" + vcs_info 'prompt' PR_GIT_UPDATE= fi From 4e433eb6bb578c864116cbcf0aa201227f80e4aa Mon Sep 17 00:00:00 2001 From: Florian Walch Date: Fri, 15 Oct 2010 11:05:47 +0200 Subject: [PATCH 09/64] Added own theme (based on robbyrussell) --- themes/fwalch.zsh-theme | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 themes/fwalch.zsh-theme diff --git a/themes/fwalch.zsh-theme b/themes/fwalch.zsh-theme new file mode 100644 index 000000000..24edf55c0 --- /dev/null +++ b/themes/fwalch.zsh-theme @@ -0,0 +1,6 @@ +PROMPT='%{$fg_bold[green]%}%p %{$fg[cyan]%}%c%{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}' + +ZSH_THEME_GIT_PROMPT_PREFIX=" (%{$fg[red]%}" +ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})" From 60b560fc9ace116cde7e56954f386b1098751648 Mon Sep 17 00:00:00 2001 From: Florian Walch Date: Fri, 15 Oct 2010 16:50:39 +0200 Subject: [PATCH 10/64] Added gpg-agent plugin Based on ssh-agent plugin. --- plugins/gpg-agent/gpg-agent.plugin.zsh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 plugins/gpg-agent/gpg-agent.plugin.zsh diff --git a/plugins/gpg-agent/gpg-agent.plugin.zsh b/plugins/gpg-agent/gpg-agent.plugin.zsh new file mode 100644 index 000000000..8cc71fd57 --- /dev/null +++ b/plugins/gpg-agent/gpg-agent.plugin.zsh @@ -0,0 +1,26 @@ +# Based on ssh-agent code + +local GPG_ENV=$HOME/.gnupg/gpg-agent.env + +function start_agent { + /usr/bin/env gpg-agent --daemon --enable-ssh-support --write-env-file ${GPG_ENV} > /dev/null + chmod 600 ${GPG_ENV} + . ${GPG_ENV} > /dev/null +} + +# Source GPG agent settings, if applicable +if [ -f "${GPG_ENV}" ]; then + . ${GPG_ENV} > /dev/null + ps -ef | grep ${SSH_AGENT_PID} | grep gpg-agent > /dev/null || { + start_agent; + } +else + start_agent; +fi + +export GPG_AGENT_INFO +export SSH_AUTH_SOCK +export SSH_AGENT_PID + +GPG_TTY=$(tty) +export GPG_TTY From 9b6dd1cd48a549d2868cfe16073bbd04357e27e5 Mon Sep 17 00:00:00 2001 From: steeef Date: Fri, 22 Oct 2010 10:39:33 -0700 Subject: [PATCH 11/64] merge with master --- themes/steeef.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/steeef.zsh-theme b/themes/steeef.zsh-theme index a5cf0f9a1..07c1d3def 100644 --- a/themes/steeef.zsh-theme +++ b/themes/steeef.zsh-theme @@ -20,7 +20,7 @@ autoload -U add-zsh-hook autoload -Uz vcs_info #use extended color pallete if available -if [ $TERM = "xterm-256color" ]; then +if [ $TERM = "xterm-256color" || $TERM = "linux" || $TERM = "rxvt-256color" || $TERM = "rxvt-unicode-256color" ]; then turquoise="%F{81}" orange="%F{166}" purple="%F{135}" From 810b8f5ce8a58b03afba4e6ec5937e2cd0bcab5c Mon Sep 17 00:00:00 2001 From: steeef Date: Fri, 22 Oct 2010 10:42:49 -0700 Subject: [PATCH 12/64] merge with master --- themes/steeef.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/steeef.zsh-theme b/themes/steeef.zsh-theme index 07c1d3def..6bca57eec 100644 --- a/themes/steeef.zsh-theme +++ b/themes/steeef.zsh-theme @@ -20,7 +20,7 @@ autoload -U add-zsh-hook autoload -Uz vcs_info #use extended color pallete if available -if [ $TERM = "xterm-256color" || $TERM = "linux" || $TERM = "rxvt-256color" || $TERM = "rxvt-unicode-256color" ]; then +if [ [ $TERM = "xterm-256color" ] || [ $TERM = "linux"] || [ $TERM = "rxvt-256color" ] || [ $TERM = "rxvt-unicode-256color" ] ]; then turquoise="%F{81}" orange="%F{166}" purple="%F{135}" From d2bfdc2d89cb08a870169af4f394f27d2b9c0aed Mon Sep 17 00:00:00 2001 From: steeef Date: Fri, 22 Oct 2010 10:51:58 -0700 Subject: [PATCH 13/64] merge theme fixes from master --- themes/steeef.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/steeef.zsh-theme b/themes/steeef.zsh-theme index 6bca57eec..f81300242 100644 --- a/themes/steeef.zsh-theme +++ b/themes/steeef.zsh-theme @@ -20,7 +20,7 @@ autoload -U add-zsh-hook autoload -Uz vcs_info #use extended color pallete if available -if [ [ $TERM = "xterm-256color" ] || [ $TERM = "linux"] || [ $TERM = "rxvt-256color" ] || [ $TERM = "rxvt-unicode-256color" ] ]; then +if [[ $TERM = *256color* || $TERM = "linux" ]]; then turquoise="%F{81}" orange="%F{166}" purple="%F{135}" From 4ff0136079b8ffe29e0990d0a0ce8876554aa0d5 Mon Sep 17 00:00:00 2001 From: steeef Date: Fri, 22 Oct 2010 11:34:52 -0700 Subject: [PATCH 14/64] merge from master --- themes/steeef.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/steeef.zsh-theme b/themes/steeef.zsh-theme index f81300242..a2583b028 100644 --- a/themes/steeef.zsh-theme +++ b/themes/steeef.zsh-theme @@ -20,7 +20,7 @@ autoload -U add-zsh-hook autoload -Uz vcs_info #use extended color pallete if available -if [[ $TERM = *256color* || $TERM = "linux" ]]; then +if [[ $TERM = *256color* || $TERM = *rxvt* ]]; then turquoise="%F{81}" orange="%F{166}" purple="%F{135}" From bdaf872ce6e411f881e5e6138fc61a9c1645e67a Mon Sep 17 00:00:00 2001 From: Claus Witt Date: Wed, 17 Nov 2010 11:17:03 +0100 Subject: [PATCH 15/64] Removed the echo statement - no need for that. --- plugins/phing/phing.plugin.zsh | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/phing/phing.plugin.zsh b/plugins/phing/phing.plugin.zsh index 80e334629..8f4adca08 100644 --- a/plugins/phing/phing.plugin.zsh +++ b/plugins/phing/phing.plugin.zsh @@ -10,7 +10,6 @@ _phing_does_target_list_need_generating () { _phing () { if [ -f build.xml ]; then if _phing_does_target_list_need_generating; then - echo "\nGenerating .phing_targets..." > /dev/stderr phing -l |grep -v ":" |grep -v "^$"|grep -v "\-" > .phing_targets fi compadd `cat .phing_targets` From fa7036b4eef177f25478091e660fca52b9ac725d Mon Sep 17 00:00:00 2001 From: Claus Witt Date: Thu, 25 Nov 2010 21:48:07 +0100 Subject: [PATCH 16/64] Added ant plugin --- plugins/ant/ant.plugin.zsh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 plugins/ant/ant.plugin.zsh diff --git a/plugins/ant/ant.plugin.zsh b/plugins/ant/ant.plugin.zsh new file mode 100644 index 000000000..0544ac92c --- /dev/null +++ b/plugins/ant/ant.plugin.zsh @@ -0,0 +1,19 @@ +_ant_does_target_list_need_generating () { + if [ ! -f .ant_targets ]; then return 0; + else + accurate=$(stat -f%m .ant_targets) + changed=$(stat -f%m build.xml) + return $(expr $accurate '>=' $changed) + fi +} + +_ant () { + if [ -f build.xml ]; then + if _ant_does_target_list_need_generating; then + sed -n '/ .ant_targets + fi + compadd `cat .ant_targets` + fi +} + +compdef _ant ant From fcc7801435fd2c5c6defcfbfc736e22341500a9d Mon Sep 17 00:00:00 2001 From: Lorenzo Manacorda Date: Mon, 24 Jan 2011 15:49:49 +0100 Subject: [PATCH 17/64] add missing unrar flag --- lib/functions.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/functions.zsh b/lib/functions.zsh index 914f2ef25..86545c7b6 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -52,7 +52,7 @@ function extract() { *.tar.xz) tar xvJf $1;; *.tar.lzma) tar --lzma -xvf $1;; *.bz2) bunzip $1;; - *.rar) unrar $1;; + *.rar) unrar x $1;; *.gz) gunzip $1;; *.tar) tar xvf $1;; *.tbz2) tar xvjf $1;; From 7f69551498a78a6b30d706c89808fcd2ba000045 Mon Sep 17 00:00:00 2001 From: Christopher Chow Date: Wed, 23 Feb 2011 02:56:25 +1100 Subject: [PATCH 18/64] Add tab completion for rvm. --- plugins/rvm/_rvm | 147 +++++++++++++++++++++++++++++++++++++ plugins/rvm/rvm.plugin.zsh | 3 + 2 files changed, 150 insertions(+) create mode 100644 plugins/rvm/_rvm create mode 100644 plugins/rvm/rvm.plugin.zsh diff --git a/plugins/rvm/_rvm b/plugins/rvm/_rvm new file mode 100644 index 000000000..bba5304a0 --- /dev/null +++ b/plugins/rvm/_rvm @@ -0,0 +1,147 @@ +#compdef rvm + +local curcontext="$curcontext" state line cmds ret=1 + +_arguments -C \ + '(- 1 *)'{-v,--version}'[display version information]' \ + '(-l|--level)'{-l,--level}'+[patch level to use with rvm use / install]:number' \ + '(--prefix)--prefix[path for all rvm files (~/.rvm/), with trailing slash!]:path:_files' \ + '(--bin)--bin[path for binaries to be placed (~/.rvm/bin/)]:path:_files' \ + '(--source)--source[src directory to use (~/.rvm/src/)]:path:_files' \ + '(--archives)--archives[directory for downladed files (~/.rvm/archives/)]:path:_files' \ + '-S[Specify a script file to attempt to load and run (rubydo)]:file:_files' \ + '-e[Execute code from the command line]:code' \ + '(-G)-G[root gem path to use]:path:_files' \ + '(--gems)--gems[Used to set the gems_flag, use with remove to remove gems]' \ + '(--archive)--archive[Used to set the archive_flag, use with remove to remove archive]' \ + '(--patch)--patch[With MRI Rubies you may specify one or more full paths to patches]' \ + '(-C|--configure)'{-C,--configure}'=[custom configure options]' \ + '(--nice)--nice[process niceness (for slow computers, default 0)]:number' \ + '(--ree)--ree-options[Options passed directly to ree ./installer on the command line]:options' \ + '(--head)--head[with update, updates rvm to git head version]' \ + '(--rubygems)--rubygems[with update, updates rubygems for selected ruby]' \ + '(--default)--default[with ruby select, sets a default ruby for new shells]' \ + '(--debug)--debug[Toggle debug mode on for very verbose output]' \ + '(--trace)--trace[Toggle trace mode on to see EVERYTHING rvm is doing]' \ + '(--force)--force[Force install, removes old install & source before install]' \ + '(--summary)--summary[Used with rubydo to print out a summary of the commands run]' \ + '(--latest)--latest[with gemset --dump skips version strings for latest gem]' \ + '(--gems)--gems[with uninstall/remove removes gems with the interpreter]' \ + '(--docs)--docs[with install, attempt to generate ri after installation]' \ + '(--reconfigure)--reconfigure[Force ./configure on install even if Makefile already exists]' \ + '1: :->cmds' \ + '*: :->args' && ret=0 + +case $state in + cmds) + cmds=( + "version:show the rvm version installed in rvm_path" + "use:setup current shell to use a specific ruby version" + "reload:reload rvm source itself (useful after changing rvm source)" + "implode:(seppuku) removes the rvm installation completely. This means everything in $rvm_path (~/.rvm)." + "update:upgrades rvm to the latest version." + "reset:remove current and stored default & system settings." + "info :show the *current* environment information for current ruby" + "current:print the *current* ruby version and the name of any gemset being used." + "debug:show info plus additional information for common issues" + "install:install one or many ruby versions" + "uninstall:uninstall one or many ruby versions, leaves their sources" + "remove:uninstall one or many ruby versions and remove their sources" + "migrate:Lets you migrate all gemsets from one ruby to another." + "upgrade:Lets you upgrade from one version of a ruby to another, including migrating your gemsets semi-automatically." + "wrapper:generates a set of wrapper executables for a given ruby with the specified ruby and gemset combination. Used under the hood for passenger support and the like." + "cleanup:Lets you remove stale source folders / archives and other miscellaneous data associated with rvm." + "repair:Lets you repair parts of your environment e.g. wrappers, env files and and similar files (e.g. general maintenance)." + "snapshot:Lets your backup / restore an rvm installation in a lightweight manner." + "disk-usage:Tells you how much disk space rvm install is using." + "tools:Provides general information about the ruby environment, primarily useful when scripting rvm." + "docs:Tools to make installing ri and rdoc documentation easier." + "rvmrc:Tools related to managing rvmrc trust and loading." + "exec:runs an arbitrary command as a set operation." + "ruby:runs a named ruby file against specified and/or all rubies" + "gem:runs a gem command using selected ruby's 'gem'" + "rake:runs a rake task against specified and/or all rubies" + "tests:runs 'rake test' across selected ruby versions" + "specs:runs 'rake spec' across selected ruby versions" + "monitor:Monitor cwd for testing, run rake {spec,test} on changes." + "gemset:gemsets: http://rvm.beginrescueend.com/gemsets/" + "rubygems:Switches the installed version of rubygems for the current ruby." + "gemdir:display the path to the current gem directory (GEM_HOME)." + "srcdir:display the path to rvm source directory (may be yanked)" + "fetch:Performs an archive / src fetch only of the selected ruby." + "list:show currently installed rubies, interactive output." + "package:Install a dependency package {readline,iconv,zlib,openssl}" + "notes:Display notes, with operating system specifics." + "export:Temporarily set an environment variable in the current shell." + "unexport:Undo changes made to the environment by 'rvm export'." + ) + _describe -t commands 'rvm command' cmds && ret=0 + ;; + args) + case $line[1] in + (use|uninstall|remove|list) + _values -S , 'rubies' $(rvm list strings | sed -e 's/ruby-\([^) ]*\)-\([^) ]*\)/ruby-\1-\2 \1-\2 \1/g') default system && ret=0 + ;; + (install|fetch) + _values -S , 'rubies' $(rvm list known_strings) && ret=0 + ;; + gemset) + if (( CURRENT == 3 )); then + _values 'gemset_commands' \ + 'import' \ + 'export' \ + 'create' \ + 'copy' \ + 'rename' \ + 'empty' \ + 'delete' \ + 'name' \ + 'dir' \ + 'list' \ + 'list_all' \ + 'gemdir' \ + 'install' \ + 'pristine' \ + 'clear' \ + 'use' \ + 'update' \ + 'unpack' \ + 'globalcache' + else + _values -S , 'gemsets' $(rvm gemset list | grep -v gemset 2>/dev/null) + fi + ret=0 + ;; + package) + if (( CURRENT == 3 )); then + _values 'package_commands' \ + 'install' \ + 'uninstall' + else + _values 'packages' \ + 'readline' \ + 'iconv' \ + 'curl' \ + 'openssl' \ + 'zlib' \ + 'autoconf' \ + 'ncurses' \ + 'pkgconfig' \ + 'gettext' \ + 'glib' \ + 'mono' \ + 'llvm' \ + 'libxml2' \ + 'libxslt' \ + 'libyaml' + fi + ret=0 + ;; + *) + (( ret )) && _message 'no more arguments' + ;; + esac + ;; +esac + +return ret diff --git a/plugins/rvm/rvm.plugin.zsh b/plugins/rvm/rvm.plugin.zsh new file mode 100644 index 000000000..ef934d547 --- /dev/null +++ b/plugins/rvm/rvm.plugin.zsh @@ -0,0 +1,3 @@ +fpath=($ZSH/plugins/rvm $fpath) +autoload -U compinit +compinit -i From d13ca43d18313a64457bf9cf265b0d0e86e94141 Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Wed, 18 May 2011 16:26:10 -0400 Subject: [PATCH 19/64] Fixed missing slash in Git completion. --- plugins/git/_git | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/git/_git b/plugins/git/_git index ac9fd1c70..7c72c98f4 100644 --- a/plugins/git/_git +++ b/plugins/git/_git @@ -2941,7 +2941,7 @@ _git-rev-parse () { else # TODO: Parse option specification? _arguments -w -S -s \ - '(- *)'{-h,--help}'[display usage]' + '(- *)'{-h,--help}'[display usage]' \ '--keep-dashdash[do not skip first -- option]' \ '--stop-at-non-option[stop parsing options at first non-option argument]' \ '*:option specification' && ret=0 From 31ef6199675be846e473c20681da339b6ea864cd Mon Sep 17 00:00:00 2001 From: Jacob Atzen Date: Thu, 19 May 2011 16:20:30 +0200 Subject: [PATCH 20/64] Add autojump plugin --- plugins/autojump/autojump.plugin.zsh | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 plugins/autojump/autojump.plugin.zsh diff --git a/plugins/autojump/autojump.plugin.zsh b/plugins/autojump/autojump.plugin.zsh new file mode 100644 index 000000000..da0a12765 --- /dev/null +++ b/plugins/autojump/autojump.plugin.zsh @@ -0,0 +1,3 @@ +if [ -f `brew --prefix`/etc/autojump ]; then + . `brew --prefix`/etc/autojump +fi From bde77af40d28ed7a308a843d8bcad556d8115f84 Mon Sep 17 00:00:00 2001 From: Jacob Atzen Date: Thu, 19 May 2011 16:33:29 +0200 Subject: [PATCH 21/64] TextMate automatically forks into the background --- plugins/textmate/textmate.plugin.zsh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/textmate/textmate.plugin.zsh b/plugins/textmate/textmate.plugin.zsh index 7b73e2751..7c4c14a5f 100644 --- a/plugins/textmate/textmate.plugin.zsh +++ b/plugins/textmate/textmate.plugin.zsh @@ -1,9 +1,9 @@ # TextMate -alias et='mate . &' -alias ett='mate app config lib db public spec test Rakefile Capfile Todo &' -alias etp='mate app config lib db public spec test vendor/plugins vendor/gems Rakefile Capfile Todo &' -alias etts='mate app config lib db public script spec test vendor/plugins vendor/gems Rakefile Capfile Todo &' +alias et='mate .' +alias ett='mate app config lib db public spec test Rakefile Capfile Todo' +alias etp='mate app config lib db public spec test vendor/plugins vendor/gems Rakefile Capfile Todo' +alias etts='mate app config lib db public script spec test vendor/plugins vendor/gems Rakefile Capfile Todo' # Editor Ruby file in TextMate alias mr='mate CHANGELOG app config db lib public script spec test' From e90118978e6fa03f388c94de91855ef4c409e961 Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Thu, 19 May 2011 15:33:10 -0400 Subject: [PATCH 22/64] Fixed additional missing slash in Git completion. --- plugins/git/_git | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/git/_git b/plugins/git/_git index 7c72c98f4..8f269e83b 100644 --- a/plugins/git/_git +++ b/plugins/git/_git @@ -3958,7 +3958,7 @@ _git-name-rev () { '--refs=[only use refs matching given pattern]: :_guard "?#" "shell pattern"' \ '(--stdin :)--all[list all commits reachable from all refs]' \ '(--all :)--stdin[read from stdin and append revision-name]' \ - '--name-only[display only name of commits]' + '--name-only[display only name of commits]' \ '--no-undefined[die with non-zero return when a reference is undefined]' \ '--always[show uniquely abbreviated commit object as fallback]' \ '(--stdin --all)*: :__git_commits' && ret=0 From 210c1ef86deed805b3c5b25833d4b128f758b610 Mon Sep 17 00:00:00 2001 From: Jan-Oliver Jahner Date: Fri, 20 May 2011 15:14:10 +0200 Subject: [PATCH 23/64] Added 'simple' theme. --- themes/simple.zsh-theme | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 themes/simple.zsh-theme diff --git a/themes/simple.zsh-theme b/themes/simple.zsh-theme new file mode 100644 index 000000000..a88d9d72a --- /dev/null +++ b/themes/simple.zsh-theme @@ -0,0 +1,6 @@ +PROMPT='%{$fg[green]%}%~%{$fg_bold[blue]%}$(git_prompt_info)%{$reset_color%} ' + +ZSH_THEME_GIT_PROMPT_PREFIX="(" +ZSH_THEME_GIT_PROMPT_SUFFIX=")" +ZSH_THEME_GIT_PROMPT_DIRTY=" ✗" +ZSH_THEME_GIT_PROMPT_CLEAN=" ✔" From 093f9077f5b358803a810d65fb0d4729477905cf Mon Sep 17 00:00:00 2001 From: Oliver Braun Date: Fri, 20 May 2011 22:26:45 +0200 Subject: [PATCH 24/64] Added obraun theme which is a slightly modified version of an already existing theme. --- themes/obraun.zsh-theme | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 themes/obraun.zsh-theme diff --git a/themes/obraun.zsh-theme b/themes/obraun.zsh-theme new file mode 100644 index 000000000..08d137665 --- /dev/null +++ b/themes/obraun.zsh-theme @@ -0,0 +1,11 @@ +if [ "$(whoami)" = "root" ]; then CARETCOLOR="red"; else CARETCOLOR="blue"; fi + +local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" + +PROMPT='%{$fg[green]%}[%*]%{$reset_color%} %{$fg_no_bold[cyan]%}%n %{${fg_bold[blue]}%}::%{$reset_color%} %{$fg[yellow]%}%m%{$reset_color%} %{$fg_no_bold[magenta]%} ➜ %{$reset_color%} %{${fg[green]}%}%3~ $(git_prompt_info)%{${fg_bold[$CARETCOLOR]}%}»%{${reset_color}%} ' + +RPS1="${return_code}" + +ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[red]%}‹" +ZSH_THEME_GIT_PROMPT_SUFFIX="› %{$reset_color%}" + From 1aacb74caf6800fe895ab3a40584c08bfded451e Mon Sep 17 00:00:00 2001 From: Guten Date: Sun, 22 May 2011 21:27:30 +0800 Subject: [PATCH 25/64] add custom completion support --- oh-my-zsh.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 3ea88e924..a3d276df5 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -1,7 +1,7 @@ # Initializes Oh My Zsh # add a function path -fpath=($ZSH/functions $fpath) +fpath=($ZSH/functions $ZSH/completions $fpath) # Load all of the config files in ~/oh-my-zsh that end in .zsh # TIP: Add files you don't want in git to .gitignore From 5c1b341132119f08047a506e2c2b06fa0c0db52e Mon Sep 17 00:00:00 2001 From: Casey Watson Date: Tue, 24 May 2011 12:15:58 -0600 Subject: [PATCH 26/64] Fix to random theme selection - themes array is 1-based - theme files names are located in indicies 1 through N inclusive - this resolves an issue where you would occasionally see: "no such file or directory. Random theme '' loaded..." --- oh-my-zsh.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 3ea88e924..2a206798d 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -31,7 +31,7 @@ if [ "$ZSH_THEME" = "random" ] then themes=($ZSH/themes/*zsh-theme) N=${#themes[@]} - ((N=RANDOM%N)) + ((N=(RANDOM%N)+1)) RANDOM_THEME=${themes[$N]} source "$RANDOM_THEME" echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..." From 21276546e9614576ce6e1a6be1393abce393d04f Mon Sep 17 00:00:00 2001 From: "Suraj N. Kurapati" Date: Wed, 23 Feb 2011 00:38:15 -0800 Subject: [PATCH 27/64] fishy theme: text indicators for $? and git status The git status indicators were taken from sorin.zsh-theme and changed to use ASCII symbols instead of Unicode ones because my preferred terminal font, DejaVu Sans Mono, renders Unicode symbols poorly and also because Unicode rendering is not available in standard Linux virtual terminals. --- themes/fishy.zsh-theme | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/themes/fishy.zsh-theme b/themes/fishy.zsh-theme index f22eda868..f9e506cae 100644 --- a/themes/fishy.zsh-theme +++ b/themes/fishy.zsh-theme @@ -3,7 +3,18 @@ local user_color='green'; [ $UID -eq 0 ] && user_color='red' PROMPT='%n@%m %{$fg[$user_color]%}%~%{$reset_color%}%(!.#.>) ' PROMPT2='%{$fg[red]%}\ %{$reset_color%}' -RPS1='%(?..%{$fg[red]%}%? ↵%{$reset_color%})$(git_prompt_info)' -ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[cyan]%}" -ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" +local return_status="%{$fg_bold[red]%}%(?..%?)%{$reset_color%}" +RPROMPT='${return_status}$(git_prompt_info)$(git_prompt_status)%{$reset_color%}' + +ZSH_THEME_GIT_PROMPT_PREFIX=" " +ZSH_THEME_GIT_PROMPT_SUFFIX="" +ZSH_THEME_GIT_PROMPT_DIRTY="" +ZSH_THEME_GIT_PROMPT_CLEAN="" + +ZSH_THEME_GIT_PROMPT_ADDED="%{$fg_bold[green]%}+" +ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg_bold[blue]%}!" +ZSH_THEME_GIT_PROMPT_DELETED="%{$fg_bold[red]%}-" +ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg_bold[magenta]%}>" +ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg_bold[yellow]%}#" +ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[cyan]%}?" From f8aae64e478066be7d05f5eb6970c356cafcfd36 Mon Sep 17 00:00:00 2001 From: Jake Bell Date: Thu, 26 May 2011 12:34:37 -0500 Subject: [PATCH 28/64] Adding ability to override plugins from the custom directory. --- .gitignore | 1 + README.textile | 6 ++++-- custom/example/example.plugin.zsh | 2 ++ oh-my-zsh.sh | 4 +++- 4 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 custom/example/example.plugin.zsh diff --git a/.gitignore b/.gitignore index 4b555067e..8fdfae286 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ locals.zsh log/.zsh_history projects.zsh custom/* +!custom/example !custom/example.zsh cache diff --git a/README.textile b/README.textile index d01c3310a..2dbfbe5a6 100644 --- a/README.textile +++ b/README.textile @@ -48,7 +48,9 @@ the "refcard":http://www.bash2zsh.com/zsh_refcard/refcard.pdf is pretty tasty fo h3. Customization If you want to override any of the default behavior, just add a new file (ending in @.zsh@) into the @custom/@ directory. -If you have many functions which go good together you can put them as a *.plugin.zsh file in the @plugin/@ directory and then enable this plugin. +If you have many functions which go good together you can put them as a *.plugin.zsh file in the @custom/plugins/@ directory and then enable this plugin. +If you would like to override the functionality of a plugin distributed with oh-my-zsh, create a plugin of the same name in the @custom/plugins/@ directory and it will be loaded instead of the one in @plugins/@. + h3. Uninstalling @@ -68,4 +70,4 @@ This project wouldn't exist without all of our awesome users and contributors. * "View our growing list of contributors":https://github.com/robbyrussell/oh-my-zsh/contributors -Thank you so much! \ No newline at end of file +Thank you so much! diff --git a/custom/example/example.plugin.zsh b/custom/example/example.plugin.zsh new file mode 100644 index 000000000..406f27445 --- /dev/null +++ b/custom/example/example.plugin.zsh @@ -0,0 +1,2 @@ +# Add your own custom plugins in the custom/plugins directory. Plugins placed +# here will override ones with the same name in the main plugins directory. diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index c8f1a33b8..dbff1ced9 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -17,7 +17,9 @@ compinit -i # Load all of the plugins that were defined in ~/.zshrc for plugin ($plugins); do - if [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then + if [ -f $ZSH/custom/plugins/$plugin/$plugin.plugin.zsh ]; then + source $ZSH/custom/plugins/$plugin/$plugin.plugin.zsh + elif [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then source $ZSH/plugins/$plugin/$plugin.plugin.zsh fi done From 04573324d52aaadf947f3a80190e4f54d8580932 Mon Sep 17 00:00:00 2001 From: Martin Thurau Date: Fri, 27 May 2011 16:58:14 +0200 Subject: [PATCH 29/64] Added compatibility for the linux 'stat' command for the ant plugin --- plugins/ant/ant.plugin.zsh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/ant/ant.plugin.zsh b/plugins/ant/ant.plugin.zsh index 0544ac92c..23bc7756a 100644 --- a/plugins/ant/ant.plugin.zsh +++ b/plugins/ant/ant.plugin.zsh @@ -1,8 +1,15 @@ +stat -f%m . > /dev/null 2>&1 +if [ "$?" = 0 ]; then + stat_cmd=(stat -f%m) +else + stat_cmd=(stat -L --format=%y) +fi + _ant_does_target_list_need_generating () { if [ ! -f .ant_targets ]; then return 0; else - accurate=$(stat -f%m .ant_targets) - changed=$(stat -f%m build.xml) + accurate=$($stat_cmd -f%m .ant_targets) + changed=$($stat_cmd -f%m build.xml) return $(expr $accurate '>=' $changed) fi } From 3e433165502a01028fcd0368161a2193eaeb386c Mon Sep 17 00:00:00 2001 From: Andrew Hodges Date: Sat, 28 May 2011 10:16:06 -0400 Subject: [PATCH 30/64] Ruby Switching Helpers Add helper functions to switch gemsets on ruby-1.8.7-p334 and ruby-1.9.2-p180. Add completion definitions for helper functions. --- plugins/rvm/rvm.plugin.zsh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/plugins/rvm/rvm.plugin.zsh b/plugins/rvm/rvm.plugin.zsh index ef934d547..274123836 100644 --- a/plugins/rvm/rvm.plugin.zsh +++ b/plugins/rvm/rvm.plugin.zsh @@ -1,3 +1,28 @@ fpath=($ZSH/plugins/rvm $fpath) autoload -U compinit compinit -i + +local ruby18='ruby-1.8.7-p334' +local ruby19='ruby-1.9.2-p180' + +function rb18 { + if [ -z "$1" ]; then + rvm use "$ruby18" + else + rvm use "$ruby18@$1" + fi +} + +_rb18() {compadd `ls -1 $rvm_path/gems | grep "^$ruby18@" | sed -e "s/^$ruby18@//" | awk '{print $1}'`} +compdef _rb18 rb18 + +function rb19 { + if [ -z "$1" ]; then + rvm use "$ruby19" + else + rvm use "$ruby19@$1" + fi +} + +_rb19() {compadd `ls -1 $rvm_path/gems | grep "^$ruby19@" | sed -e "s/^$ruby19@//" | awk '{print $1}'`} +compdef _rb19 rb19 From e703c9591c64cd23bb0f0e1a892fbed0efe74fa7 Mon Sep 17 00:00:00 2001 From: Andrew Hodges Date: Sat, 28 May 2011 10:23:06 -0400 Subject: [PATCH 31/64] Helpful Listing Aliases Add alias to list installed rubies. Add alias to list gemsets in active ruby. --- plugins/rvm/rvm.plugin.zsh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/rvm/rvm.plugin.zsh b/plugins/rvm/rvm.plugin.zsh index 274123836..ba780c97d 100644 --- a/plugins/rvm/rvm.plugin.zsh +++ b/plugins/rvm/rvm.plugin.zsh @@ -2,6 +2,9 @@ fpath=($ZSH/plugins/rvm $fpath) autoload -U compinit compinit -i +alias rubies='rvm list rubies' +alias gemsets='rvm gemset list' + local ruby18='ruby-1.8.7-p334' local ruby19='ruby-1.9.2-p180' From 9f34bbedc8d4843b0ed50f76d38b63e5aa48cc8b Mon Sep 17 00:00:00 2001 From: Andrew Hodges Date: Sat, 28 May 2011 10:35:54 -0400 Subject: [PATCH 32/64] RVM Update Helpers Add helper function to get rvm head. Add helper function to link zsh completion that comes with rvm into om-my-zsh plugin directory, but don't overwrite the completion that comes with oh-my-zsh (oh-my-zsh's completion is better, but I want to be able to compare). --- plugins/rvm/rvm.plugin.zsh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/rvm/rvm.plugin.zsh b/plugins/rvm/rvm.plugin.zsh index ba780c97d..509dcbd98 100644 --- a/plugins/rvm/rvm.plugin.zsh +++ b/plugins/rvm/rvm.plugin.zsh @@ -29,3 +29,12 @@ function rb19 { _rb19() {compadd `ls -1 $rvm_path/gems | grep "^$ruby19@" | sed -e "s/^$ruby19@//" | awk '{print $1}'`} compdef _rb19 rb19 + +function rvm-update { + rvm get head + rvm reload # TODO: Reload rvm completion? +} + +function rvm-link-completion { + ln -s "$rvm_path/scripts/zsh/Completion/_rvm" "$ZSH/plugins/rvm/_rvm.official" +} From 572b27b75724d00fbc99ef64de3dbd21a28c8194 Mon Sep 17 00:00:00 2001 From: Andrew Hodges Date: Sat, 28 May 2011 10:50:06 -0400 Subject: [PATCH 33/64] Gem List Helper Add helper function to list gems in a pretty way (only with rvm, for now). Add missng EOF newline and a todo to the ruby plugin. --- plugins/ruby/ruby.plugin.zsh | 4 +++- plugins/rvm/rvm.plugin.zsh | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/ruby/ruby.plugin.zsh b/plugins/ruby/ruby.plugin.zsh index 82bf5d49d..08ca9c601 100644 --- a/plugins/ruby/ruby.plugin.zsh +++ b/plugins/ruby/ruby.plugin.zsh @@ -1,4 +1,6 @@ +# TODO: Make this compatible with rvm. +# Run sudo gem on the system ruby, not the active ruby. alias sgem='sudo gem' # Find ruby file -alias rfind='find . -name *.rb | xargs grep -n' \ No newline at end of file +alias rfind='find . -name *.rb | xargs grep -n' diff --git a/plugins/rvm/rvm.plugin.zsh b/plugins/rvm/rvm.plugin.zsh index 509dcbd98..8a3ec788a 100644 --- a/plugins/rvm/rvm.plugin.zsh +++ b/plugins/rvm/rvm.plugin.zsh @@ -38,3 +38,15 @@ function rvm-update { function rvm-link-completion { ln -s "$rvm_path/scripts/zsh/Completion/_rvm" "$ZSH/plugins/rvm/_rvm.official" } + +# TODO: Make this usable w/o rvm. +function gems { + local current_ruby=`rvm-prompt i v p` + local current_gemset=`rvm-prompt g` + + gem list $@ | sed \ + -Ee "s/\([0-9\.]+( .+)?\)/$fg[blue]&$reset_color/g" \ + -Ee "s|$(echo $rvm_path)|$fg[magenta]\$rvm_path$reset_color|g" \ + -Ee "s/$current_ruby@global/$fg[yellow]&$reset_color/g" \ + -Ee "s/$current_ruby$current_gemset$/$fg[green]&$reset_color/g" +} From e263f1f0057f6cac15ef588c681e6f49713c3975 Mon Sep 17 00:00:00 2001 From: Andrew Hodges Date: Sat, 28 May 2011 10:57:48 -0400 Subject: [PATCH 34/64] Brew Plugin Merge completion with official brew completion. Add a helper to link official completion into oh-my-zsh plugin (without overwriting). Add an alias to list installed brews. Add brews to the path (in a somewhat strange way). --- plugins/brew/_brew | 24 +++++++++++++++++------- plugins/brew/brew.plugin.zsh | 13 +++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 plugins/brew/brew.plugin.zsh diff --git a/plugins/brew/_brew b/plugins/brew/_brew index cee1e25f0..1dcf0a4bf 100644 --- a/plugins/brew/_brew +++ b/plugins/brew/_brew @@ -25,10 +25,12 @@ _1st_arguments=( 'link:link a formula' 'list:list files in a formula or not-installed formulae' 'log:git commit log for a formula' + 'missing:check all installed formuale for missing dependencies.' 'outdated:list formulas for which a newer version is available' 'prune:remove dead links' 'remove:remove a formula' 'search:search for a formula (/regex/ or string)' + 'server:start a local web app that lets you browse formulae (requires Sinatra)' 'unlink:unlink a formula' 'update:freshen up links' 'upgrade:upgrade outdated formulae' @@ -36,10 +38,14 @@ _1st_arguments=( ) local expl -local -a formula installed_formulae +local -a formulae installed_formulae _arguments \ - '(-v --verbose)'{-v,--verbose}'[verbose]' \ + '(-v)-v[verbose]' \ + '(--cellar)--cellar[brew cellar]' \ + '(--config)--config[brew configuration]' \ + '(--env)--env[brew environment]' \ + '(--repository)--repository[brew repository]' \ '(--version)--version[version information]' \ '(--prefix)--prefix[where brew lives on this system]' \ '(--cache)--cache[brew cache]' \ @@ -51,20 +57,24 @@ if (( CURRENT == 1 )); then fi case "$words[1]" in - list) + search|-S) + _arguments \ + '(--macports)--macports[search the macports repository]' \ + '(--fink)--fink[search the fink repository]' ;; + list|ls) _arguments \ '(--unbrewed)--unbrewed[files in brew --prefix not controlled by brew]' \ + '(--versions)--versions[list all installed versions of a formula]' \ '1: :->forms' && return 0 if [[ "$state" == forms ]]; then _brew_installed_formulae - _requested installed_formulae expl 'installed formulae' compadd -a installed_formulae + _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae fi ;; - install|home|log|info|uses|cat|deps) + install|home|homepage|log|info|abv|uses|cat|deps|edit|options) _brew_all_formulae _wanted formulae expl 'all formulae' compadd -a formulae ;; - remove|edit|xo) + remove|rm|uninstall|unlink|cleanup|link|ln) _brew_installed_formulae _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;; esac - diff --git a/plugins/brew/brew.plugin.zsh b/plugins/brew/brew.plugin.zsh new file mode 100644 index 000000000..f584a4684 --- /dev/null +++ b/plugins/brew/brew.plugin.zsh @@ -0,0 +1,13 @@ +# Move /usr/local/bin (path where brews are linked) to the front of the path +# This will allow us to override system binaries like ruby with our brews +# TODO: Do this in a more compatible way. +# What if someone doesn't have /usr/bin in their path? +export PATH=`echo $PATH | sed -e 's|/usr/local/bin||' -e 's|::|:|g'` # Remove /usr/local/bin +export PATH=`echo $PATH | sed -e 's|/usr/bin|/usr/local/bin:&|'` # Add it in front of /usr/bin +export PATH=`echo $PATH | sed -e 's|/usr/bin|/usr/local/sbin:&|'` # Add /usr/local/sbin + +alias brews='brew list -1' + +function brew-link-completion { + ln -s "$(brew --prefix)/Library/Contributions/brew_zsh_completion.zsh" "$ZSH/plugins/brew/_brew.official" +} From befb02e3da0573fa788114e1c18c70b75f787f1f Mon Sep 17 00:00:00 2001 From: Andrew Hodges Date: Sat, 28 May 2011 11:09:37 -0400 Subject: [PATCH 35/64] Pow! Restart Helper Add helper function to restart an app running on Pow! --- plugins/pow/pow.plugin.zsh | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 plugins/pow/pow.plugin.zsh diff --git a/plugins/pow/pow.plugin.zsh b/plugins/pow/pow.plugin.zsh new file mode 100644 index 000000000..6b2a6f2be --- /dev/null +++ b/plugins/pow/pow.plugin.zsh @@ -0,0 +1,10 @@ +# Thanks to Christopher Sexton +# https://gist.github.com/965032 +function kapow { + touch ~/.pow/$1/tmp/restart.txt + if [ $? -eq 0 ]; then + echo "$fg[yellow]Pow restarting $1...$reset_color" + fi +} + +compctl -W ~/.pow -/ kapow From d72b9c5ec5d55765998bb301b3425fbe84012c1f Mon Sep 17 00:00:00 2001 From: Andrew Hodges Date: Sat, 28 May 2011 11:20:48 -0400 Subject: [PATCH 36/64] Node.js Helpers Add helper function to open node api in browser. Add binaries installed via npm to path. Tell node where to find things (what things?). --- plugins/node/node.plugin.zsh | 8 ++++++++ plugins/npm/npm.plugin.zsh | 2 ++ 2 files changed, 10 insertions(+) create mode 100644 plugins/node/node.plugin.zsh create mode 100644 plugins/npm/npm.plugin.zsh diff --git a/plugins/node/node.plugin.zsh b/plugins/node/node.plugin.zsh new file mode 100644 index 000000000..18f35333c --- /dev/null +++ b/plugins/node/node.plugin.zsh @@ -0,0 +1,8 @@ +# This works if you installed node via homebrew. +export NODE_PATH="/usr/local/lib/node" + +# Open the node api for your current version to the optional section. +# TODO: Make the section part easier to use. +function node-api { + open "http://nodejs.org/docs/$(node --version)/api/all.html#$1" +} diff --git a/plugins/npm/npm.plugin.zsh b/plugins/npm/npm.plugin.zsh new file mode 100644 index 000000000..0b0a30e11 --- /dev/null +++ b/plugins/npm/npm.plugin.zsh @@ -0,0 +1,2 @@ +# TODO: Don't do this in such a weird way. +export PATH=`echo $PATH | sed -e 's|/usr/bin|/usr/local/share/npm/bin:&|'` From 18293cd724224282d6ca473fcbe6e7439d3eac0c Mon Sep 17 00:00:00 2001 From: Andrew Hodges Date: Sat, 28 May 2011 11:27:50 -0400 Subject: [PATCH 37/64] OS X Helpers Add helper aliases for show/hide files. Add helper alias to recursively delete .DS_Store files. --- plugins/osx/osx.plugin.zsh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index 81eed5e92..a65ca642a 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -1,3 +1,9 @@ +alias showfiles='defaults write com.apple.finder AppleShowAllFiles TRUE; killall Finder' +alias hidefiles='defaults write com.apple.finder AppleShowAllFiles FALSE; killall Finder' + +# Recursively delete .DS_Store files +alias rm-dsstore="find . -name '*.DS_Store' -type f -delete" + function savepath() { pwd > ~/.current_path~ } From 18ab94bccd3cfe64f81ab2ea0e09ce4a630a21bc Mon Sep 17 00:00:00 2001 From: brian tse Date: Sat, 28 May 2011 23:57:32 +0800 Subject: [PATCH 38/64] Add new 'minimal' theme --- themes/minimal.zsh-theme | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 themes/minimal.zsh-theme diff --git a/themes/minimal.zsh-theme b/themes/minimal.zsh-theme new file mode 100644 index 000000000..ee3ab6b22 --- /dev/null +++ b/themes/minimal.zsh-theme @@ -0,0 +1,15 @@ +ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[white]%}[" +ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}●%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_CLEAN="" + +#Customized git status, oh-my-zsh currently does not allow render dirty status before branch +git_custom_status() { + local cb=$(current_branch) + if [ -n "$cb" ]; then + echo "- $ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX" + fi +} + + +PROMPT='%2~ $(git_custom_status) »%b ' \ No newline at end of file From ace84c8b7eb8b50842798bac9811d02928f58dd3 Mon Sep 17 00:00:00 2001 From: Andrew Hodges Date: Sat, 28 May 2011 13:06:03 -0400 Subject: [PATCH 39/64] Cleanup Add missing newlines at EOF. Remove redundant comment. Fix grammar in comment. --- plugins/cap/cap.plugin.zsh | 2 +- plugins/compleat/compleat.plugin.zsh | 2 -- plugins/github/github.plugin.zsh | 1 - plugins/textmate/textmate.plugin.zsh | 4 +--- 4 files changed, 2 insertions(+), 7 deletions(-) diff --git a/plugins/cap/cap.plugin.zsh b/plugins/cap/cap.plugin.zsh index a0fa21d00..8336182d5 100644 --- a/plugins/cap/cap.plugin.zsh +++ b/plugins/cap/cap.plugin.zsh @@ -18,4 +18,4 @@ function _cap () { fi } -compctl -K _cap cap \ No newline at end of file +compctl -K _cap cap diff --git a/plugins/compleat/compleat.plugin.zsh b/plugins/compleat/compleat.plugin.zsh index 8d16a5687..38f1b396a 100644 --- a/plugins/compleat/compleat.plugin.zsh +++ b/plugins/compleat/compleat.plugin.zsh @@ -5,7 +5,6 @@ # VERSION: 1.0.0 # ------------------------------------------------------------------------------ - if (( ${+commands[compleat]} )); then local prefix="${commands[compleat]:h:h}" local setup="${prefix}/share/compleat-1.0/compleat_setup" @@ -19,4 +18,3 @@ if (( ${+commands[compleat]} )); then source "$setup" fi fi - diff --git a/plugins/github/github.plugin.zsh b/plugins/github/github.plugin.zsh index df7053ba7..1eb338113 100644 --- a/plugins/github/github.plugin.zsh +++ b/plugins/github/github.plugin.zsh @@ -4,4 +4,3 @@ if [ "$commands[(I)hub]" ]; then # eval `hub alias -s zsh` function git(){hub "$@"} fi - diff --git a/plugins/textmate/textmate.plugin.zsh b/plugins/textmate/textmate.plugin.zsh index 7c4c14a5f..aa2f75f4f 100644 --- a/plugins/textmate/textmate.plugin.zsh +++ b/plugins/textmate/textmate.plugin.zsh @@ -1,11 +1,9 @@ - -# TextMate alias et='mate .' alias ett='mate app config lib db public spec test Rakefile Capfile Todo' alias etp='mate app config lib db public spec test vendor/plugins vendor/gems Rakefile Capfile Todo' alias etts='mate app config lib db public script spec test vendor/plugins vendor/gems Rakefile Capfile Todo' -# Editor Ruby file in TextMate +# Edit Ruby app in TextMate alias mr='mate CHANGELOG app config db lib public script spec test' function tm() { From 18bfb14a2f774b115c8634cdaa3864cbdee91a94 Mon Sep 17 00:00:00 2001 From: Andrew Hodges Date: Sat, 28 May 2011 13:12:03 -0400 Subject: [PATCH 40/64] Thor Add plugin with completion for thor. --- plugins/thor/_thor | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 plugins/thor/_thor diff --git a/plugins/thor/_thor b/plugins/thor/_thor new file mode 100644 index 000000000..9f7ed5aef --- /dev/null +++ b/plugins/thor/_thor @@ -0,0 +1,4 @@ +#compdef thor +#autoload + +compadd `thor list | grep thor | cut -d " " -f 2` From 205e2f4842d1d1808b0d8d16bcfd1daeadb111d9 Mon Sep 17 00:00:00 2001 From: Magnus Woldrich Date: Sun, 29 May 2011 11:55:24 +0200 Subject: [PATCH 41/64] add trapd00r theme --- themes/trapd00r.zsh-theme | 95 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 themes/trapd00r.zsh-theme diff --git a/themes/trapd00r.zsh-theme b/themes/trapd00r.zsh-theme new file mode 100644 index 000000000..cba14c42c --- /dev/null +++ b/themes/trapd00r.zsh-theme @@ -0,0 +1,95 @@ +# Name: trapd00r zsh theme +# Author: Magnus Woldrich +# +# This theme needs a terminal supporting 256 colors as well as unicode. It also +# needs the script that splits up the current path and makes it fancy as located +# here: https://github.com/trapd00r/utils/blob/master/zsh_path +# +# By default it spans over two lines like so: +# +# scp1@shiva:pts/9-> /home » scp1 (0) +# > +# +# that's user@host:pts/-> splitted path (return status) +# +# If the current directory is a git repository, we span 3 lines; +# +# git❨ master ❩ DIRTY +# scp1@shiva:pts/4-> /home » scp1 » dev » utils (0) +# > + +autoload -U add-zsh-hook +autoload -Uz vcs_info + +local c0=$( printf "\e[m") +local c1=$( printf "\e[38;5;245m") +local c2=$( printf "\e[38;5;250m") +local c3=$( printf "\e[38;5;242m") +local c4=$( printf "\e[38;5;197m") +local c5=$( printf "\e[38;5;225m") +local c6=$( printf "\e[38;5;240m") +local c7=$( printf "\e[38;5;242m") +local c8=$( printf "\e[38;5;244m") +local c9=$( printf "\e[38;5;162m") +local c10=$(printf "\e[1m") +local c11=$(printf "\e[38;5;208m\e[1m") +local c12=$(printf "\e[38;5;142m\e[1m") +local c13=$(printf "\e[38;5;196m\e[1m") + + +# We dont want to use the extended colorset in the TTY / VC. +if [ "$TERM" = "linux" ]; then + c1=$( printf "\e[34;1m") + c2=$( printf "\e[35m") + c3=$( printf "\e[31m") + c4=$( printf "\e[31;1m") + c5=$( printf "\e[32m") + c6=$( printf "\e[32;1m") + c7=$( printf "\e[33m") + c8=$( printf "\e[33;1m") + c9=$( printf "\e[34m") + + c11=$(printf "\e[35;1m") + c12=$(printf "\e[36m") + c13=$(printf "\e[31;1m") +fi + +zstyle ':vcs_info:*' actionformats \ + '%{$c8%}(%f%s)%{$c7%}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f ' + +zstyle ':vcs_info:*' formats \ + "%{$c8%}%s%%{$c7%}❨ %{$c9%}%{$c11%}%b%{$c7%} ❩%{$reset_color%}%f " + +zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r' +zstyle ':vcs_info:*' enable git + +add-zsh-hook precmd prompt_jnrowe_precmd + +prompt_jnrowe_precmd () { + vcs_info + if [ "${vcs_info_msg_0_}" = "" ]; then + dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})" + PROMPT='%{$fg_bold[green]%}%p%{$reset_color%}${vcs_info_msg_0_}${dir_status} ${ret_status}%{$reset_color%} +> ' + +# modified, to be commited + elif [[ $(git diff --cached --name-status 2>/dev/null ) != "" ]]; then + dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})" + PROMPT='${vcs_info_msg_0_}%{$30%} %{$bg_bold[red]%}%{$fg_bold[cyan]%}C%{$fg_bold[black]%}OMMIT%{$reset_color%} +%{$fg_bold[green]%}%p%{$reset_color%}${dir_status}%{$reset_color%} +> ' + + elif [[ $(git diff --name-status 2>/dev/null ) != "" ]]; then + dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})" + PROMPT='${vcs_info_msg_0_}%{$bg_bold[red]%}%{$fg_bold[blue]%}D%{$fg_bold[black]%}IRTY%{$reset_color%} +%{$fg_bold[green]%}%p%{$reset_color%}${dir_status}%{$reset_color%} +%{$c13%}>%{$c0%} ' + else + dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})" + PROMPT='${vcs_info_msg_0_} +%{$fg_bold[green]%}%p%{$reset_color%}${dir_status} ${vcs_info_msg_0_}%{$reset_color%} +> ' +fi +} + +# vim: set ft=zsh sw=2 et tw=0: From aef3b988a2ab49223e8aa2b8054c0bc97094749a Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Sun, 29 May 2011 17:08:16 -0400 Subject: [PATCH 42/64] Synced Git completion with ZSH HEAD. --- plugins/git/_git | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/plugins/git/_git b/plugins/git/_git index 8f269e83b..e062705ee 100644 --- a/plugins/git/_git +++ b/plugins/git/_git @@ -131,7 +131,7 @@ _git-archive () { '--format=-[format of the resulting archive]:archive format:__git_archive_formats' \ '(- :)'{-l,--list}'[list available archive formats]' \ '(-v --verbose)'{-v,--verbose}'[report progress to stderr]' \ - '--prefix=-[prepend the given path prefix to to each filename]:path prefix:_directories -r ""' \ + '--prefix=-[prepend the given path prefix to each filename]:path prefix:_directories -r ""' \ '--output=[write archive to argument instead of stdout]:archive:_files' \ '--worktree-attributes[look for attributes in .gitattributes in working directory too]' \ $backend_args \ @@ -258,16 +258,22 @@ _git-branch () { d='-d -D' declare -a dependent_creation_args - dependent_creation_args=( - "($l $m $d): :__git_branch_names" - "::start-point:__git_revisions") + if (( words[(I)-r] == 0 )); then + dependent_creation_args=( + "($l $m $d): :__git_branch_names" + "::start-point:__git_revisions") + fi declare -a dependent_deletion_args if (( words[(I)-d] || words[(I)-D] )); then dependent_creation_args= dependent_deletion_args=( - '-r[delete remote-tracking branches]' - '*: :__git_ignore_line_inside_arguments __git_branch_names') + '-r[delete only remote-tracking branches]') + if (( words[(I)-r] )); then + dependent_deletion_args+='*: :__git_ignore_line_inside_arguments __git_remote_branch_names' + else + dependent_deletion_args+='*: :__git_ignore_line_inside_arguments __git_branch_names' + fi fi declare -a dependent_modification_args @@ -281,7 +287,7 @@ _git-branch () { _arguments -w -S -s \ "($c $m $d --no-color :)--color=-[turn on branch coloring]:: :__git_color_whens" \ "($c $m $d : --color)--no-color[turn off branch coloring]" \ - "($c $m $d : -a)-r[list only the remote-tracking branches]" \ + "($c $m -a)-r[list or delete only remote-tracking branches]" \ "($c $m $d : -r)-a[list both remote-tracking branches and local branches]" \ "($c $m $d : -v --verbose)"{-v,--verbose}'[show SHA1 and commit subject line for each head]' \ "($c $m $d :)--abbrev=[set minimum SHA1 display-length]: :__git_guard_number length" \ @@ -4919,7 +4925,7 @@ __git_remote_branch_names () { local expl declare -a branch_names - branch_names=(${${(f)"$(_call_program remote-branch-refs git for-each-ref --format='%(refname)' refs/remotes 2>/dev/null)"}#refs/remotes/}) + branch_names=(${${(f)"$(_call_program remote-branch-refs git for-each-ref --format='"%(refname)"' refs/remotes 2>/dev/null)"}#refs/remotes/}) __git_command_successful $pipestatus || return _wanted remote-branch-names expl 'remote branch name' compadd $* - $branch_names @@ -5162,7 +5168,7 @@ __git_files_relative () { files=() - # Collapse "//" and "/./" into "/". Strip any remaining "/." and "/". + # Collapse “//” and “/./” into “/”. Strip any remaining “/.” and “/”. for file in ${${${${${(0)1}//\/\///}//\/.\///}%/.}%/}; do integer i n (( n = $#file > $#prefix ? $#file : $#prefix )) @@ -5413,6 +5419,10 @@ __git_guard_diff-stat-width () { (( $+functions[__git_guard_number] )) || __git_guard_number () { + declare -A opts + + zparseopts -K -D -A opts M: J: V: 1 2 n F: X: + _guard "[[:digit:]]#" ${1:-number} } From 59789f8c8c1135429ccf2a148a03aa62048d930b Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Sun, 29 May 2011 21:24:53 -0400 Subject: [PATCH 43/64] Added new aliases, changed and fixed bugs in old aliases. --- custom/aliases.zsh | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/custom/aliases.zsh b/custom/aliases.zsh index bd7632ab1..e2d743c55 100644 --- a/custom/aliases.zsh +++ b/custom/aliases.zsh @@ -4,12 +4,12 @@ [[ -x "${commands[gdircolors]}" ]] && use_color_gnu='true' || use_color_bsd='true' } -[[ "$use_color_gnu" == 'true' ]] && eval $(gdircolors $HOME/.dir_colors) +[[ "$use_color_gnu" == 'true' && -e "$HOME/.dir_colors" ]] && eval $(gdircolors $HOME/.dir_colors) [[ "$use_color_bsd" == 'true' ]] && export CLICOLOR=1 [[ "$use_color_bsd" == 'true' ]] && export LSCOLORS="exfxcxdxbxegedabagacad" # add colors for filetype recognition -[[ "$use_color_gnu" == 'true' ]] && alias ls='ls -hF --group-directories-first --color=auto' +[[ "$use_color_gnu" == 'true' ]] && alias ls='ls -hF --group-directories-first --color=auto' [[ "$use_color_bsd" == 'true' ]] && alias ls='ls -G -F' alias la='ls -Ahl' # show hidden files @@ -29,15 +29,17 @@ alias rm='nocorrect rm -i' alias cp='nocorrect cp -i' alias mv='nocorrect mv -i' alias ln='nocorrect ln -i' +alias mkdir='nocorrect mkdir -p' alias du='du -kh' alias df='df -kh' -alias e="$EDITOR" +alias e="$EDITOR" alias get='curl -C - -O' -alias mkdir='nocorrect mkdir -p' alias q='exit' alias ssh='ssh -X' alias h='history' alias j='jobs -l' +alias f='fg' +alias gr='grep -r' alias type='type -a' alias print-path='echo -e ${PATH//:/\\n}' alias print-libpath='echo -e ${LD_LIBRARY_PATH//:/\\n}' @@ -58,17 +60,17 @@ fi # Screen # ------------------------------------------------------------------------------ -[[ "$TERM" == 'xterm-color' ]] && screenrc="$HOME/.screenrc" -[[ "$TERM" == 'xterm-256color' ]] && screenrc="$HOME/.screenrc256" -alias screen="screen -c '$screenrc'" -alias sls="screen -c '$screenrc' -list" -alias surd="screen -c '$screenrc' -aAURD" -alias sus="screen -c '$screenrc' -US" +[[ "$TERM" == 'xterm-color' && -e "$HOME/.screenrc" ]] && screenrc="-c '$HOME/.screenrc'" +[[ "$TERM" == 'xterm-256color' && -e "$HOME/.screenrc256" ]] && screenrc="-c '$HOME/.screenrc256'" +alias screen="screen $screenrc" +alias sl="screen $screenrc -list" +alias sr="screen $screenrc -a -A -U -D -R" +alias S="screen $screenrc -U -S" # TMUX # ------------------------------------------------------------------------------ -[[ "$TERM" == 'xterm-color' ]] && tmuxconf="$HOME/.tmux.conf" -[[ "$TERM" == 'xterm-256color' ]] && tmuxconf="$HOME/.tmux256.conf" -alias tmux="tmux -f '$tmuxconf'" +[[ "$TERM" == 'xterm-color' && -e "$HOME/.tmux.conf" ]] && tmuxconf="-f '$HOME/.tmux.conf'" +[[ "$TERM" == 'xterm-256color' && -e "$HOME/.tmux256.conf" ]] && tmuxconf="-f '$HOME/.tmux256.conf'" +alias tmux="tmux $tmuxconf" alias tls="tmux list-sessions" From e9d2eee6e31550a55b8250ccebda38264fcf2ff3 Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Mon, 30 May 2011 18:39:04 -0400 Subject: [PATCH 44/64] Merged custom and lib. --- custom/aliases.zsh | 76 ----------------------- custom/directories.zsh | 1 - custom/functions.zsh | 47 --------------- custom/grep.zsh | 8 --- custom/history-substring-search.zsh | 4 -- custom/shortcuts.zsh | 5 -- lib/aliases.zsh | 93 +++++++++++++++++++++++------ lib/functions.zsh | 47 +++++++++++++++ lib/grep.zsh | 8 ++- oh-my-zsh.sh | 10 +--- 10 files changed, 130 insertions(+), 169 deletions(-) delete mode 100644 custom/aliases.zsh delete mode 100644 custom/directories.zsh delete mode 100644 custom/functions.zsh delete mode 100644 custom/grep.zsh delete mode 100644 custom/history-substring-search.zsh delete mode 100644 custom/shortcuts.zsh diff --git a/custom/aliases.zsh b/custom/aliases.zsh deleted file mode 100644 index e2d743c55..000000000 --- a/custom/aliases.zsh +++ /dev/null @@ -1,76 +0,0 @@ -# The 'ls' family -# ------------------------------------------------------------------------------ -[[ "$DISABLE_COLOR" != 'true' ]] && { - [[ -x "${commands[gdircolors]}" ]] && use_color_gnu='true' || use_color_bsd='true' -} - -[[ "$use_color_gnu" == 'true' && -e "$HOME/.dir_colors" ]] && eval $(gdircolors $HOME/.dir_colors) -[[ "$use_color_bsd" == 'true' ]] && export CLICOLOR=1 -[[ "$use_color_bsd" == 'true' ]] && export LSCOLORS="exfxcxdxbxegedabagacad" - -# add colors for filetype recognition -[[ "$use_color_gnu" == 'true' ]] && alias ls='ls -hF --group-directories-first --color=auto' -[[ "$use_color_bsd" == 'true' ]] && alias ls='ls -G -F' - -alias la='ls -Ahl' # show hidden files -alias lx='ls -lhXB' # sort by extension -alias lk='ls -lhSr' # sort by size, biggest last -alias lc='ls -lhtcr' # sort by and show change time, most recent last -alias lu='ls -lhtur' # sort by and show access time, most recent last -alias lt='ls -lhtr' # sort by date, most recent last -alias lm='ls -ahl | more' # pipe through 'more' -alias lr='ls -lhR' # recursive ls -alias l='ls -lha' -alias ll='ls -lh' - -# General -# ------------------------------------------------------------------------------ -alias rm='nocorrect rm -i' -alias cp='nocorrect cp -i' -alias mv='nocorrect mv -i' -alias ln='nocorrect ln -i' -alias mkdir='nocorrect mkdir -p' -alias du='du -kh' -alias df='df -kh' -alias e="$EDITOR" -alias get='curl -C - -O' -alias q='exit' -alias ssh='ssh -X' -alias h='history' -alias j='jobs -l' -alias f='fg' -alias gr='grep -r' -alias type='type -a' -alias print-path='echo -e ${PATH//:/\\n}' -alias print-libpath='echo -e ${LD_LIBRARY_PATH//:/\\n}' -alias lsbom='lsbom -f -l -s -pf' -alias t="$HOME/.local/bin/t --task-dir ~/.tasks --list todo.txt --delete-if-empty" - -if [[ -x "${commands[htop]}" ]]; then - alias top=htop -else - alias topm='top -o vsize' - alias topc='top -o cpu' -fi - -[[ "$DISABLE_COLOR" != 'true' ]] && { - [[ -x "${commands[colordiff]}" ]] && alias diff='colordiff' - [[ -x "${commands[colormake]}" ]] && alias make='colormake' -} - -# Screen -# ------------------------------------------------------------------------------ -[[ "$TERM" == 'xterm-color' && -e "$HOME/.screenrc" ]] && screenrc="-c '$HOME/.screenrc'" -[[ "$TERM" == 'xterm-256color' && -e "$HOME/.screenrc256" ]] && screenrc="-c '$HOME/.screenrc256'" -alias screen="screen $screenrc" -alias sl="screen $screenrc -list" -alias sr="screen $screenrc -a -A -U -D -R" -alias S="screen $screenrc -U -S" - -# TMUX -# ------------------------------------------------------------------------------ -[[ "$TERM" == 'xterm-color' && -e "$HOME/.tmux.conf" ]] && tmuxconf="-f '$HOME/.tmux.conf'" -[[ "$TERM" == 'xterm-256color' && -e "$HOME/.tmux256.conf" ]] && tmuxconf="-f '$HOME/.tmux256.conf'" -alias tmux="tmux $tmuxconf" -alias tls="tmux list-sessions" - diff --git a/custom/directories.zsh b/custom/directories.zsh deleted file mode 100644 index 1237335b4..000000000 --- a/custom/directories.zsh +++ /dev/null @@ -1 +0,0 @@ -unsetopt auto_pushd \ No newline at end of file diff --git a/custom/functions.zsh b/custom/functions.zsh deleted file mode 100644 index 91d624b57..000000000 --- a/custom/functions.zsh +++ /dev/null @@ -1,47 +0,0 @@ -function cdll() { - if [[ -n "$1" ]]; then - builtin cd "$1" - ls -lFhA - else - ls -lFhA - fi -} - -function pushdll() { - if [[ -n "$1" ]]; then - builtin pushd "$1" - ls -lFhA - else - ls -lFhA - fi -} - -function popdll() { - builtin popd - ls -lFhA -} - -function grab() { - sudo chown -R ${USER} ${1:-.} -} - -function reload() { - source "$HOME/.zshrc" -} - -function calc() { - echo "scale=4; $@" | bc -l -} - -function pmine() { - ps $@ -u $USER -o pid,%cpu,%mem,command -} - -function findexec() { - find . -type f -iname '*'${1:-}'*' -exec ${2:-file} {} \; -} - -function httpserve() { - python -m SimpleHTTPServer -} - diff --git a/custom/grep.zsh b/custom/grep.zsh deleted file mode 100644 index 23d9d55f9..000000000 --- a/custom/grep.zsh +++ /dev/null @@ -1,8 +0,0 @@ -if [[ "$DISABLE_COLOR" != "true" ]]; then - export GREP_OPTIONS='--color=auto' - export GREP_COLOR='37;45' -else - export GREP_OPTIONS='--color=none' - export GREP_COLOR='' -fi - diff --git a/custom/history-substring-search.zsh b/custom/history-substring-search.zsh deleted file mode 100644 index 6c54f0451..000000000 --- a/custom/history-substring-search.zsh +++ /dev/null @@ -1,4 +0,0 @@ -if [[ "$DISABLE_COLOR" == "true" ]]; then - F_ordinary_highlight="bg=none,fg=none" - F_out_of_matches_highlight="bg=none,fg=none" -fi diff --git a/custom/shortcuts.zsh b/custom/shortcuts.zsh deleted file mode 100644 index 28ffcae25..000000000 --- a/custom/shortcuts.zsh +++ /dev/null @@ -1,5 +0,0 @@ -# Add yourself some shortcuts to projects you often work on -# Example: -# -# brainstormr=/Users/robbyrussell/Projects/development/planetargon/brainstormr -# \ No newline at end of file diff --git a/lib/aliases.zsh b/lib/aliases.zsh index 0555be264..a529f816f 100644 --- a/lib/aliases.zsh +++ b/lib/aliases.zsh @@ -1,24 +1,83 @@ -# Push and pop directories on directory stack -alias pu='pushd' -alias po='popd' +# The 'ls' family +# ------------------------------------------------------------------------------ +[[ "$DISABLE_COLOR" != 'true' ]] && { + [[ -x "${commands[gdircolors]}" ]] && use_color_gnu='true' || use_color_bsd='true' +} -# Basic directory operations +[[ "$use_color_gnu" == 'true' && -e "$HOME/.dir_colors" ]] && eval $(gdircolors $HOME/.dir_colors) +[[ "$use_color_bsd" == 'true' ]] && export CLICOLOR=1 +[[ "$use_color_bsd" == 'true' ]] && export LSCOLORS="exfxcxdxbxegedabagacad" + +# add colors for filetype recognition +[[ "$use_color_gnu" == 'true' ]] && alias ls='ls -hF --group-directories-first --color=auto' +[[ "$use_color_bsd" == 'true' ]] && alias ls='ls -G -F' + +alias ll='ls -lh' # show human readable +alias la='ls -lhA' # show hidden files +alias lx='ls -lhXB' # sort by extension +alias lk='ls -lhSr' # sort by size, biggest last +alias lc='ls -lhtcr' # sort by and show change time, most recent last +alias lu='ls -lhtur' # sort by and show access time, most recent last +alias lt='ls -lhtr' # sort by date, most recent last +alias lm='ls -lha | more' # pipe through 'more' +alias lr='ls -lhR' # recursive ls +alias sl='ls' # often screw this up + +# General +# ------------------------------------------------------------------------------ alias ...='cd ../..' alias -- -='cd -' - -# Super user +alias rm='nocorrect rm -i' +alias cp='nocorrect cp -i' +alias mv='nocorrect mv -i' +alias ln='nocorrect ln -i' +alias mkdir='nocorrect mkdir -p' +alias du='du -kh' +alias df='df -kh' +alias pu='pushd' +alias po='popd' alias _='sudo' - -#alias g='grep -in' - -# Show history +alias e="$EDITOR" +alias q='exit' alias history='fc -l 1' - -# List direcory contents -alias lsa='ls -lah' -alias l='ls -la' -alias ll='ls -l' -alias sl=ls # often screw this up - +alias h='history' +alias j='jobs -l' +alias f='fg' +alias gr='grep -r' +alias get='curl -C - -O' alias afind='ack-grep -il' +alias type='type -a' +alias ssh='ssh -X' +alias print-path='echo -e ${PATH//:/\\n}' +alias print-libpath='echo -e ${LD_LIBRARY_PATH//:/\\n}' +alias lsbom='lsbom -f -l -s -pf' +alias t="$HOME/.local/bin/t --task-dir ~/.tasks --list todo.txt --delete-if-empty" + +if [[ -x "${commands[htop]}" ]]; then + alias top=htop +else + alias topm='top -o vsize' + alias topc='top -o cpu' +fi + +[[ "$DISABLE_COLOR" != 'true' ]] && { + [[ -x "${commands[colordiff]}" ]] && alias diff='colordiff' + [[ -x "${commands[colormake]}" ]] && alias make='colormake' +} + +# Screen +# ------------------------------------------------------------------------------ +[[ "$TERM" == 'xterm-color' && -e "$HOME/.screenrc" ]] && screenrc="-c '$HOME/.screenrc'" +[[ "$TERM" == 'xterm-256color' && -e "$HOME/.screenrc256" ]] && screenrc="-c '$HOME/.screenrc256'" +alias screen="screen $screenrc" +alias sl="screen $screenrc -list" +alias sr="screen $screenrc -a -A -U -D -R" +alias S="screen $screenrc -U -S" + +# TMUX +# ------------------------------------------------------------------------------ +[[ "$TERM" == 'xterm-color' && -e "$HOME/.tmux.conf" ]] && tmuxconf="-f '$HOME/.tmux.conf'" +[[ "$TERM" == 'xterm-256color' && -e "$HOME/.tmux256.conf" ]] && tmuxconf="-f '$HOME/.tmux256.conf'" +alias tmux="tmux $tmuxconf" +alias tls="tmux list-sessions" diff --git a/lib/functions.zsh b/lib/functions.zsh index ef7cc6383..f26659ec3 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -15,3 +15,50 @@ function take() { cd $1 } +function cdll() { + if [[ -n "$1" ]]; then + builtin cd "$1" + ls -lFhA + else + ls -lFhA + fi +} + +function pushdll() { + if [[ -n "$1" ]]; then + builtin pushd "$1" + ls -lFhA + else + ls -lFhA + fi +} + +function popdll() { + builtin popd + ls -lFhA +} + +function grab() { + sudo chown -R ${USER} ${1:-.} +} + +function reload() { + source "$HOME/.zshrc" +} + +function calc() { + echo "scale=4; $@" | bc -l +} + +function pmine() { + ps $@ -u $USER -o pid,%cpu,%mem,command +} + +function findexec() { + find . -type f -iname '*'${1:-}'*' -exec ${2:-file} {} \; +} + +function httpserve() { + python -m SimpleHTTPServer +} + diff --git a/lib/grep.zsh b/lib/grep.zsh index 714ac9ccb..3e1f213e7 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -1,4 +1,8 @@ if [[ "$DISABLE_COLOR" != "true" ]]; then - [[ -z "$GREP_OPTIONS" ]] && export GREP_OPTIONS='--color=auto' - [[ -z "$GREP_COLOR" ]] && export GREP_COLOR='1;32' + export GREP_OPTIONS='--color=auto' + export GREP_COLOR='37;45' +else + export GREP_OPTIONS='--color=none' + export GREP_COLOR='' fi + diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index bc6a92973..69b4b033f 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -5,9 +5,6 @@ if [ "$TERM" = "dumb" ]; then DISABLE_COLOR="true" fi -# add a function path -fpath=($ZSH/functions $ZSH/completions $fpath) - # Load all of the config files in ~/oh-my-zsh that end in .zsh # TIP: Add files you don't want in git to .gitignore for config_file ($ZSH/lib/*.zsh) source $config_file @@ -22,9 +19,7 @@ compinit -i # Load all of the plugins that were defined in ~/.zshrc for plugin ($plugins); do - if [ -f $ZSH/custom/plugins/$plugin/$plugin.plugin.zsh ]; then - source $ZSH/custom/plugins/$plugin/$plugin.plugin.zsh - elif [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then + if [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then source $ZSH/plugins/$plugin/$plugin.plugin.zsh fi done @@ -43,9 +38,6 @@ else source "$ZSH/themes/$ZSH_THEME.zsh-theme" fi -# Load all of your custom configurations from custom/ -for config_file ($ZSH/custom/*.zsh) source $config_file - # Compile zcompdump, if modified, to increase startup speed. if [ "$HOME/.zcompdump" -nt "$HOME/.zcompdump.zwc" -o ! -e "$HOME/.zcompdump.zwc" ]; then zcompile "$HOME/.zcompdump" From 52b63cd2cee7ba025ed6a52fb82a76403b229251 Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Mon, 30 May 2011 19:46:27 -0400 Subject: [PATCH 45/64] Removed tools I have never used nor will I ever use. --- README.textile | 18 ------------------ lib/functions.zsh | 8 -------- oh-my-zsh.sh | 7 ------- templates/zshrc.zsh-template | 3 --- tools/check_for_upgrade.sh | 35 ----------------------------------- tools/install.sh | 36 ------------------------------------ tools/uninstall.sh | 20 -------------------- tools/upgrade.sh | 12 ------------ 8 files changed, 139 deletions(-) delete mode 100644 tools/check_for_upgrade.sh delete mode 100755 tools/install.sh delete mode 100644 tools/uninstall.sh delete mode 100644 tools/upgrade.sh diff --git a/README.textile b/README.textile index 2dbfbe5a6..c176540fd 100644 --- a/README.textile +++ b/README.textile @@ -6,13 +6,6 @@ h2. Setup @oh-my-zsh@ should work with any recent release of "zsh":http://www.zsh.org/, the minimum recommended version is 4.3.9. -h3. The automatic installer... (do you trust me?) - -@wget --no-check-certificate https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh@ - -h3. The manual way - - 1. Clone the repository @git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh@ @@ -47,23 +40,12 @@ the "refcard":http://www.bash2zsh.com/zsh_refcard/refcard.pdf is pretty tasty fo h3. Customization -If you want to override any of the default behavior, just add a new file (ending in @.zsh@) into the @custom/@ directory. If you have many functions which go good together you can put them as a *.plugin.zsh file in the @custom/plugins/@ directory and then enable this plugin. -If you would like to override the functionality of a plugin distributed with oh-my-zsh, create a plugin of the same name in the @custom/plugins/@ directory and it will be loaded instead of the one in @plugins/@. - - -h3. Uninstalling - -If you want to uninstall it, just run @uninstall_oh_my_zsh@ from the command line and it'll remove itself and revert you to bash (or your previous zsh config). h2. Help out! I'm far from being a zsh-expert and suspect there are many ways to improve. If you have ideas on how to make the configuration easier to maintain (and faster), don't hesitate to fork and send pull requests! -h3. Send us your theme! - -I'm hoping to collect a bunch of themes for our command prompts. You can see existing ones in the @themes/@ directory. - h2. Contributors This project wouldn't exist without all of our awesome users and contributors. diff --git a/lib/functions.zsh b/lib/functions.zsh index f26659ec3..892f0537c 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -2,14 +2,6 @@ function zsh_stats() { history | awk '{print $2}' | sort | uniq -c | sort -rn | head } -function uninstall_oh_my_zsh() { - /bin/sh $ZSH/tools/uninstall.sh -} - -function upgrade_oh_my_zsh() { - /bin/sh $ZSH/tools/upgrade.sh -} - function take() { mkdir -p $1 cd $1 diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 69b4b033f..b0b7d395e 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -43,10 +43,3 @@ if [ "$HOME/.zcompdump" -nt "$HOME/.zcompdump.zwc" -o ! -e "$HOME/.zcompdump.zwc zcompile "$HOME/.zcompdump" fi -# Check for updates on initial load... -if [ "$DISABLE_AUTO_UPDATE" = "true" ] -then - return -else - /usr/bin/env zsh $ZSH/tools/check_for_upgrade.sh -fi diff --git a/templates/zshrc.zsh-template b/templates/zshrc.zsh-template index 65299df3e..c2accfc87 100644 --- a/templates/zshrc.zsh-template +++ b/templates/zshrc.zsh-template @@ -10,9 +10,6 @@ export ZSH_THEME="robbyrussell" # Set to this to use case-sensitive completion # export CASE_SENSITIVE="true" -# Comment this out to disable weekly auto-update checks -# export DISABLE_AUTO_UPDATE="true" - # Uncomment following line if you want to disable colors in ls # export DISABLE_COLOR="true" diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh deleted file mode 100644 index e1e4eb99f..000000000 --- a/tools/check_for_upgrade.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh - -function _current_epoch() { - echo $(($(date +%s) / 60 / 60 / 24)) -} - -function _update_zsh_update() { - echo "LAST_EPOCH=$(_current_epoch)" > ~/.zsh-update -} - -if [ -f ~/.zsh-update ] -then - . ~/.zsh-update - - if [[ -z "$LAST_EPOCH" ]]; then - _update_zsh_update && return 0; - fi - - epoch_diff=$(($(_current_epoch) - $LAST_EPOCH)) - if [ $epoch_diff -gt 6 ] - then - echo "[Oh My Zsh] Would you like to check for updates?" - echo "Type Y to update oh-my-zsh: \c" - read line - if [ "$line" = Y ] || [ "$line" = y ] - then - /bin/sh $ZSH/tools/upgrade.sh - # update the zsh file - _update_zsh_update - fi - fi -else - # create the zsh file - _update_zsh_update -fi diff --git a/tools/install.sh b/tools/install.sh deleted file mode 100755 index 8ed1403af..000000000 --- a/tools/install.sh +++ /dev/null @@ -1,36 +0,0 @@ -if [ -d ~/.oh-my-zsh ] -then - echo "You already have Oh My Zsh installed. You'll need to remove ~/.oh-my-zsh if you want to install" - exit -fi - -echo "Cloning Oh My Zsh..." -/usr/bin/env git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh - -echo "Looking for an existing zsh config..." -if [ -f ~/.zshrc ] || [ -h ~/.zshrc ] -then - echo "Found ~/.zshrc. Backing up to ~/.zshrc.pre-oh-my-zsh"; - cp ~/.zshrc ~/.zshrc.pre-oh-my-zsh; - rm ~/.zshrc; -fi - -echo "Using the Oh My Zsh template file and adding it to ~/.zshrc" -cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc - -echo "Copying your current PATH and adding it to the end of ~/.zshrc for you." -echo "export PATH=$PATH" >> ~/.zshrc - -echo "Time to change your default shell to zsh!" -chsh -s `which zsh` - -echo ' __ __ ' -echo ' ____ / /_ ____ ___ __ __ ____ _____/ /_ ' -echo ' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ ' -echo '/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / ' -echo '\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ ' -echo ' /____/' - -echo "\n\n ....is now installed." -/usr/bin/env zsh -source ~/.zshrc diff --git a/tools/uninstall.sh b/tools/uninstall.sh deleted file mode 100644 index 8ff583322..000000000 --- a/tools/uninstall.sh +++ /dev/null @@ -1,20 +0,0 @@ -echo "Removing ~/.oh-my-zsh" -if [[ -d ~/.oh-my-zsh ]] -then - rm -rf ~/.oh-my-zsh -fi - -echo "Looking for an existing zsh config..." -if [ -f ~/.zshrc.pre-oh-my-zsh ] || [ -h ~/.zshrc.pre-oh-my-zsh ] -then - echo "Found ~/.zshrc. Backing up to ~/.zshrc.pre-oh-my-zsh"; - rm ~/.zshrc; - cp ~/.zshrc.pre-oh-my-zsh ~/.zshrc; - source ~/.zshrc; -else - echo "Switching back to bash" - chsh -s /bin/bash - source /etc/profile -fi - -echo "Thanks for trying out Oh My Zsh. It's been uninstalled." \ No newline at end of file diff --git a/tools/upgrade.sh b/tools/upgrade.sh deleted file mode 100644 index 6bdd02e38..000000000 --- a/tools/upgrade.sh +++ /dev/null @@ -1,12 +0,0 @@ -current_path=`pwd` -echo "Upgrading Oh My Zsh" -( cd $ZSH && git pull origin master ) -echo ' __ __ ' -echo ' ____ / /_ ____ ___ __ __ ____ _____/ /_ ' -echo ' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ ' -echo '/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / ' -echo '\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ ' -echo ' /____/' -echo "Hooray! Oh My Zsh has been updated and/or is at the current version. \nAny new updates will be reflected when you start your next terminal session." -echo "To keep up on the latest, be sure to follow Oh My Zsh on twitter: http://twitter.com/ohmyzsh" -cd $current_path \ No newline at end of file From ef526b57e15ab49bcb8fec766c3121eb5f76c97d Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Mon, 30 May 2011 19:47:55 -0400 Subject: [PATCH 46/64] Removed directories mcd function and aliases. --- lib/directories.zsh | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/directories.zsh b/lib/directories.zsh index bb114f615..539e30d22 100644 --- a/lib/directories.zsh +++ b/lib/directories.zsh @@ -34,11 +34,3 @@ cd () { fi } -alias md='mkdir -p' -alias rd=rmdir -alias d='dirs -v' - -# mkdir & cd to it -function mcd() { - mkdir -p "$1" && cd "$1"; -} \ No newline at end of file From db6c172e9f6b7c8453a57c0473e72a41e0e783e5 Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Mon, 30 May 2011 21:38:07 -0400 Subject: [PATCH 47/64] Removed unused log directory. --- log/.easter-egg | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 log/.easter-egg diff --git a/log/.easter-egg b/log/.easter-egg deleted file mode 100644 index 2533149e2..000000000 --- a/log/.easter-egg +++ /dev/null @@ -1,4 +0,0 @@ -This file is only here so that Git will keep a log directory as .gitignore is ignoring all the log files within it. - -feel free to add love notes for people here. - From 1e9b718af1a507e229c7cf25585c8a8c8b6c9415 Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Wed, 1 Jun 2011 02:48:26 -0400 Subject: [PATCH 48/64] Cleaned up /lib/, removed trailing white space everywhere. --- lib/aliases.zsh | 96 +++++++++++++----------- lib/completion.zsh | 33 ++++---- lib/correction.zsh | 1 + lib/directories.zsh | 10 ++- lib/functions.zsh | 24 +++--- lib/git.zsh | 43 +++++++---- lib/grep.zsh | 10 ++- lib/history.zsh | 19 ++--- lib/key-bindings.zsh | 20 +++-- lib/misc.zsh | 20 +++-- lib/rvm.zsh | 9 ++- lib/spectrum.zsh | 20 ++--- lib/termsupport.zsh | 41 ++++++---- lib/theme-and-appearance.zsh | 40 ++++------ oh-my-zsh.sh | 50 ++++++------ plugins/compleat/compleat.plugin.zsh | 4 +- plugins/dirpersist/dirpersist.plugin.zsh | 6 +- plugins/extract/extract.plugin.zsh | 8 +- plugins/git-flow/git-flow.plugin.zsh | 2 +- plugins/git/git.plugin.zsh | 21 +----- plugins/gnu-utils/gnu-utils.plugin.zsh | 6 +- plugins/macports/_port | 8 +- plugins/osx/osx.plugin.zsh | 6 +- plugins/perl/perl.plugin.zsh | 2 +- plugins/redis-cli/_redis-cli | 2 +- plugins/rvm/_rvm | 4 +- plugins/svn/svn.plugin.zsh | 8 +- plugins/vagrant/_vagrant | 6 +- plugins/vi-mode/vi-mode.plugin.zsh | 2 +- templates/zshrc.zsh-template | 29 ++++--- themes/Soliah.zsh-theme | 10 +-- themes/awesomepanda.zsh-theme | 2 +- themes/cloud.zsh-theme | 2 +- themes/eastwood.zsh-theme | 2 +- themes/evan.zsh-theme | 2 +- themes/example.zsh-theme | 2 +- themes/funky.zsh-theme | 2 +- themes/gallois.zsh-theme | 2 +- themes/imajes.zsh-theme | 2 +- themes/jonathan.zsh-theme | 20 ++--- themes/josh.zsh-theme | 8 +- themes/juanghurtado.zsh-theme | 2 +- themes/kardan.zsh-theme | 2 +- themes/linuxonly | 6 +- themes/mikeh.zsh-theme | 2 +- themes/minimal.zsh-theme | 2 +- themes/rixius.zsh-theme | 2 +- themes/sorin.zsh-theme | 6 +- themes/theunraveler.zsh-theme | 2 +- themes/tonotdo.zsh-theme | 2 +- 50 files changed, 332 insertions(+), 298 deletions(-) diff --git a/lib/aliases.zsh b/lib/aliases.zsh index a529f816f..0cfafc6e0 100644 --- a/lib/aliases.zsh +++ b/lib/aliases.zsh @@ -1,32 +1,35 @@ # The 'ls' family # ------------------------------------------------------------------------------ -[[ "$DISABLE_COLOR" != 'true' ]] && { - [[ -x "${commands[gdircolors]}" ]] && use_color_gnu='true' || use_color_bsd='true' -} +if [[ "$DISABLE_COLOR" != 'true' ]]; then + if (( ${+commands[dircolors]} )); then + dircolors="${commands[dircolors]}" + fi + if (( ${+commands[gdircolors]} )); then + dircolors="${commands[gdircolors]}" + fi + if [[ -x "$dircolors" ]] && [[ -e "$HOME/.dir_colors" ]]; then + eval $("$dircolors" "$HOME/.dir_colors") + alias ls='ls -hF --group-directories-first --color=auto' + else + export CLICOLOR=1 + export LSCOLORS="exfxcxdxbxegedabagacad" + alias ls='ls -G -F' + fi +fi -[[ "$use_color_gnu" == 'true' && -e "$HOME/.dir_colors" ]] && eval $(gdircolors $HOME/.dir_colors) -[[ "$use_color_bsd" == 'true' ]] && export CLICOLOR=1 -[[ "$use_color_bsd" == 'true' ]] && export LSCOLORS="exfxcxdxbxegedabagacad" - -# add colors for filetype recognition -[[ "$use_color_gnu" == 'true' ]] && alias ls='ls -hF --group-directories-first --color=auto' -[[ "$use_color_bsd" == 'true' ]] && alias ls='ls -G -F' - -alias ll='ls -lh' # show human readable -alias la='ls -lhA' # show hidden files -alias lx='ls -lhXB' # sort by extension -alias lk='ls -lhSr' # sort by size, biggest last -alias lc='ls -lhtcr' # sort by and show change time, most recent last -alias lu='ls -lhtur' # sort by and show access time, most recent last -alias lt='ls -lhtr' # sort by date, most recent last -alias lm='ls -lha | more' # pipe through 'more' -alias lr='ls -lhR' # recursive ls -alias sl='ls' # often screw this up +alias ll='ls -lh' # Show human readable. +alias la='ls -lhA' # Show hidden files. +alias lx='ls -lhXB' # Sort by extension. +alias lk='ls -lhSr' # Sort by size, biggest last. +alias lc='ls -lhtcr' # Sort by and show change time, most recent lasa. +alias lu='ls -lhtur' # Sort by and show access time, most recent last. +alias lt='ls -lhtr' # Sort by date, most recent last. +alias lm='ls -lha | more' # Pipe through 'more'. +alias lr='ls -lhR' # Recursive ls. +alias sl='ls' # I often screw this up. # General # ------------------------------------------------------------------------------ -alias ...='cd ../..' -alias -- -='cd -' alias rm='nocorrect rm -i' alias cp='nocorrect cp -i' alias mv='nocorrect mv -i' @@ -38,20 +41,13 @@ alias pu='pushd' alias po='popd' alias _='sudo' alias e="$EDITOR" -alias q='exit' alias history='fc -l 1' -alias h='history' -alias j='jobs -l' -alias f='fg' -alias gr='grep -r' alias get='curl -C - -O' -alias afind='ack-grep -il' +alias afind='ack -il' alias type='type -a' alias ssh='ssh -X' alias print-path='echo -e ${PATH//:/\\n}' -alias print-libpath='echo -e ${LD_LIBRARY_PATH//:/\\n}' -alias lsbom='lsbom -f -l -s -pf' -alias t="$HOME/.local/bin/t --task-dir ~/.tasks --list todo.txt --delete-if-empty" +alias t="t --task-dir ~/.tasks --list todo.txt --delete-if-empty" if [[ -x "${commands[htop]}" ]]; then alias top=htop @@ -60,24 +56,38 @@ else alias topc='top -o cpu' fi -[[ "$DISABLE_COLOR" != 'true' ]] && { - [[ -x "${commands[colordiff]}" ]] && alias diff='colordiff' - [[ -x "${commands[colormake]}" ]] && alias make='colormake' -} +if [[ "$DISABLE_COLOR" != 'true' ]]; then + if [[ -x "${commands[colordiff]}" ]]; then + alias diff='colordiff' + fi -# Screen + if [[ -x "${commands[colormake]}" ]]; then + alias make='colormake' + fi +fi + +# Terminal Multiplexer # ------------------------------------------------------------------------------ -[[ "$TERM" == 'xterm-color' && -e "$HOME/.screenrc" ]] && screenrc="-c '$HOME/.screenrc'" -[[ "$TERM" == 'xterm-256color' && -e "$HOME/.screenrc256" ]] && screenrc="-c '$HOME/.screenrc256'" +local screenrc tmuxconf +if [[ "$TERM" == 'xterm-color' ]]; then + if [[ -e "$HOME/.screenrc" ]]; then + screenrc="-c '$HOME/.screenrc'" + tmuxconf="-f '$HOME/.tmux.conf'" + fi +fi + +if [[ "$TERM" == 'xterm-256color' ]]; then + if [[ -e "$HOME/.screenrc256" ]]; then + screenrc="-c '$HOME/.screenrc256'" + tmuxconf="-f '$HOME/.tmux256.conf'" + fi +fi + alias screen="screen $screenrc" alias sl="screen $screenrc -list" alias sr="screen $screenrc -a -A -U -D -R" alias S="screen $screenrc -U -S" -# TMUX -# ------------------------------------------------------------------------------ -[[ "$TERM" == 'xterm-color' && -e "$HOME/.tmux.conf" ]] && tmuxconf="-f '$HOME/.tmux.conf'" -[[ "$TERM" == 'xterm-256color' && -e "$HOME/.tmux256.conf" ]] && tmuxconf="-f '$HOME/.tmux256.conf'" alias tmux="tmux $tmuxconf" alias tls="tmux list-sessions" diff --git a/lib/completion.zsh b/lib/completion.zsh index 7c81f77bd..c60faf636 100644 --- a/lib/completion.zsh +++ b/lib/completion.zsh @@ -1,19 +1,21 @@ -# fixme - the load process here seems a bit bizarre -[[ "$TERM" == "dumb" ]] && return +# Dumb terminals lack support. +if [[ "$TERM" == 'dumb' ]]; then + return +fi -unsetopt menu_complete # do not autoselect the first completion entry -unsetopt flowcontrol -setopt auto_menu # show completion menu on succesive tab press -setopt complete_in_word -setopt always_to_end +unsetopt menu_complete # Do not autoselect the first completion entry. +unsetopt flow_control # Disable start/stop characters in shell editor. +setopt auto_menu # Show completion menu on a succesive tab press. +setopt complete_in_word # Complete from both ends of a word. +setopt always_to_end # Move cursor to the end of a completed word. WORDCHARS='' -# fixme - complist is crashing ZSH on menu completion +# FIXME: complist is crashing ZSH on menu completion. # zmodload -i zsh/complist -## case-insensitive (all),partial-word and then substring completion -if [ "x$CASE_SENSITIVE" = "xtrue" ]; then +## Case-insensitive (all), partial-word, and then substring completion. +if [[ "$CASE_SENSITIVE" == "true" ]]; then zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' unset CASE_SENSITIVE else @@ -22,18 +24,19 @@ fi zstyle ':completion:*' list-colors '' -# should this be in keybindings? +# FIXME: It depends on complist which crashes ZSH on menu completion. +# Should this be in key-bindings.zsh? # bindkey -M menuselect '^o' accept-and-infer-next-history zstyle ':completion:*:*:*:*:*' menu select zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01' zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm -w -w" -# disable named-directories autocompletion +# Disable named-directories autocompletion. zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories cdpath=(.) -# use /etc/hosts and known_hosts for hostname completion +# Use /etc/hosts and known_hosts for hostname completion. [ -r ~/.ssh/known_hosts ] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=() [ -r /etc/hosts ] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$( /dev/null) || return - echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX" + local branch=$(git_current_branch) + if [[ -n "$branch" ]]; then + echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${branch}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}" + fi } -# Checks if working tree is dirty -parse_git_dirty() { +# Gets the current branch. +function git_current_branch() { + local ref=$(git symbolic-ref HEAD 2> /dev/null) + if [[ -n "$ref" ]]; then + echo "${ref#refs/heads/}" + fi +} + +# Checks if the working tree is dirty. +function parse_git_dirty() { if [[ -n $(git status -s 2> /dev/null) ]]; then echo "$ZSH_THEME_GIT_PROMPT_DIRTY" else @@ -13,25 +23,31 @@ parse_git_dirty() { fi } -# Checks if there are commits ahead from remote +# Checks if there are commits ahead from remote. function git_prompt_ahead() { - if $(echo "$(git log origin/$(current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then + if $(echo "$(git log origin/$(git_current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then echo "$ZSH_THEME_GIT_PROMPT_AHEAD" fi } -# Formats prompt string for current git commit short SHA +# Formats the prompt string for current git commit short SHA. function git_prompt_short_sha() { - SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER" + local sha=$(git rev-parse --short HEAD 2> /dev/null) + if [[ -n "$sha" ]]; then + echo "${ZSH_THEME_GIT_PROMPT_SHA_BEFORE}${sha}${ZSH_THEME_GIT_PROMPT_SHA_AFTER}" + fi } -# Formats prompt string for current git commit long SHA +# Formats the prompt string for current git commit long SHA. function git_prompt_long_sha() { - SHA=$(git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER" + local sha=$(git rev-parse HEAD 2> /dev/null) + if [[ -n "$sha" ]]; then + echo "${ZSH_THEME_GIT_PROMPT_SHA_BEFORE}${sha}${ZSH_THEME_GIT_PROMPT_SHA_AFTER}" + fi } -# Get the status of the working tree -git_prompt_status() { +# Gets the status of the working tree. +function git_prompt_status() { local indicators line untracked added modified renamed deleted while IFS=$'\n' read line; do if [[ "$line" =~ '^\?\? ' ]]; then @@ -61,3 +77,4 @@ git_prompt_status() { done < <(git status --porcelain 2> /dev/null) echo $indicators } + diff --git a/lib/grep.zsh b/lib/grep.zsh index 3e1f213e7..75cfc2925 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -1,6 +1,10 @@ -if [[ "$DISABLE_COLOR" != "true" ]]; then - export GREP_OPTIONS='--color=auto' - export GREP_COLOR='37;45' +if [[ "$DISABLE_COLOR" != 'true' ]]; then + if [[ -z "$GREP_OPTIONS" ]]; then + export GREP_OPTIONS='--color=auto' + fi + if [[ -z "$GREP_COLOR" ]]; then + export GREP_COLOR='37;45' + fi else export GREP_OPTIONS='--color=none' export GREP_COLOR='' diff --git a/lib/history.zsh b/lib/history.zsh index 604658a5f..8a32e339a 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -1,13 +1,14 @@ ## Command history configuration -HISTFILE=$HOME/.zsh_history +HISTFILE="$HOME/.zsh_history" HISTSIZE=10000 SAVEHIST=10000 -setopt HIST_VERIFY -setopt HIST_EXPIRE_DUPS_FIRST -setopt HIST_IGNORE_SPACE -setopt HIST_IGNORE_DUPS -setopt SHARE_HISTORY -setopt APPEND_HISTORY -setopt EXTENDED_HISTORY -setopt INC_APPEND_HISTORY +setopt hist_verify +setopt hist_expire_dups_first +setopt hist_ignore_space +setopt hist_ignore_dups +setopt share_history +setopt append_history +setopt extended_history +setopt inc_append_history + diff --git a/lib/key-bindings.zsh b/lib/key-bindings.zsh index 9f28d5761..fd795ed78 100644 --- a/lib/key-bindings.zsh +++ b/lib/key-bindings.zsh @@ -1,4 +1,4 @@ -# TODO: Explain what some of this does.. +# TODO: Write a GNU Emacs key bindings file akin to the vi-mode plugin. bindkey -e bindkey '\ew' kill-region @@ -8,7 +8,7 @@ bindkey '^r' history-incremental-search-backward bindkey "^[[5~" up-line-or-history bindkey "^[[6~" down-line-or-history -# make search up and down work, so partially type and hit up/down to find relevant stuff +# Make key up/down move up/down or search history. bindkey '^[[A' up-line-or-search bindkey '^[[B' down-line-or-search @@ -16,18 +16,22 @@ bindkey "^[[H" beginning-of-line bindkey "^[[1~" beginning-of-line bindkey "^[[F" end-of-line bindkey "^[[4~" end-of-line -bindkey ' ' magic-space # also do history expansion on space +# Do history expansion on space. +bindkey ' ' magic-space + +# File rename magick. +bindkey "^[m" copy-prev-shell-word bindkey '^[[Z' reverse-menu-complete -# Make the delete key (or Fn + Delete on the Mac) work instead of outputting a ~ +# Make the delete key (or Fn + Delete on the Mac) work instead of outputting a ~. bindkey "^[[3~" delete-char bindkey "^[3;5~" delete-char bindkey "\e[3~" delete-char -# consider emacs keybindings: +# Consider GNU Emacs keybindings: -#bindkey -e ## emacs key bindings +#bindkey -e # Emacs key bindings. # #bindkey '^[[A' up-line-or-search #bindkey '^[[B' down-line-or-search @@ -40,6 +44,6 @@ bindkey "\e[3~" delete-char #bindkey '^X^N' accept-and-infer-next-history #bindkey '^W' kill-region #bindkey '^I' complete-word -## Fix weird sequence that rxvt produces +## FIXME: A weird sequence that rxvt produces #bindkey -s '^[[Z' '\t' -# + diff --git a/lib/misc.zsh b/lib/misc.zsh index 364ad8792..efc38400b 100644 --- a/lib/misc.zsh +++ b/lib/misc.zsh @@ -1,13 +1,17 @@ -## smart urls +# Smart URLs autoload -U url-quote-magic zle -N self-insert url-quote-magic -## file rename magick -bindkey "^[m" copy-prev-shell-word - -## jobs +# Jobs setopt long_list_jobs -## pager -[[ -z "$PAGER" ]] && export PAGER=less -[[ -z "$LC_CTYPE" ]] && export LC_CTYPE=en_US.UTF-8 +# Pager +if [[ -z "$PAGER" ]]; then + export PAGER=less +fi + +# Localization +if [[ -z "$LC_CTYPE" ]]; then + export LC_CTYPE=en_US.UTF-8 +fi + diff --git a/lib/rvm.zsh b/lib/rvm.zsh index 597be1b33..25ba36b7d 100644 --- a/lib/rvm.zsh +++ b/lib/rvm.zsh @@ -1,7 +1,8 @@ -# get the name of the branch we are on +# Get the name of the current branch. function rvm_prompt_info() { - ruby_version=$(~/.rvm/bin/rvm-prompt 2> /dev/null) || return - echo "($ruby_version)" + local ruby_version=$(~/.rvm/bin/rvm-prompt 2> /dev/null) + if [[ -n "$ruby_version" ]]; then + echo "($ruby_version)" + fi } - diff --git a/lib/spectrum.zsh b/lib/spectrum.zsh index 4006a7fe1..43a013d78 100644 --- a/lib/spectrum.zsh +++ b/lib/spectrum.zsh @@ -1,20 +1,20 @@ -#! /bin/zsh -# A script to make using 256 colors in zsh less painful. +# A script to make using 256 colors in ZSH less painful. # P.C. Shyamshankar # Copied from http://github.com/sykora/etc/blob/master/zsh/functions/spectrum/ typeset -Ag FX FG BG FX=( - reset "%{%}" - bold "%{%}" no-bold "%{%}" - italic "%{%}" no-italic "%{%}" - underline "%{%}" no-underline "%{%}" - blink "%{%}" no-blink "%{%}" - reverse "%{%}" no-reverse "%{%}" + reset "%{%}" + bold "%{%}" no-bold "%{%}" + italic "%{%}" no-italic "%{%}" + underline "%{%}" no-underline "%{%}" + blink "%{%}" no-blink "%{%}" + reverse "%{%}" no-reverse "%{%}" ) for color in {000..255}; do - FG[$color]="%{[38;5;${color}m%}" - BG[$color]="%{[48;5;${color}m%}" + FG[$color]="%{[38;5;${color}m%}" + BG[$color]="%{[48;5;${color}m%}" done + diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index 9a5765709..5c1c812d1 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -1,31 +1,40 @@ -[[ "$TERM" == "dumb" ]] && return +# Dumb terminals lack support. +if [[ "$TERM" == 'dumb' ]]; then + return +fi -#usage: title short_tab_title looooooooooooooooooooooggggggg_windows_title -#http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1 -#Fully support screen, iterm, and probably most modern xterm and rxvt -#Limited support for Apple Terminal (Terminal can't set window or tab separately) +# Fully supports GNU Screen, iTerm, and most modern xterm and rxvt terminals. +# Partially supports Mac OS X Terminal since it can't set window and tab separately. +# Usage: title "tab title" "window title" function title { - [ "$DISABLE_AUTO_TITLE" != "true" ] || return - if [[ "$TERM" == screen* ]]; then - print -Pn "\ek$1:q\e\\" #set screen hardstatus, usually truncated at 20 chars - elif [[ "$TERM" == xterm* ]] || [[ $TERM == rxvt* ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then - print -Pn "\e]2;$2:q\a" #set window name - print -Pn "\e]1;$1:q\a" #set icon (=tab) name (will override window name on broken terminal) + if [[ "$DISABLE_AUTO_TITLE" != 'true' ]]; then + if [[ "$TERM" == screen* ]]; then + # Set GNU Screen's hardstatus (usually truncated at 20 characters). + print -Pn "\ek$1:q\e\\" + elif [[ "$TERM" == xterm* ]] || [[ "$TERM" == rxvt* ]]; then + # Set the window title. + print -Pn "\e]2;$2:q\a" + # Set the tab title (will override window title on a broken terminal). + print -Pn "\e]1;$1:q\a" + fi fi } -ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD +# 15 character, left-truncated current working directory. +ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~" -#Appears when you have the prompt +# Set the tab and window titles before the prompt is displayed. function precmd { - title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE + title "$ZSH_THEME_TERM_TAB_TITLE_IDLE" "$ZSH_THEME_TERM_TITLE_IDLE" } -#Appears at the beginning of (and during) of command execution +# Set the tab and window titles before command execution. function preexec { emulate -L zsh setopt extended_glob - local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd + # Command name only, or if this is sudo or ssh, the next command. + local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]} title "$CMD" "%100>...>$2%<<" } + diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index ab5aba4da..2596013b6 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -1,35 +1,23 @@ -# ls colors -autoload colors; colors; -[[ -z "$LSCOLORS" ]] && export LSCOLORS="Gxfxcxdxbxegedabagacad" +# Load and run colors. +autoload -U colors +colors -i -# Enable ls colors -if [ "$DISABLE_COLOR" != "true" ] -then - # Find the option for using colors in ls, depending on the version: Linux or BSD - ls --color -d . &>/dev/null 2>&1 && alias ls='ls --color=tty' || alias ls='ls -G' -fi - -#setopt no_beep -setopt auto_cd -setopt multios -setopt cdablevarS - -if [[ x$WINDOW != x ]] -then - SCREEN_NO="%B$WINDOW%b " +# Set the GNU Screen window number. +if [[ -n "$WINDOW" ]]; then + SCREEN_NO="%B$WINDOW%b " else - SCREEN_NO="" + SCREEN_NO="" fi -# Apply theming defaults +# Set the default prompt theme. PS1="%n@%m:%~%# " -# git theming default: Variables for theming the git info prompt -ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Prefix at the very beginning of the prompt, before the branch name -ZSH_THEME_GIT_PROMPT_SUFFIX=")" # At the very end of the prompt -ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty -ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean +# Set the default Git prompt theme. +ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Prefix before the branch name. +ZSH_THEME_GIT_PROMPT_SUFFIX=")" # Suffix after the branch name. +ZSH_THEME_GIT_PROMPT_DIRTY="*" # Indicator to display if the branch is dirty. +ZSH_THEME_GIT_PROMPT_CLEAN="" # Indicator to display if the branch is clean. -# Setup the prompt with pretty colors +# Enable parameter, arithmentic expansion and command substitution in prompt. setopt prompt_subst diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index b0b7d395e..e67c2df69 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -1,45 +1,45 @@ -# Initializes Oh My Zsh +# Initializes OH MY ZSH. -# Disable colors on dumb terminals -if [ "$TERM" = "dumb" ]; then - DISABLE_COLOR="true" +# Disable color in dumb terminals. +if [[ "$TERM" == 'dumb' ]]; then + DISABLE_COLOR='true' fi -# Load all of the config files in ~/oh-my-zsh that end in .zsh -# TIP: Add files you don't want in git to .gitignore -for config_file ($ZSH/lib/*.zsh) source $config_file +# Load all files in $ZSH/oh-my-zsh/lib/ that end in .zsh. +for config_file in $ZSH/lib/*.zsh; do + source "$config_file" +done -# Add all defined plugins to fpath +# Add all defined plugins to fpath. plugin=${plugin:=()} -for plugin ($plugins) fpath=($ZSH/plugins/$plugin $fpath) +for plugin in $plugins; do + fpath=($ZSH/plugins/$plugin $fpath) +done -# Load and run compinit +# Load and run compinit. autoload -U compinit compinit -i -# Load all of the plugins that were defined in ~/.zshrc -for plugin ($plugins); do - if [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then - source $ZSH/plugins/$plugin/$plugin.plugin.zsh +# Load all plugins defined in ~/.zshrc. +for plugin in $plugins; do + if [[ -f "$ZSH/plugins/$plugin/$plugin.plugin.zsh" ]]; then + source "$ZSH/plugins/$plugin/$plugin.plugin.zsh" fi done -# Load the theme -# Check for updates on initial load... -if [ "$ZSH_THEME" = "random" ] -then - themes=($ZSH/themes/*zsh-theme) - N=${#themes[@]} - ((N=(RANDOM%N)+1)) - RANDOM_THEME=${themes[$N]} - source "$RANDOM_THEME" - echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..." +# Load the theme. +if [[ "$ZSH_THEME" == "random" ]]; then + themes=($ZSH/themes/*.zsh-theme) + theme_index=${#themes[@]} + (( theme_index=((RANDOM % theme_index) + 1) )) + random_theme="${themes[$theme_index]}" + source "$random_theme" else source "$ZSH/themes/$ZSH_THEME.zsh-theme" fi # Compile zcompdump, if modified, to increase startup speed. -if [ "$HOME/.zcompdump" -nt "$HOME/.zcompdump.zwc" -o ! -e "$HOME/.zcompdump.zwc" ]; then +if [[ "$HOME/.zcompdump" -nt "$HOME/.zcompdump.zwc" ]] || [[ ! -e "$HOME/.zcompdump.zwc" ]]; then zcompile "$HOME/.zcompdump" fi diff --git a/plugins/compleat/compleat.plugin.zsh b/plugins/compleat/compleat.plugin.zsh index 38f1b396a..7fbd2b953 100644 --- a/plugins/compleat/compleat.plugin.zsh +++ b/plugins/compleat/compleat.plugin.zsh @@ -7,7 +7,7 @@ if (( ${+commands[compleat]} )); then local prefix="${commands[compleat]:h:h}" - local setup="${prefix}/share/compleat-1.0/compleat_setup" + local setup="${prefix}/share/compleat-1.0/compleat_setup" if [[ -f "$setup" ]]; then if ! bashcompinit >/dev/null 2>&1; then @@ -15,6 +15,6 @@ if (( ${+commands[compleat]} )); then bashcompinit -i fi - source "$setup" + source "$setup" fi fi diff --git a/plugins/dirpersist/dirpersist.plugin.zsh b/plugins/dirpersist/dirpersist.plugin.zsh index 6a2b289a2..baf21b1da 100644 --- a/plugins/dirpersist/dirpersist.plugin.zsh +++ b/plugins/dirpersist/dirpersist.plugin.zsh @@ -1,9 +1,9 @@ #!/bin/zsh -# +# # Make the dirstack more persistant -# +# # Add dirpersist to $plugins in ~/.zshrc to load -# +# # $zdirstore is the file used to persist the stack zdirstore=~/.zdirstore diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh index d2b28ad1a..aa55234ad 100644 --- a/plugins/extract/extract.plugin.zsh +++ b/plugins/extract/extract.plugin.zsh @@ -23,7 +23,7 @@ function extract() { remove_archive=1 if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then - remove_archive=0 + remove_archive=0 shift fi @@ -64,10 +64,10 @@ function extract() { cd ..; rm *.tar.gz debian-binary cd .. ;; - (*) + (*) echo "extract: '$1' cannot be extracted" 1>&2 - success=1 - ;; + success=1 + ;; esac (( success = $success > 0 ? $success : $? )) diff --git a/plugins/git-flow/git-flow.plugin.zsh b/plugins/git-flow/git-flow.plugin.zsh index 270bcbe38..a889473e8 100644 --- a/plugins/git-flow/git-flow.plugin.zsh +++ b/plugins/git-flow/git-flow.plugin.zsh @@ -329,4 +329,4 @@ __git_command_successful () { return 0 } -zstyle ':completion:*:*:git:*' user-commands flow:'description for foo' \ No newline at end of file +zstyle ':completion:*:*:git:*' user-commands flow:'description for foo' diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index bc340e86b..6f0ce28c0 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -1,4 +1,3 @@ -# Aliases alias g='git' compdef g=git alias gst='git status' @@ -27,24 +26,12 @@ alias gcp='git cherry-pick' compdef _git gcp=git-cherry-pick alias glg='git log --stat --max-count=5' compdef _git glg=git-log - -# Git and svn mix alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk' compdef git-svn-dcommit-push=git - -# -# Will return the current branch name -# Usage example: git pull origin $(current_branch) -# -function current_branch() { - ref=$(git symbolic-ref HEAD 2> /dev/null) || return - echo ${ref#refs/heads/} -} - -# these aliases take advantage of the previous function -alias ggpull='git pull origin $(current_branch)' +alias ggpull='git pull origin $(git_current_branch)' compdef ggpull=git -alias ggpush='git push origin $(current_branch)' +alias ggpush='git push origin $(git_current_branch)' compdef ggpush=git -alias ggpnp='git pull origin $(current_branch) && git push origin $(current_branch)' +alias ggpnp='git pull origin $(git_current_branch) && git push origin $(git_current_branch)' compdef ggpnp=git + diff --git a/plugins/gnu-utils/gnu-utils.plugin.zsh b/plugins/gnu-utils/gnu-utils.plugin.zsh index e59265d66..28317ff99 100644 --- a/plugins/gnu-utils/gnu-utils.plugin.zsh +++ b/plugins/gnu-utils/gnu-utils.plugin.zsh @@ -6,7 +6,7 @@ # ------------------------------------------------------------------------------ -if [[ -x "${commands[gwhoami]}" ]]; then +if [[ -x "${commands[gwhoami]}" ]]; then __gnu_utils() { emulate -L zsh local gcmds @@ -14,7 +14,7 @@ if [[ -x "${commands[gwhoami]}" ]]; then local cmd local prefix - # coreutils + # coreutils gcmds=('g[' 'gbase64' 'gbasename' 'gcat' 'gchcon' 'gchgrp' 'gchmod' 'gchown' 'gchroot' 'gcksum' 'gcomm' 'gcp' 'gcsplit' 'gcut' 'gdate' 'gdd' 'gdf' 'gdir' 'gdircolors' 'gdirname' 'gdu' 'gecho' 'genv' 'gexpand' @@ -35,7 +35,7 @@ if [[ -x "${commands[gwhoami]}" ]]; then for gcmd in "${gcmds[@]}"; do # # This method allows for builtin commands to be primary but it's - # lost if hash -r or rehash -f is executed. Thus, those two + # lost if hash -r or rehash -f is executed. Thus, those two # functions have to be wrapped. # (( ${+commands[$gcmd]} )) && hash ${gcmd[2,-1]}=${commands[$gcmd]} diff --git a/plugins/macports/_port b/plugins/macports/_port index 06d7fb426..c4de6eabb 100644 --- a/plugins/macports/_port +++ b/plugins/macports/_port @@ -1,6 +1,6 @@ #compdef port -local subcmds +local subcmds # we cache the list of ports # we shall use some cache policy to avoid problems with new ports @@ -31,8 +31,8 @@ subcmds=( 'file' 'help' 'info' -'install' -'installed' +'install' +'installed' 'list' 'livecheck' 'location' @@ -48,7 +48,7 @@ subcmds=( 'test' 'unarchive' 'uninstall' -'upgrade' +'upgrade' 'variants' 'version' ) diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index 62f7ccd75..682bb2667 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -44,7 +44,7 @@ EOF } function pfd() { - osascript 2>/dev/null </dev/null </dev/null </dev/null </dev/null) - if [ $s ]; then + if [ $s ]; then echo $1 - else + else echo $2 fi fi @@ -39,4 +39,4 @@ function svn_dirty_choose { function svn_dirty { svn_dirty_choose $ZSH_THEME_SVN_PROMPT_DIRTY $ZSH_THEME_SVN_PROMPT_CLEAN -} \ No newline at end of file +} diff --git a/plugins/vagrant/_vagrant b/plugins/vagrant/_vagrant index 483b29c53..2e76d2ec2 100644 --- a/plugins/vagrant/_vagrant +++ b/plugins/vagrant/_vagrant @@ -1,4 +1,4 @@ -#compdef vagrant +#compdef vagrant #autoload # vagrant zsh completion @@ -64,7 +64,7 @@ __vagrant-box () (options) case $line[1] in (repackage|remove) - _arguments ':feature:__box_list' + _arguments ':feature:__box_list' ;; esac ;; @@ -93,7 +93,7 @@ case $state in (options) case $line[1] in (help) - _arguments ':feature:__task_list' + _arguments ':feature:__task_list' ;; (box) diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index 019fc1d7b..f9d50d2eb 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -52,7 +52,7 @@ bindkey -v # Use vi key bindings. bindkey -M vicmd "^M" accept_line # Alow RETURN in vi command. bindkey -M vicmd v edit-command-line # ESC-v to edit in an external editor. -bindkey ' ' magic-space +bindkey ' ' magic-space bindkey -M vicmd "gg" beginning-of-history bindkey -M vicmd "G" end-of-history diff --git a/templates/zshrc.zsh-template b/templates/zshrc.zsh-template index c2accfc87..6746feb28 100644 --- a/templates/zshrc.zsh-template +++ b/templates/zshrc.zsh-template @@ -1,25 +1,24 @@ -# Path to your oh-my-zsh configuration. -export ZSH=$HOME/.oh-my-zsh +# Path to oh-my-zsh. +export ZSH="$HOME/.oh-my-zsh" -# Set name of the theme to load. -# Look in ~/.oh-my-zsh/themes/ -# Optionally, if you set this to "random", it'll load a random theme each -# time that oh-my-zsh is loaded. +# Set the name of the theme to load (see $ZSH/themes/). +# Setting it to 'random' loads a random theme. export ZSH_THEME="robbyrussell" -# Set to this to use case-sensitive completion -# export CASE_SENSITIVE="true" +# Set to 'true' to enable case-sensitivity. +export CASE_SENSITIVE='false' -# Uncomment following line if you want to disable colors in ls -# export DISABLE_COLOR="true" +# Set to 'true' to disable color (auto set on dumb terminals). +export DISABLE_COLOR='false' -# Uncomment following line if you want to disable autosetting terminal title. -# export DISABLE_AUTO_TITLE="true" +# Set to 'true' to disable auto setting the tab and window titles. +export DISABLE_AUTO_TITLE='false' -# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*) -# Example format: plugins=(rails git textmate ruby lighthouse) +# Set the plugins to load (see $ZSH/plugins/). +# Example: plugins=(rails git textmate ruby lighthouse) plugins=(git) -source $ZSH/oh-my-zsh.sh +source "$ZSH/oh-my-zsh.sh" # Customize to your needs... + diff --git a/themes/Soliah.zsh-theme b/themes/Soliah.zsh-theme index 237e70fda..e0932c4b5 100644 --- a/themes/Soliah.zsh-theme +++ b/themes/Soliah.zsh-theme @@ -5,10 +5,10 @@ ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[white]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%})" # Text to display if the branch is dirty -ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}" # Text to display if the branch is clean -ZSH_THEME_GIT_PROMPT_CLEAN="" +ZSH_THEME_GIT_PROMPT_CLEAN="" # Colors vary depending on time lapsed. ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}" @@ -35,7 +35,7 @@ function rvm_gemset() { GEMSET=`rvm gemset list | grep '=>' | cut -b4-` if [[ -n $GEMSET ]]; then echo "%{$fg[yellow]%}$GEMSET%{$reset_color%}|" - fi + fi } @@ -53,12 +53,12 @@ function git_time_since_commit() { # Totals MINUTES=$((seconds_since_last_commit / 60)) HOURS=$((seconds_since_last_commit/3600)) - + # Sub-hours and sub-minutes DAYS=$((seconds_since_last_commit / 86400)) SUB_HOURS=$((HOURS % 24)) SUB_MINUTES=$((MINUTES % 60)) - + if [[ -n $(git status -s 2> /dev/null) ]]; then if [ "$MINUTES" -gt 30 ]; then COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG" diff --git a/themes/awesomepanda.zsh-theme b/themes/awesomepanda.zsh-theme index 411b89837..1915bd13c 100644 --- a/themes/awesomepanda.zsh-theme +++ b/themes/awesomepanda.zsh-theme @@ -15,4 +15,4 @@ ZSH_THEME_REPO_NAME_COLOR="%{$fg_bold[red]%}" ZSH_THEME_SVN_PROMPT_PREFIX="svn:(" ZSH_THEME_SVN_PROMPT_SUFFIX=")" ZSH_THEME_SVN_PROMPT_DIRTY="%{$fg[red]%} ✘ %{$reset_color%}" -ZSH_THEME_SVN_PROMPT_CLEAN=" " \ No newline at end of file +ZSH_THEME_SVN_PROMPT_CLEAN=" " diff --git a/themes/cloud.zsh-theme b/themes/cloud.zsh-theme index ad5e2834b..4e94f61a7 100644 --- a/themes/cloud.zsh-theme +++ b/themes/cloud.zsh-theme @@ -3,4 +3,4 @@ PROMPT='%{$fg_bold[cyan]%}☁ %{$fg_bold[green]%}%p %{$fg[green]%}%c %{$fg_bold[ ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}[%{$fg[cyan]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[green]%}] %{$fg[yellow]%}⚡%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%}]" \ No newline at end of file +ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%}]" diff --git a/themes/eastwood.zsh-theme b/themes/eastwood.zsh-theme index 83664515a..8f15f367f 100644 --- a/themes/eastwood.zsh-theme +++ b/themes/eastwood.zsh-theme @@ -1,5 +1,5 @@ #RVM settings -if [[ -s ~/.rvm/scripts/rvm ]] ; then +if [[ -s ~/.rvm/scripts/rvm ]] ; then RPS1="%{$fg[yellow]%}rvm:%{$reset_color%}%{$fg[red]%}\$(~/.rvm/bin/rvm-prompt)%{$reset_color%} $EPS1" fi diff --git a/themes/evan.zsh-theme b/themes/evan.zsh-theme index 5ef1f40dd..2ebb27159 100644 --- a/themes/evan.zsh-theme +++ b/themes/evan.zsh-theme @@ -1,2 +1,2 @@ # Evan describes this sexy prompt as: "a skinny, topless prompt" -PROMPT='%m :: %2~ %B»%b ' \ No newline at end of file +PROMPT='%m :: %2~ %B»%b ' diff --git a/themes/example.zsh-theme b/themes/example.zsh-theme index dbd9dc9c9..4ad3b7cae 100644 --- a/themes/example.zsh-theme +++ b/themes/example.zsh-theme @@ -2,4 +2,4 @@ # http://zshwiki.org/home/config/prompt # -PROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%~ %{$reset_color%}%% " \ No newline at end of file +PROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%~ %{$reset_color%}%% " diff --git a/themes/funky.zsh-theme b/themes/funky.zsh-theme index 2451296d9..503455485 100644 --- a/themes/funky.zsh-theme +++ b/themes/funky.zsh-theme @@ -11,4 +11,4 @@ local smiley="%(?,%{$fg[green]%}:%)%{$reset_color%},%{$fg[red]%}:(%{$reset_color PROMPT="╭─${path_p}─${user_host}─${ret_status}─${hist_no} ╰─${blue_op}${smiley}${blue_cp} %# " local cur_cmd="${blue_op}%_${blue_cp}" -PROMPT2="${cur_cmd}> " \ No newline at end of file +PROMPT2="${cur_cmd}> " diff --git a/themes/gallois.zsh-theme b/themes/gallois.zsh-theme index 259640ba4..be8fe0999 100644 --- a/themes/gallois.zsh-theme +++ b/themes/gallois.zsh-theme @@ -12,7 +12,7 @@ git_custom_status() { } #RVM and git settings -if [[ -s ~/.rvm/scripts/rvm ]] ; then +if [[ -s ~/.rvm/scripts/rvm ]] ; then RPS1='$(git_custom_status)%{$fg[red]%}[`~/.rvm/bin/rvm-prompt`]%{$reset_color%} $EPS1' fi diff --git a/themes/imajes.zsh-theme b/themes/imajes.zsh-theme index 88c35b6d9..918cd8081 100644 --- a/themes/imajes.zsh-theme +++ b/themes/imajes.zsh-theme @@ -2,4 +2,4 @@ # http://zshwiki.org/home/config/prompt # -PROMPT="%{$fg[red]%}%%%{$reset_color%} " \ No newline at end of file +PROMPT="%{$fg[red]%}%%%{$reset_color%} " diff --git a/themes/jonathan.zsh-theme b/themes/jonathan.zsh-theme index add485279..79d0d21ff 100644 --- a/themes/jonathan.zsh-theme +++ b/themes/jonathan.zsh-theme @@ -5,15 +5,15 @@ function precmd { ### # Truncate the path if it's too long. - + PR_FILLBAR="" PR_PWDLEN="" - + local promptsize=${#${(%):---(%n@%m:%l)---()--}} local rubyprompt=`rvm_prompt_info` local rubypromptsize=${#${rubyprompt}} local pwdsize=${#${(%):-%~}} - + if [[ "$promptsize + $rubypromptsize + $pwdsize" -gt $TERMWIDTH ]]; then ((PR_PWDLEN=$TERMWIDTH - $promptsize)) else @@ -69,7 +69,7 @@ setprompt () { ### # See if we can use extended characters to look nicer. - + typeset -A altchar set -A altchar ${(s..)terminfo[acsc]} PR_SET_CHARSET="%{$terminfo[enacs]%}" @@ -81,10 +81,10 @@ setprompt () { PR_LRCORNER=${altchar[j]:--} PR_URCORNER=${altchar[k]:--} - + ### # Decide if we need to set titlebar text. - + case $TERM in xterm*) PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}' @@ -96,8 +96,8 @@ setprompt () { PR_TITLEBAR='' ;; esac - - + + ### # Decide whether to set a screen title if [[ "$TERM" == "screen" ]]; then @@ -105,8 +105,8 @@ setprompt () { else PR_STITLE='' fi - - + + ### # Finally, the prompt. diff --git a/themes/josh.zsh-theme b/themes/josh.zsh-theme index 6bed1a70e..d6c64da8e 100644 --- a/themes/josh.zsh-theme +++ b/themes/josh.zsh-theme @@ -15,7 +15,7 @@ function josh_prompt { branch_size=${#branch} ruby_size=${#ruby_version} user_machine_size=${#${(%):-%n@%m-}} - + if [[ ${#branch} -eq 0 ]] then (( ruby_size = ruby_size + 1 )) else @@ -24,15 +24,15 @@ function josh_prompt { (( branch_size = branch_size + 2 )) fi fi - + (( spare_width = ${spare_width} - (${user_machine_size} + ${path_size} + ${branch_size} + ${ruby_size}) )) while [ ${#prompt} -lt $spare_width ]; do prompt=" $prompt" done - + prompt="%{%F{green}%}$PWD$prompt%{%F{red}%}$(rvm_prompt_info)%{$reset_color%} $(git_prompt_info)" - + echo $prompt } diff --git a/themes/juanghurtado.zsh-theme b/themes/juanghurtado.zsh-theme index 2f715cc9e..3ca50cee8 100644 --- a/themes/juanghurtado.zsh-theme +++ b/themes/juanghurtado.zsh-theme @@ -43,4 +43,4 @@ ZSH_THEME_GIT_PROMPT_SHA_AFTER="%{$WHITE%}]" PROMPT=' %{$GREEN_BOLD%}%n@%m%{$WHITE%}:%{$YELLOW%}%~%u$(parse_git_dirty)$(git_prompt_ahead)%{$RESET_COLOR%} %{$BLUE%}>%{$RESET_COLOR%} ' -RPROMPT='%{$GREEN_BOLD%}$(current_branch)$(git_prompt_short_sha)$(git_prompt_status)%{$RESET_COLOR%}' \ No newline at end of file +RPROMPT='%{$GREEN_BOLD%}$(current_branch)$(git_prompt_short_sha)$(git_prompt_status)%{$RESET_COLOR%}' diff --git a/themes/kardan.zsh-theme b/themes/kardan.zsh-theme index fd6586a9d..59c938037 100644 --- a/themes/kardan.zsh-theme +++ b/themes/kardan.zsh-theme @@ -9,4 +9,4 @@ RPROMPT='%~$(git_prompt_info)$(get_host)' ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[yellow]%}✗%{$reset_color%}" ZSH_THEME_GIT_PROMPT_PREFIX="(" -ZSH_THEME_GIT_PROMPT_SUFFIX=")" \ No newline at end of file +ZSH_THEME_GIT_PROMPT_SUFFIX=")" diff --git a/themes/linuxonly b/themes/linuxonly index a11b80d7f..335b2c4a7 100644 --- a/themes/linuxonly +++ b/themes/linuxonly @@ -47,7 +47,7 @@ prompt_jnrowe_precmd () { #dir_status="$c1%n%F{7}@%F{9}%m%F{7}:%F{12}%/" dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$c4%}%/ %{$c0%}(%{$c5%}%?%{$c0%})" #dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$foopath%} %{$c0%}(%{$c5%}%?%{$c0%})" - + PROMPT='%{$fg_bold[green]%}%p%{$reset_color%}${vcs_info_msg_0_}${dir_status} ${ret_status}%{$reset_color%} > ' elif [[ $(git diff --cached --name-status 2>/dev/null ) != "" ]]; then @@ -55,7 +55,7 @@ prompt_jnrowe_precmd () { PROMPT='${vcs_info_msg_0_} %{$fg_bold[green]%}%p%{$reset_color%}${dir_status} ${vcs_info_msg_0_}%{$reset_color%} > ' - + elif [[ $(git diff --name-status 2>/dev/null ) != "" ]]; then dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$c4%}%/ %{$c0%}(%{$c5%}%?%{$c0%})" @@ -67,7 +67,7 @@ prompt_jnrowe_precmd () { PROMPT='${vcs_info_msg_0_} %{$fg_bold[green]%}%p%{$reset_color%}${dir_status} ${vcs_info_msg_0_}%{$reset_color%} > ' - + fi } diff --git a/themes/mikeh.zsh-theme b/themes/mikeh.zsh-theme index 943f04d38..e611b6832 100644 --- a/themes/mikeh.zsh-theme +++ b/themes/mikeh.zsh-theme @@ -20,4 +20,4 @@ mikeh_precmd() { # entry in a nice long thread on the Arch Linux forums: http://bbs.archlinux.org/viewtopic.php?pid=521888#p521888 PROMPT=$'%{\e[0;34m%}%B..[%b%{\e[0m%}%{\e[1;32m%}%n%{\e[1;30m%}@%{\e[0m%}%{\e[0;36m%}%m%{\e[0;34m%}%B]%b%{\e[0m%} - %b%{\e[0;34m%}%B[%b%{\e[1;37m%}%~%{\e[0;34m%}%B]%b%{\e[0m%} - %{\e[0;34m%}%B[%b%{\e[0;33m%}'%D{"%a %b %d, %I:%M"}%b$'%{\e[0;34m%}%B]%b%{\e[0m%} %{\e[0;34m%}%B..%B[%{\e[1;35m%}$%{\e[0;34m%}%B] <($vcs_info_msg_0_)>%{\e[0m%}%b ' -PS2=$' \e[0;34m%}%B>%{\e[0m%}%b ' \ No newline at end of file +PS2=$' \e[0;34m%}%B>%{\e[0m%}%b ' diff --git a/themes/minimal.zsh-theme b/themes/minimal.zsh-theme index ee3ab6b22..d3c9e3663 100644 --- a/themes/minimal.zsh-theme +++ b/themes/minimal.zsh-theme @@ -12,4 +12,4 @@ git_custom_status() { } -PROMPT='%2~ $(git_custom_status) »%b ' \ No newline at end of file +PROMPT='%2~ $(git_custom_status) »%b ' diff --git a/themes/rixius.zsh-theme b/themes/rixius.zsh-theme index c0c5c9c71..7e7c9c633 100644 --- a/themes/rixius.zsh-theme +++ b/themes/rixius.zsh-theme @@ -1,6 +1,6 @@ # /|/ Code by Stephen # /|/ "Rixius" Middleton -# +# # name in folder (github) # ± if in github repo, or ≥ if otherwise Time in 24-hour format is on right. function collapse_pwd { diff --git a/themes/sorin.zsh-theme b/themes/sorin.zsh-theme index 33ca9c1e2..a63a98441 100644 --- a/themes/sorin.zsh-theme +++ b/themes/sorin.zsh-theme @@ -10,7 +10,7 @@ if [[ "$DISABLE_COLOR" != "true" ]]; then MODE_INDICATOR="%{$fg_bold[red]%}❮%{$reset_color%}%{$fg[red]%}❮❮%{$reset_color%}" local return_status="%{$fg[red]%}%(?..⏎)%{$reset_color%}" - + PROMPT='%{$fg[cyan]%}%c$(git_prompt_info) %(!.%{$fg_bold[red]%}#.%{$fg_bold[green]%}❯)%{$reset_color%} ' ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[blue]%}git%{$reset_color%}:%{$fg[red]%}" @@ -26,10 +26,10 @@ if [[ "$DISABLE_COLOR" != "true" ]]; then ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[magenta]%} ➜" ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[yellow]%} ═" ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%} ✭" -else +else MODE_INDICATOR="❮❮❮" local return_status="%(?::⏎)" - + PROMPT='%c$(git_prompt_info) %(!.#.❯) ' ZSH_THEME_GIT_PROMPT_PREFIX=" git:" diff --git a/themes/theunraveler.zsh-theme b/themes/theunraveler.zsh-theme index e4bfb79c5..a896970df 100644 --- a/themes/theunraveler.zsh-theme +++ b/themes/theunraveler.zsh-theme @@ -13,4 +13,4 @@ ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[yellow]%} ✭" ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%} ✗" ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[blue]%} ➦" ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[magenta]%} ✂" -ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[grey]%} ✱" \ No newline at end of file +ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[grey]%} ✱" diff --git a/themes/tonotdo.zsh-theme b/themes/tonotdo.zsh-theme index a6407034c..52670e8a5 100644 --- a/themes/tonotdo.zsh-theme +++ b/themes/tonotdo.zsh-theme @@ -9,4 +9,4 @@ ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg_bold[yellow]%}✗%{$fg_bold[blue]%})" # LS colors, made with http://geoff.greer.fm/lscolors/ export LSCOLORS="Gxfxcxdxbxegedabagacad" -export LS_COLORS='no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.avi=01;35:*.bmp=01;35:*.fli=01;35:*.gif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mng=01;35:*.mov=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.tga=01;35:*.tif=01;35:*.xbm=01;35:*.xpm=01;35:*.dl=01;35:*.gl=01;35:*.wmv=01;35:*.aiff=00;32:*.au=00;32:*.mid=00;32:*.mp3=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:' \ No newline at end of file +export LS_COLORS='no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.avi=01;35:*.bmp=01;35:*.fli=01;35:*.gif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mng=01;35:*.mov=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.tga=01;35:*.tif=01;35:*.xbm=01;35:*.xpm=01;35:*.dl=01;35:*.gl=01;35:*.wmv=01;35:*.aiff=00;32:*.au=00;32:*.mid=00;32:*.mp3=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:' From 3df2fe787e9317bf4f4fba72b8de042890a64386 Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Wed, 1 Jun 2011 14:14:20 -0400 Subject: [PATCH 49/64] Merged /lib/git.zsh and /lib/rvm.zsh into /plugins/. --- lib/git.zsh | 80 -------------------------------------- lib/rvm.zsh | 8 ---- plugins/git/git.plugin.zsh | 80 ++++++++++++++++++++++++++++++++++++++ plugins/rvm/rvm.plugin.zsh | 9 +++++ 4 files changed, 89 insertions(+), 88 deletions(-) delete mode 100644 lib/git.zsh delete mode 100644 lib/rvm.zsh diff --git a/lib/git.zsh b/lib/git.zsh deleted file mode 100644 index bb7f05381..000000000 --- a/lib/git.zsh +++ /dev/null @@ -1,80 +0,0 @@ -# Renders the name of the current branch. -function git_prompt_info() { - local branch=$(git_current_branch) - if [[ -n "$branch" ]]; then - echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${branch}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}" - fi -} - -# Gets the current branch. -function git_current_branch() { - local ref=$(git symbolic-ref HEAD 2> /dev/null) - if [[ -n "$ref" ]]; then - echo "${ref#refs/heads/}" - fi -} - -# Checks if the working tree is dirty. -function parse_git_dirty() { - if [[ -n $(git status -s 2> /dev/null) ]]; then - echo "$ZSH_THEME_GIT_PROMPT_DIRTY" - else - echo "$ZSH_THEME_GIT_PROMPT_CLEAN" - fi -} - -# Checks if there are commits ahead from remote. -function git_prompt_ahead() { - if $(echo "$(git log origin/$(git_current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then - echo "$ZSH_THEME_GIT_PROMPT_AHEAD" - fi -} - -# Formats the prompt string for current git commit short SHA. -function git_prompt_short_sha() { - local sha=$(git rev-parse --short HEAD 2> /dev/null) - if [[ -n "$sha" ]]; then - echo "${ZSH_THEME_GIT_PROMPT_SHA_BEFORE}${sha}${ZSH_THEME_GIT_PROMPT_SHA_AFTER}" - fi -} - -# Formats the prompt string for current git commit long SHA. -function git_prompt_long_sha() { - local sha=$(git rev-parse HEAD 2> /dev/null) - if [[ -n "$sha" ]]; then - echo "${ZSH_THEME_GIT_PROMPT_SHA_BEFORE}${sha}${ZSH_THEME_GIT_PROMPT_SHA_AFTER}" - fi -} - -# Gets the status of the working tree. -function git_prompt_status() { - local indicators line untracked added modified renamed deleted - while IFS=$'\n' read line; do - if [[ "$line" =~ '^\?\? ' ]]; then - [[ -n $untracked ]] && continue || untracked='yes' - indicators="${ZSH_THEME_GIT_PROMPT_UNTRACKED}${indicators}" - fi - if [[ "$line" =~ '^(((A|M|D|T) )|(AD|AM|AT|MM)) ' ]]; then - [[ -n $added ]] && continue || added='yes' - indicators="${ZSH_THEME_GIT_PROMPT_ADDED}${indicators}" - fi - if [[ "$line" =~ '^(( (M|T))|(AM|AT|MM)) ' ]]; then - [[ -n $modified ]] && continue || modified='yes' - indicators="${ZSH_THEME_GIT_PROMPT_MODIFIED}${indicators}" - fi - if [[ "$line" =~ '^R ' ]]; then - [[ -n $renamed ]] && continue || renamed='yes' - indicators="${ZSH_THEME_GIT_PROMPT_RENAMED}${indicators}" - fi - if [[ "$line" =~ '^( D|AD) ' ]]; then - [[ -n $deleted ]] && continue || deleted='yes' - indicators="${ZSH_THEME_GIT_PROMPT_DELETED}${indicators}" - fi - if [[ "$line" =~ '^UU ' ]]; then - [[ -n $unmerged ]] && continue || unmerged='yes' - indicators="${ZSH_THEME_GIT_PROMPT_UNMERGED}${indicators}" - fi - done < <(git status --porcelain 2> /dev/null) - echo $indicators -} - diff --git a/lib/rvm.zsh b/lib/rvm.zsh deleted file mode 100644 index 25ba36b7d..000000000 --- a/lib/rvm.zsh +++ /dev/null @@ -1,8 +0,0 @@ -# Get the name of the current branch. -function rvm_prompt_info() { - local ruby_version=$(~/.rvm/bin/rvm-prompt 2> /dev/null) - if [[ -n "$ruby_version" ]]; then - echo "($ruby_version)" - fi -} - diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 6f0ce28c0..baf34b830 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -1,3 +1,83 @@ +# Renders the name of the current branch. +function git_prompt_info() { + local branch=$(git_current_branch) + if [[ -n "$branch" ]]; then + echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${branch}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}" + fi +} + +# Gets the current branch. +function git_current_branch() { + local ref=$(git symbolic-ref HEAD 2> /dev/null) + if [[ -n "$ref" ]]; then + echo "${ref#refs/heads/}" + fi +} + +# Checks if the working tree is dirty. +function parse_git_dirty() { + if [[ -n $(git status -s 2> /dev/null) ]]; then + echo "$ZSH_THEME_GIT_PROMPT_DIRTY" + else + echo "$ZSH_THEME_GIT_PROMPT_CLEAN" + fi +} + +# Checks if there are commits ahead from remote. +function git_prompt_ahead() { + if $(echo "$(git log origin/$(git_current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then + echo "$ZSH_THEME_GIT_PROMPT_AHEAD" + fi +} + +# Formats the prompt string for current git commit short SHA. +function git_prompt_short_sha() { + local sha=$(git rev-parse --short HEAD 2> /dev/null) + if [[ -n "$sha" ]]; then + echo "${ZSH_THEME_GIT_PROMPT_SHA_BEFORE}${sha}${ZSH_THEME_GIT_PROMPT_SHA_AFTER}" + fi +} + +# Formats the prompt string for current git commit long SHA. +function git_prompt_long_sha() { + local sha=$(git rev-parse HEAD 2> /dev/null) + if [[ -n "$sha" ]]; then + echo "${ZSH_THEME_GIT_PROMPT_SHA_BEFORE}${sha}${ZSH_THEME_GIT_PROMPT_SHA_AFTER}" + fi +} + +# Gets the status of the working tree. +function git_prompt_status() { + local indicators line untracked added modified renamed deleted + while IFS=$'\n' read line; do + if [[ "$line" =~ '^\?\? ' ]]; then + [[ -n $untracked ]] && continue || untracked='yes' + indicators="${ZSH_THEME_GIT_PROMPT_UNTRACKED}${indicators}" + fi + if [[ "$line" =~ '^(((A|M|D|T) )|(AD|AM|AT|MM)) ' ]]; then + [[ -n $added ]] && continue || added='yes' + indicators="${ZSH_THEME_GIT_PROMPT_ADDED}${indicators}" + fi + if [[ "$line" =~ '^(( (M|T))|(AM|AT|MM)) ' ]]; then + [[ -n $modified ]] && continue || modified='yes' + indicators="${ZSH_THEME_GIT_PROMPT_MODIFIED}${indicators}" + fi + if [[ "$line" =~ '^R ' ]]; then + [[ -n $renamed ]] && continue || renamed='yes' + indicators="${ZSH_THEME_GIT_PROMPT_RENAMED}${indicators}" + fi + if [[ "$line" =~ '^( D|AD) ' ]]; then + [[ -n $deleted ]] && continue || deleted='yes' + indicators="${ZSH_THEME_GIT_PROMPT_DELETED}${indicators}" + fi + if [[ "$line" =~ '^UU ' ]]; then + [[ -n $unmerged ]] && continue || unmerged='yes' + indicators="${ZSH_THEME_GIT_PROMPT_UNMERGED}${indicators}" + fi + done < <(git status --porcelain 2> /dev/null) + echo $indicators +} + alias g='git' compdef g=git alias gst='git status' diff --git a/plugins/rvm/rvm.plugin.zsh b/plugins/rvm/rvm.plugin.zsh index c7ec154f4..cda28795a 100644 --- a/plugins/rvm/rvm.plugin.zsh +++ b/plugins/rvm/rvm.plugin.zsh @@ -1,3 +1,11 @@ +# Get the name of the current branch. +function rvm_prompt_info() { + local ruby_version=$(~/.rvm/bin/rvm-prompt 2> /dev/null) + if [[ -n "$ruby_version" ]]; then + echo "($ruby_version)" + fi +} + alias rubies='rvm list rubies' alias gemsets='rvm gemset list' @@ -46,3 +54,4 @@ function gems { -Ee "s/$current_ruby@global/$fg[yellow]&$reset_color/g" \ -Ee "s/$current_ruby$current_gemset$/$fg[green]&$reset_color/g" } + From 384c594abbf847dff8a89fc919d7f9c326a56870 Mon Sep 17 00:00:00 2001 From: Ashley Dev Date: Thu, 2 Jun 2011 11:07:00 -0700 Subject: [PATCH 50/64] Update plugins/git: - move aliases into plugins/git/git-aliases.plugin.zsh - move git prompt info into plugins/git/git-prompt-old.plugin.zsh - add revamped git prompt info into plugins/git/git-prompt.plugin.zsh - plugins/git/git.plugin.zsh now just sources the above files Added themes/ashleydev.theme.zsh that takes advantage of the new git prompt info --- plugins/git/git-aliases.plugin.zsh | 60 +++ plugins/git/git-prompt-old.plugin.zsh | 79 ++++ plugins/git/git-prompt.plugin.zsh | 604 ++++++++++++++++++++++++++ plugins/git/git.plugin.zsh | 120 +---- themes/ashleydev.zsh-theme | 144 ++++++ 5 files changed, 890 insertions(+), 117 deletions(-) create mode 100644 plugins/git/git-aliases.plugin.zsh create mode 100644 plugins/git/git-prompt-old.plugin.zsh create mode 100644 plugins/git/git-prompt.plugin.zsh create mode 100644 themes/ashleydev.zsh-theme diff --git a/plugins/git/git-aliases.plugin.zsh b/plugins/git/git-aliases.plugin.zsh new file mode 100644 index 000000000..859b637c6 --- /dev/null +++ b/plugins/git/git-aliases.plugin.zsh @@ -0,0 +1,60 @@ +# Aliases +alias g='git' ; compdef g=git +alias ga='git add' ; compdef _git ga=git-add +alias gaa='git add --all' ; compdef _git gaa=git-add +alias gs='git status' ; compdef _git gs=git-status +alias gst='git status' ; compdef _git gst=git-status +# for `gsts ""` +alias gsts='git stash save' ; compdef _git gsts=git-stash +alias gstp='git stash pop' ; compdef _git gstp=git-stash +alias gstl='git stash list' ; compdef _git gstl=git-stash +alias gstll='git stash show -p --stat' ; compdef _git gstll=git-stash +alias gl='git pull' ; compdef _git gl=git-pull +alias gup='git fetch && git rebase' ; compdef _git gup=git-fetch +alias gf='git fetch' ; compdef _git gf=git-fetch +alias gp='git push' ; compdef _git gp=git-push +alias gd='git diff --no-ext-diff -b' ; compdef _git gd=git-diff +alias gdd='git diff --no-ext-diff' ; compdef _git gdd=git-diff +gdv() { git-diff -w "$@" | view - } ; compdef _git gdv=git-diff +alias gc='git commit -v' ; compdef _git gc=git-commit +alias gca='git commit -v -a' ; compdef _git gca=git-commit +alias gco='git checkout' ; compdef _git gco=git-checkout +alias gb='git branch' ; compdef _git gb=git-branch +alias gba='git branch -a' ; compdef _git gba=git-branch +alias gcount='git shortlog -sn' ; compdef gcount=git +alias gcp='git cherry-pick' ; compdef _git gcp=git-cherry-pick +alias gm='git merge' ; compdef _git gm=git-merge +alias glg='git log --stat --max-count=5'; compdef _git glg=git-log + +# Git history (pretty) +local pretty_format_oneline='--pretty=format:"%C(yellow)%h %C(green)%cd %C(cyan)%an %C(bold cyan)%d%C(reset) %s" --date=short' +local pretty_format_medium='--pretty=format:"%C(yellow)commit %H %C(bold cyan)%d%C(reset) +%C(cyan)Author: %an <%ae>%C(reset) +%C(green)Date: %cd%C(reset) +%+s +%+b"' +alias gh="git log --graph $pretty_format_oneline" ; compdef _git gh=git-log +alias ghh="git log --graph $pretty_format_medium" ; compdef _git gh=git-log +alias ghhh="git log --graph --stat $pretty_format_medium" ; compdef _git gh=git-log +alias ghhhh="git log --graph --stat -p --full-diff $pretty_format_medium"; compdef _git gh=git-log + +# Git and svn mix +alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk' +compdef _git git-svn-dcommit-push=git + +# +# Will return the current branch name +# Usage example: git pull origin $(current_branch) +# +function current_branch() { + ref=$(git symbolic-ref HEAD 2> /dev/null) || return + echo ${ref#refs/heads/} +} + +# these aliases take advantage of the previous function +alias ggpull='git pull origin $(current_branch)' +compdef _git ggpull=git +alias ggpush='git push origin $(current_branch)' +compdef _git ggpush=git +alias ggpnp='git pull origin $(current_branch) && git push origin $(current_branch)' +compdef _git ggpnp=git diff --git a/plugins/git/git-prompt-old.plugin.zsh b/plugins/git/git-prompt-old.plugin.zsh new file mode 100644 index 000000000..ece86e6d3 --- /dev/null +++ b/plugins/git/git-prompt-old.plugin.zsh @@ -0,0 +1,79 @@ +# Renders the name of the current branch. +function git_prompt_info() { + local branch=$(git_current_branch) + if [[ -n "$branch" ]]; then + echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${branch}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}" + fi +} + +# Gets the current branch. +function git_current_branch() { + local ref=$(git symbolic-ref HEAD 2> /dev/null) + if [[ -n "$ref" ]]; then + echo "${ref#refs/heads/}" + fi +} + +# Checks if the working tree is dirty. +function parse_git_dirty() { + if [[ -n $(git status -s 2> /dev/null) ]]; then + echo "$ZSH_THEME_GIT_PROMPT_DIRTY" + else + echo "$ZSH_THEME_GIT_PROMPT_CLEAN" + fi +} + +# Checks if there are commits ahead from remote. +function git_prompt_ahead() { + if $(echo "$(git log origin/$(git_current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then + echo "$ZSH_THEME_GIT_PROMPT_AHEAD" + fi +} + +# Formats the prompt string for current git commit short SHA. +function git_prompt_short_sha() { + local sha=$(git rev-parse --short HEAD 2> /dev/null) + if [[ -n "$sha" ]]; then + echo "${ZSH_THEME_GIT_PROMPT_SHA_BEFORE}${sha}${ZSH_THEME_GIT_PROMPT_SHA_AFTER}" + fi +} + +# Formats the prompt string for current git commit long SHA. +function git_prompt_long_sha() { + local sha=$(git rev-parse HEAD 2> /dev/null) + if [[ -n "$sha" ]]; then + echo "${ZSH_THEME_GIT_PROMPT_SHA_BEFORE}${sha}${ZSH_THEME_GIT_PROMPT_SHA_AFTER}" + fi +} + +# Gets the status of the working tree. +function git_prompt_status() { + local indicators line untracked added modified renamed deleted + while IFS=$'\n' read line; do + if [[ "$line" =~ '^\?\? ' ]]; then + [[ -n $untracked ]] && continue || untracked='yes' + indicators="${ZSH_THEME_GIT_PROMPT_UNTRACKED}${indicators}" + fi + if [[ "$line" =~ '^(((A|M|D|T) )|(AD|AM|AT|MM)) ' ]]; then + [[ -n $added ]] && continue || added='yes' + indicators="${ZSH_THEME_GIT_PROMPT_ADDED}${indicators}" + fi + if [[ "$line" =~ '^(( (M|T))|(AM|AT|MM)) ' ]]; then + [[ -n $modified ]] && continue || modified='yes' + indicators="${ZSH_THEME_GIT_PROMPT_MODIFIED}${indicators}" + fi + if [[ "$line" =~ '^R ' ]]; then + [[ -n $renamed ]] && continue || renamed='yes' + indicators="${ZSH_THEME_GIT_PROMPT_RENAMED}${indicators}" + fi + if [[ "$line" =~ '^( D|AD) ' ]]; then + [[ -n $deleted ]] && continue || deleted='yes' + indicators="${ZSH_THEME_GIT_PROMPT_DELETED}${indicators}" + fi + if [[ "$line" =~ '^UU ' ]]; then + [[ -n $unmerged ]] && continue || unmerged='yes' + indicators="${ZSH_THEME_GIT_PROMPT_UNMERGED}${indicators}" + fi + done < <(git status --porcelain 2> /dev/null) + echo $indicators +} diff --git a/plugins/git/git-prompt.plugin.zsh b/plugins/git/git-prompt.plugin.zsh new file mode 100644 index 000000000..5b575be6c --- /dev/null +++ b/plugins/git/git-prompt.plugin.zsh @@ -0,0 +1,604 @@ +# ------------------------------------------------------------------------------ +# FILE: git-prompt.plugin.zsh +# DESCRIPTION: oh-my-zsh git information for your PROMPT. +# AUTHOR: Ashley Dev (the.ashley.dev+git-prompt@gmail.com) +# VERSION: 2.1 +# SCREENSHOT: +# ------------------------------------------------------------------------------ + +# USAGE: +# +# 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. +# +# This example shows some of the things you can do with this plugin. This is +# how the author uses it: +# ---------------------- SAMPLE THEME FILE ------------------------ +# +# # 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 +# # logic will turn off the showing of dirty +# # state in your git prompt if ctrl-c is pressed +# # 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 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 +# # repositories. +# #GIT_PROMPT_SHORTCIRCUIT='off' +# +# GIT_PROMPT_SHOWUPSTREAM="verbose" +# #GIT_PROMPT_SHOWREBASEINFO='off' +# #GIT_PROMPT_SHOWBRANCH='off' +# #GIT_PROMPT_SHOWSTASHSTATE='off' +# #GIT_PROMPT_SHORTCIRCUIT='off' +# #GIT_PROMPT_SHOWDIRTYSTATE='off' +# +# # Some color settings for my prompt format +# # '_C' for color: +# 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 +# +# # GIT_PROMPT_INFO_FUNC must be set to the +# # function that defines your prompt info +# # in order to turn this plugin on. +# # $GIT_PROMPT_INFO_FUNC to be called when the +# # git prompt info variable needs to be updated. +# GIT_PROMPT_INFO_FUNC='update__GIT_PROMPT_INFO' +# +# # update__GIT_PROMPT_INFO creates the format and +# # content 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. +# # +# # 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. +# # +# local __GIT_PROMPT_INFO='' +# 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 +# fi +# +# _git_prompt__stash +# local s=$GIT_PROMPT_STASH_STATE_DIRTY +# +# _git_prompt__upstream +# local p=$GIT_PROMPT_UPSTREAM_STATE +# +# _git_prompt__branch +# local b=$GIT_PROMPT_BRANCH +# +# _git_prompt__rebase_info +# local r=$GIT_PROMPT_REBASE_INFO +# +# _git_prompt__dirty_state +# local w=$GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY +# local i=$GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY +# local u=$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED +# local f=$GIT_PROMPT_DIRTY_STATE_FRESH_REPO +# +# if [ -z "$b$i$w$u" ]; then +# if [ -n "$g" ]; then +# __GIT_PROMPT_INFO="$R$_Cerror_(Error: bad ./$g dir)$R" +# return +# fi +# fi +# +# if [ "$s" = 'yes' ]; then +# s="$_Cs_\$$R" +# else +# s="" +# fi +# +# if [ -n "$p" ]; then +# p="$_Cp_$p$R" +# fi +# +# if [ "$i" = "yes" ]; then +# i="$_Ci_+$R" +# else +# i="" +# fi +# +# if [ -n "$b" ]; then +# if [ "$f" = "yes" ]; then +# # this is a fresh repo, nothing here... +# b="$_Cb_new_repo_$b$R" +# elif [ "$w" = 'yes' ]; then +# b="$_Cb_dirty_$b$R" +# elif [ "$w" = 'no' ]; then +# b="$_Cb_clean_$b$R" +# fi +# fi +# +# if [ -n "$r" ]; then +# r="$_Cr_$r$R" +# fi +# +# local _prompt="$b$r$i$s$p" +# # add ( ) around _prompt: +# if [ $f = 'yes' ]; then +# _prompt="($_prompt)" +# elif [ "$u" = "yes" ]; then +# _prompt="$_Cu_dirty_($_prompt$_Cu_dirty_)" +# elif [ "$u" = "no" ]; then +# _prompt="$_Cu_clean_($_prompt$_Cu_clean_)" +# else +# fi +# +# __GIT_PROMPT_INFO="$R$_prompt$R" +# } +# ----------------------------------------------------------------- +# +# + + +#------------------ git information utils ------------------ +# For some of the following functions, I borrowed some from: +# https://github.com/git/git/blob/master/contrib/completion/git-completion.bash +# + +# _git_promt__git_dir accepts 0 or 1 arguments (i.e., location) +# 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 + if [ -d .git ]; then + echo .git + else + git rev-parse --git-dir 2>/dev/null + fi + elif [ -d "$1/.git" ]; then + echo "$1/.git" + else + echo "$1" + fi +} + +# sets GIT_PROMPT_UPSTREAM_STATE +# +# output format: +# A "<" indicates you are behind, ">" indicates you are ahead, "<>" +# indicates you have diverged, "=" indicates no divergence, and "" indicates +# there is no upstream or this feature is turned 'off' (see below). +# +# You can control behaviour by setting GIT_PROMPT_SHOWUPSTREAM to a +# space-separated list of values: +# off no output +# verbose show number of commits ahead/behind (+/-) upstream instead +# of using "<" and ">". +# legacy don't use the '--count' option available in recent +# versions of git-rev-list +# git always compare HEAD to @{upstream} +# svn always compare HEAD to your SVN upstream +# By default, _git_prompt__upstream will compare HEAD to your SVN upstream +# if it can find one, or @{upstream} otherwise. Once you have +# set GIT_PROMPT_SHOWUPSTREAM, you can override it on a +# per-repository basis by setting the prompt.showUpstream config +# variable (i.e. `git config prompt.showUpstream 'verbose legacy'`). +# +# _git_prompt__upstream accepts 0 or 1 arguments. If an argument is given, it +# must be a string of the form specified above for GIT_PROMPT_SHOWUPSTREAM. +# Setting this argument will override any value set for GIT_PROMPT_SHOWUPSTREAM +# or in the .git/config. +_git_prompt__upstream () +{ + GIT_PROMPT_UPSTREAM_STATE='' + + if [ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then + return + fi + + local key value + local svn_remote svn_url_pattern count n + local upstream=git legacy="" verbose="" + local p + + # get some config options from git-config + while read key value; do + case "$key" in + prompt.showupstream*) + GIT_PROMPT_SHOWUPSTREAM="$value" + ;; + svn-remote.*.url) + svn_remote=( "${svn_remote[@]}" $value ) + svn_url_pattern="$svn_url_pattern\\|$value" + upstream=svn+git # default upstream is SVN if available, else git + ;; + esac + done < <(git config --get-regexp '^(svn-remote\..*\.url|prompt\.showupstream)' 2>/dev/null) + + if [ -n "${1-}" ]; then + GIT_PROMPT_SHOWUPSTREAM=$1 + fi + + # parse configuration values + for option in ${GIT_PROMPT_SHOWUPSTREAM}; do + case "$option" in + off) return ;; + git|svn) upstream="$option" ;; + verbose) verbose=1 ;; + legacy) legacy=1 ;; + esac + done + + # Find our upstream + case "$upstream" in + git) upstream="@{upstream}" ;; + svn*) + # get the upstream from the "git-svn-id: ..." in a commit message + # (git-svn uses essentially the same procedure internally) + local svn_upstream=$(git log --first-parent -1 --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null | awk '/commit / { print $2 }') + if [[ 0 -ne ${#svn_upstream[@]} ]]; then + if [[ -z "$svn_upstream" ]]; then + # default branch name for checkouts with no layout: + upstream='git-svn' + else + upstream=${svn_upstream#/} + fi + elif [[ "svn+git" = "$upstream" ]]; then + upstream="@{upstream}" + fi + ;; + esac + + # Find how many commits we are ahead/behind our upstream + # produce equivalent output to --count for older versions of git + local ahead behind + if git rev-list --left-right "$upstream"...HEAD >/dev/null 2>&1; then + behind="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null | grep '^<' | wc -l | tr -d ' ' 2>/dev/null)" + ahead="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null | grep '^[^<]' | wc -l | tr -d ' ' 2>/dev/null)" + count="$behind $ahead" + fi + + # calculate the result + if [[ -z "$verbose" ]]; then + case "$count" in + "") # no upstream + p="" ;; + "0 0") # equal to upstream + p="=" ;; + "0 "*) # ahead of upstream + p=">" ;; + *" 0") # behind upstream + p="<" ;; + *) # diverged from upstream + p="<>" ;; + esac + else + case "$count" in + "") # no upstream + p="" ;; + "0 0") # equal to upstream + p="=" ;; + "0 "*) # ahead of upstream + p="+${count#0 }" ;; + *" 0") # behind upstream + p="-${count% 0}" ;; + *) # diverged from upstream + p="-${count% *}+${count#* }" ;; + esac + fi + + GIT_PROMPT_UPSTREAM_STATE=$p +} + +_git_prompt__rebase_info () +{ + GIT_PROMPT_REBASE_INFO='' + + if [ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then + return + fi + if [ "$GIT_PROMPT_SHOWREBASEINFO" = 'off' ]; then + return + fi + if [ "$(git config --bool prompt.showRebaseInfo)" = "false" ]; then + return + fi + + local r="" + local g="$(_git_promt__git_dir)" + if [ -n "$g" ]; then + if [ -f "$g/rebase-merge/interactive" ]; then + r="|REBASE-i" + elif [ -d "$g/rebase-merge" ]; then + r="|REBASE-m" + else + if [ -d "$g/rebase-apply" ]; then + if [ -f "$g/rebase-apply/rebasing" ]; then + r="|REBASE" + elif [ -f "$g/rebase-apply/applying" ]; then + r="|AM" + else + r="|AM/REBASE" + fi + elif [ -f "$g/MERGE_HEAD" ]; then + r="|MERGING" + elif [ -f "$g/CHERRY_PICK_HEAD" ]; then + r="|CHERRY-PICKING" + elif [ -f "$g/BISECT_LOG" ]; then + r="|BISECTING" + fi + + fi + fi + + GIT_PROMPT_REBASE_INFO=$r +} + +_git_prompt__branch () +{ + GIT_PROMPT_BRANCH='' + + if [ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then + return + fi + + if [ "$GIT_PROMPT_SHOWBRANCH" = 'off' ]; then + return + fi + if [ "$(git config --bool prompt.showBranch)" = "false" ]; then + return + fi + + local b="" + local g="$(_git_promt__git_dir)" + if [ -n "$g" ]; then + if [ -f "$g/rebase-merge/interactive" ]; then + b="$(cat "$g/rebase-merge/head-name")" + elif [ -d "$g/rebase-merge" ]; then + b="$(cat "$g/rebase-merge/head-name")" + else + b="$(git symbolic-ref HEAD 2>/dev/null)" || { + + b="$( + case "${GIT_PROMPT_DESCRIBE_STYLE-}" in + (contains) + git describe --contains HEAD ;; + (branch) + git describe --contains --all HEAD ;; + (describe) + git describe HEAD ;; + (* | default) + git describe --tags --exact-match HEAD ;; + esac 2>/dev/null)" || + + b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)" || + b="$b" + } + fi + b=${b##refs/heads/} + if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then + if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then + b="BARE:$b" + else + b="GIT_DIR!" + fi + fi + fi + + GIT_PROMPT_BRANCH=$b +} + + +_git_prompt__stash () +{ + GIT_PROMPT_STASH_STATE_DIRTY='' + + if [ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then + return + fi + + if [ "$GIT_PROMPT_SHOWSTASHSTATE" = 'off' ]; then + return + fi + if [ "$(git config --bool prompt.showStashState)" = "false" ]; then + return + fi + + if git rev-parse --verify refs/stash >/dev/null 2>&1; then + GIT_PROMPT_STASH_STATE_DIRTY='yes' + else + GIT_PROMPT_STASH_STATE_DIRTY='no' + fi +} + + +# This is the short-circuit logic: +local _big_repo='init' +__git_prompt_shortcircuit () +{ + if [[ "$_big_repo" == 'yes' ]]; then + _big_repo='' + if [ "$GIT_PROMPT_SHORTCIRCUIT" != 'off' ]; then + echo "$fg[red]" > /dev/stderr + echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: Looks like you hit ctrl-c." > /dev/stderr + echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: So for this repo I'm setting:" > /dev/stderr + echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: git config prompt.showDirtyState false" > /dev/stderr + echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: On big git repos it takes a long time to get info for your prompt." > /dev/stderr + echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: To revert it, run:" > /dev/stderr + echo "${bold_color}SHELL PROMPT$fg_no_bold[red]:$reset_color git config prompt.showDirtyState true" > /dev/stderr + echo '' > /dev/stderr + + git config prompt.showDirtyState 'false' + $GIT_PROMPT_INFO_FUNC + fi + fi +} +TRAPINT () +{ + __git_prompt_shortcircuit + return $(( 128 + $1 )) +} + +_git_prompt__dirty_state () +{ + GIT_PROMPT_DIRTY_STATE_FRESH_REPO='' + GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='' + GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='' + GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='' + GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='' + GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='' + GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='' + GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='' + GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='' + + if [ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then + return + fi + + local g="$(_git_promt__git_dir)" + if [ -z "$g" ]; then + return + fi + if [ "$GIT_PROMPT_SHOWDIRTYSTATE" = 'off' ]; then + return + fi + if [ "$(git config --bool prompt.showDirtyState)" = "false" ]; then + return + fi + + GIT_PROMPT_DIRTY_STATE_FRESH_REPO='no' + GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='no' + GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='no' + GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='no' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='no' + GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='no' + GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='no' + GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='no' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='no' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='no' + GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='no' + GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='no' + + if git rev-parse --quiet --verify HEAD >/dev/null; then + else + GIT_PROMPT_DIRTY_STATE_FRESH_REPO='yes' + fi + + _big_repo='yes' + local line + while IFS=$'\n' read line; do + if [[ "$line" = M* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' + fi + if [[ "$line" = A* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' + fi + if [[ "$line" = R* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' + fi + if [[ "$line" = C* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' + fi + if [[ "$line" = D* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' + fi + + if [[ "$line" = \?\?* ]]; then + GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='yes' + fi + if [[ "$line" = \ M* ]]; then + GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='yes' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='yes' + fi + if [[ "$line" = \ D* ]]; then + GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='yes' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='yes' + fi + + if [[ "$line" = UU* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' + fi + done < <(git status --porcelain 2> /dev/null) + _big_repo='' +} + +#------------------ Fast Prompt ------------------ +# This section sets up some functions that get called infrequently as possible +# and therefore don't slow your prompt down as you are using zsh. +# +# I borrowed from: http://sebastiancelis.com/2009/nov/16/zsh-prompt-git-users/ + +# Enable auto-execution of functions. +typeset -Uga preexec_functions +typeset -Uga precmd_functions +typeset -Uga chpwd_functions +typeset -Uga periodic_functions + +# Append git functions needed for prompt. +preexec_functions+='_git_prompt__preexec_update_git_vars' +precmd_functions+='_git_prompt__precmd_update_git_vars' +chpwd_functions+="_git_prompt_info" +PERIOD=15 +periodic_functions+="_git_prompt_info" + +_git_prompt_info () { $GIT_PROMPT_INFO_FUNC } +_git_prompt_info + +_git_prompt__precmd_update_git_vars() +{ + if [[ $ZSH_VERSION = *\ 4.2* ]]; then + # some older versions of zsh don't have periodic_functions, so do the + # slow path if that's the case: + $GIT_PROMPT_INFO_FUNC + + elif [ -n "$__EXECUTED_GIT_COMMAND" ]; then + $GIT_PROMPT_INFO_FUNC + unset __EXECUTED_GIT_COMMAND + fi +} +_git_prompt__preexec_update_git_vars () +{ + case "$1" in + $EDITOR*) __EXECUTED_GIT_COMMAND=1 ;; + g*) __EXECUTED_GIT_COMMAND=1 ;; + rm*) __EXECUTED_GIT_COMMAND=1 ;; + touch*) __EXECUTED_GIT_COMMAND=1 ;; + mkdir*) __EXECUTED_GIT_COMMAND=1 ;; + esac +} + +#-------------------------------------------------- diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index baf34b830..bb515c73a 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -1,117 +1,3 @@ -# Renders the name of the current branch. -function git_prompt_info() { - local branch=$(git_current_branch) - if [[ -n "$branch" ]]; then - echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${branch}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}" - fi -} - -# Gets the current branch. -function git_current_branch() { - local ref=$(git symbolic-ref HEAD 2> /dev/null) - if [[ -n "$ref" ]]; then - echo "${ref#refs/heads/}" - fi -} - -# Checks if the working tree is dirty. -function parse_git_dirty() { - if [[ -n $(git status -s 2> /dev/null) ]]; then - echo "$ZSH_THEME_GIT_PROMPT_DIRTY" - else - echo "$ZSH_THEME_GIT_PROMPT_CLEAN" - fi -} - -# Checks if there are commits ahead from remote. -function git_prompt_ahead() { - if $(echo "$(git log origin/$(git_current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then - echo "$ZSH_THEME_GIT_PROMPT_AHEAD" - fi -} - -# Formats the prompt string for current git commit short SHA. -function git_prompt_short_sha() { - local sha=$(git rev-parse --short HEAD 2> /dev/null) - if [[ -n "$sha" ]]; then - echo "${ZSH_THEME_GIT_PROMPT_SHA_BEFORE}${sha}${ZSH_THEME_GIT_PROMPT_SHA_AFTER}" - fi -} - -# Formats the prompt string for current git commit long SHA. -function git_prompt_long_sha() { - local sha=$(git rev-parse HEAD 2> /dev/null) - if [[ -n "$sha" ]]; then - echo "${ZSH_THEME_GIT_PROMPT_SHA_BEFORE}${sha}${ZSH_THEME_GIT_PROMPT_SHA_AFTER}" - fi -} - -# Gets the status of the working tree. -function git_prompt_status() { - local indicators line untracked added modified renamed deleted - while IFS=$'\n' read line; do - if [[ "$line" =~ '^\?\? ' ]]; then - [[ -n $untracked ]] && continue || untracked='yes' - indicators="${ZSH_THEME_GIT_PROMPT_UNTRACKED}${indicators}" - fi - if [[ "$line" =~ '^(((A|M|D|T) )|(AD|AM|AT|MM)) ' ]]; then - [[ -n $added ]] && continue || added='yes' - indicators="${ZSH_THEME_GIT_PROMPT_ADDED}${indicators}" - fi - if [[ "$line" =~ '^(( (M|T))|(AM|AT|MM)) ' ]]; then - [[ -n $modified ]] && continue || modified='yes' - indicators="${ZSH_THEME_GIT_PROMPT_MODIFIED}${indicators}" - fi - if [[ "$line" =~ '^R ' ]]; then - [[ -n $renamed ]] && continue || renamed='yes' - indicators="${ZSH_THEME_GIT_PROMPT_RENAMED}${indicators}" - fi - if [[ "$line" =~ '^( D|AD) ' ]]; then - [[ -n $deleted ]] && continue || deleted='yes' - indicators="${ZSH_THEME_GIT_PROMPT_DELETED}${indicators}" - fi - if [[ "$line" =~ '^UU ' ]]; then - [[ -n $unmerged ]] && continue || unmerged='yes' - indicators="${ZSH_THEME_GIT_PROMPT_UNMERGED}${indicators}" - fi - done < <(git status --porcelain 2> /dev/null) - echo $indicators -} - -alias g='git' -compdef g=git -alias gst='git status' -compdef _git gst=git-status -alias gl='git pull' -compdef _git gl=git-pull -alias gup='git fetch && git rebase' -compdef _git gup=git-fetch -alias gp='git push' -compdef _git gp=git-push -gdv() { git-diff -w "$@" | view - } -compdef _git gdv=git-diff -alias gc='git commit -v' -compdef _git gc=git-commit -alias gca='git commit -v -a' -compdef _git gca=git-commit -alias gco='git checkout' -compdef _git gco=git-checkout -alias gb='git branch' -compdef _git gb=git-branch -alias gba='git branch -a' -compdef _git gba=git-branch -alias gcount='git shortlog -sn' -compdef gcount=git -alias gcp='git cherry-pick' -compdef _git gcp=git-cherry-pick -alias glg='git log --stat --max-count=5' -compdef _git glg=git-log -alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk' -compdef git-svn-dcommit-push=git -alias ggpull='git pull origin $(git_current_branch)' -compdef ggpull=git -alias ggpush='git push origin $(git_current_branch)' -compdef ggpush=git -alias ggpnp='git pull origin $(git_current_branch) && git push origin $(git_current_branch)' -compdef ggpnp=git - +source $ZSH/plugins/git/git-aliases.plugin.zsh +source $ZSH/plugins/git/git-prompt-old.plugin.zsh +source $ZSH/plugins/git/git-prompt.plugin.zsh diff --git a/themes/ashleydev.zsh-theme b/themes/ashleydev.zsh-theme new file mode 100644 index 000000000..bf0932768 --- /dev/null +++ b/themes/ashleydev.zsh-theme @@ -0,0 +1,144 @@ +# 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. + +#-------------------- 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 + + # Reset formating: + local R="%{$terminfo[sgr0]%}" + + # 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]%}" + + # RPROMPT colors: + local _Cdate_="%{$fg[green]%}" + local _Creturn_code_="%{$fg[red]%}" + local _Cvi_mode_="%{$fg_bold[cyan]%}" +fi + +#----------------------------------------------------- +# git prompt info: + +# 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' + +local __GIT_PROMPT_INFO='' +# will set __GIT_PROMPT_INFO +update__GIT_PROMPT_INFO () +{ + local g="$(_git_promt__git_dir)" + if [ -z "$g" ]; then + __GIT_PROMPT_INFO='' + return + fi + + _git_prompt__stash + local s=$GIT_PROMPT_STASH_STATE_DIRTY + + _git_prompt__upstream + local p=$GIT_PROMPT_UPSTREAM_STATE + + _git_prompt__branch + local b=$GIT_PROMPT_BRANCH + + _git_prompt__rebase_info + local r=$GIT_PROMPT_REBASE_INFO + + _git_prompt__dirty_state + local w=$GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY + local i=$GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY + local u=$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED + local f=$GIT_PROMPT_DIRTY_STATE_FRESH_REPO + + if [ -z "$b$i$w$u" ]; then + if [ -n "$g" ]; then + __GIT_PROMPT_INFO="$R$_Cerror_(Error: bad ./$g dir)$R" + return + fi + fi + + if [ "$s" = 'yes' ]; then + s="$_Cs_\$$R" + else + s="" + fi + + if [ -n "$p" ]; then + p="$_Cp_$p$R" + fi + + if [ "$i" = "yes" ]; then + i="$_Ci_+$R" + else + i="" + fi + + if [ -n "$b" ]; then + if [ "$f" = "yes" ]; then + # this is a fresh repo, nothing here... + b="$_Cb_new_repo_$b$R" + elif [ "$w" = 'yes' ]; then + b="$_Cb_dirty_$b$R" + elif [ "$w" = 'no' ]; then + b="$_Cb_clean_$b$R" + fi + fi + + if [ -n "$r" ]; then + r="$_Cr_$r$R" + fi + + local _prompt="$b$r$i$s$p" + # add ( ) around _prompt: + if [ "$f" = 'yes' ]; then + _prompt="($_prompt)" + elif [ "$u" = "yes" ]; then + _prompt="$_Cu_dirty_($_prompt$_Cu_dirty_)" + elif [ "$u" = "no" ]; then + _prompt="$_Cu_clean_($_prompt$_Cu_clean_)" + else + fi + + __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" + From 0a3611c572aadc7fbaedd76970afdb1bc032607d Mon Sep 17 00:00:00 2001 From: Ashley Dev Date: Thu, 2 Jun 2011 11:13:22 -0700 Subject: [PATCH 51/64] add header to theme file --- themes/ashleydev.zsh-theme | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/themes/ashleydev.zsh-theme b/themes/ashleydev.zsh-theme index bf0932768..2dcb8be8a 100644 --- a/themes/ashleydev.zsh-theme +++ b/themes/ashleydev.zsh-theme @@ -1,3 +1,12 @@ +# ------------------------------------------------------------------------------ +# FILE: ashleydev.theme.zsh +# DESCRIPTION: oh-my-zsh prompt theme, shows vi mode, last shell return code, +# and verbose git info. +# AUTHOR: Ashley Dev (the.ashley.dev+zsh-theme@gmail.com) +# VERSION: 2.1 +# SCREENSHOT: +# ------------------------------------------------------------------------------ + # 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. From ba0e90d88737db6346d38c52b5e794c42caecca4 Mon Sep 17 00:00:00 2001 From: Ashley Dev Date: Thu, 2 Jun 2011 14:11:40 -0700 Subject: [PATCH 52/64] fix up the git prompt when it's a fresh repo --- plugins/git/git-prompt.plugin.zsh | 9 ++++----- themes/ashleydev.zsh-theme | 5 ++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/plugins/git/git-prompt.plugin.zsh b/plugins/git/git-prompt.plugin.zsh index 5b575be6c..e79749e77 100644 --- a/plugins/git/git-prompt.plugin.zsh +++ b/plugins/git/git-prompt.plugin.zsh @@ -148,13 +148,12 @@ # # local _prompt="$b$r$i$s$p" # # add ( ) around _prompt: -# if [ $f = 'yes' ]; then -# _prompt="($_prompt)" -# elif [ "$u" = "yes" ]; then +# if [ "$u" = "yes" ]; then # _prompt="$_Cu_dirty_($_prompt$_Cu_dirty_)" # elif [ "$u" = "no" ]; then # _prompt="$_Cu_clean_($_prompt$_Cu_clean_)" # else +# _prompt="($_prompt$)" # fi # # __GIT_PROMPT_INFO="$R$_prompt$R" @@ -539,11 +538,11 @@ _git_prompt__dirty_state () if [[ "$line" = \?\?* ]]; then GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='yes' fi - if [[ "$line" = \ M* ]]; then + if [[ "$line" = ?M* ]]; then GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='yes' GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='yes' fi - if [[ "$line" = \ D* ]]; then + if [[ "$line" = ?D* ]]; then GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='yes' GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='yes' fi diff --git a/themes/ashleydev.zsh-theme b/themes/ashleydev.zsh-theme index 2dcb8be8a..30351a515 100644 --- a/themes/ashleydev.zsh-theme +++ b/themes/ashleydev.zsh-theme @@ -120,13 +120,12 @@ update__GIT_PROMPT_INFO () local _prompt="$b$r$i$s$p" # add ( ) around _prompt: - if [ "$f" = 'yes' ]; then - _prompt="($_prompt)" - elif [ "$u" = "yes" ]; then + if [ "$u" = "yes" ]; then _prompt="$_Cu_dirty_($_prompt$_Cu_dirty_)" elif [ "$u" = "no" ]; then _prompt="$_Cu_clean_($_prompt$_Cu_clean_)" else + _prompt="($_prompt$)" fi __GIT_PROMPT_INFO="$R$_prompt$R" From 9c4f4f501fe2646d859d0217617cad86e597032e Mon Sep 17 00:00:00 2001 From: Ashley Dev Date: Thu, 2 Jun 2011 15:28:39 -0700 Subject: [PATCH 53/64] Add screenshot urls --- plugins/git/git-prompt.plugin.zsh | 3 ++- themes/ashleydev.zsh-theme | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/git/git-prompt.plugin.zsh b/plugins/git/git-prompt.plugin.zsh index e79749e77..9feda6470 100644 --- a/plugins/git/git-prompt.plugin.zsh +++ b/plugins/git/git-prompt.plugin.zsh @@ -3,7 +3,8 @@ # DESCRIPTION: oh-my-zsh git information for your PROMPT. # AUTHOR: Ashley Dev (the.ashley.dev+git-prompt@gmail.com) # VERSION: 2.1 -# SCREENSHOT: +# SCREENSHOT: http://i.imgur.com/Yw1KG.png +# http://i.imgur.com/wx6MU.png # ------------------------------------------------------------------------------ # USAGE: diff --git a/themes/ashleydev.zsh-theme b/themes/ashleydev.zsh-theme index 30351a515..2cd37341e 100644 --- a/themes/ashleydev.zsh-theme +++ b/themes/ashleydev.zsh-theme @@ -4,7 +4,8 @@ # and verbose git info. # AUTHOR: Ashley Dev (the.ashley.dev+zsh-theme@gmail.com) # VERSION: 2.1 -# SCREENSHOT: +# SCREENSHOT: http://i.imgur.com/Yw1KG.png +# http://i.imgur.com/wx6MU.png # ------------------------------------------------------------------------------ # NOTE: make sure to add 'git' to your list of oh-my-zsh plugins (in your From c4a2588a769ac4f89479525a03cd8c5fc3ee0072 Mon Sep 17 00:00:00 2001 From: Ashley Dev Date: Thu, 2 Jun 2011 16:47:41 -0700 Subject: [PATCH 54/64] update comments: - Describe short-circuit logic better - Make the Sample smaller and simpler --- plugins/git/git-prompt.plugin.zsh | 157 +++++++++--------------------- 1 file changed, 44 insertions(+), 113 deletions(-) diff --git a/plugins/git/git-prompt.plugin.zsh b/plugins/git/git-prompt.plugin.zsh index 9feda6470..da166d6a7 100644 --- a/plugins/git/git-prompt.plugin.zsh +++ b/plugins/git/git-prompt.plugin.zsh @@ -12,152 +12,49 @@ # 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. # -# This example shows some of the things you can do with this plugin. This is -# how the author uses it: +# This simple example shows some of the things you can do with this plugin. +# (See the ashleydev theme for more complex usage.) # ---------------------- SAMPLE THEME FILE ------------------------ # # # 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 -# # logic will turn off the showing of dirty -# # state in your git prompt if ctrl-c is pressed -# # 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 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 -# # repositories. # #GIT_PROMPT_SHORTCIRCUIT='off' # -# GIT_PROMPT_SHOWUPSTREAM="verbose" -# #GIT_PROMPT_SHOWREBASEINFO='off' -# #GIT_PROMPT_SHOWBRANCH='off' -# #GIT_PROMPT_SHOWSTASHSTATE='off' -# #GIT_PROMPT_SHORTCIRCUIT='off' -# #GIT_PROMPT_SHOWDIRTYSTATE='off' -# -# # Some color settings for my prompt format -# # '_C' for color: -# 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 -# # # GIT_PROMPT_INFO_FUNC must be set to the # # function that defines your prompt info # # in order to turn this plugin on. -# # $GIT_PROMPT_INFO_FUNC to be called when the -# # git prompt info variable needs to be updated. # GIT_PROMPT_INFO_FUNC='update__GIT_PROMPT_INFO' # -# # update__GIT_PROMPT_INFO creates the format and -# # content 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. -# # -# # 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. -# # # local __GIT_PROMPT_INFO='' # 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 -# fi -# -# _git_prompt__stash -# local s=$GIT_PROMPT_STASH_STATE_DIRTY -# -# _git_prompt__upstream -# local p=$GIT_PROMPT_UPSTREAM_STATE -# # _git_prompt__branch # local b=$GIT_PROMPT_BRANCH # -# _git_prompt__rebase_info -# local r=$GIT_PROMPT_REBASE_INFO -# # _git_prompt__dirty_state # local w=$GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY # local i=$GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY -# local u=$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED -# local f=$GIT_PROMPT_DIRTY_STATE_FRESH_REPO -# -# if [ -z "$b$i$w$u" ]; then -# if [ -n "$g" ]; then -# __GIT_PROMPT_INFO="$R$_Cerror_(Error: bad ./$g dir)$R" -# return -# fi -# fi -# -# if [ "$s" = 'yes' ]; then -# s="$_Cs_\$$R" -# else -# s="" -# fi -# -# if [ -n "$p" ]; then -# p="$_Cp_$p$R" -# fi # +# # Reset color +# local R="%{$terminfo[sgr0]%}" +# # if [ "$i" = "yes" ]; then -# i="$_Ci_+$R" +# i="%{$bold_color$fg[red]%}+$R" # else # i="" # fi # # if [ -n "$b" ]; then -# if [ "$f" = "yes" ]; then -# # this is a fresh repo, nothing here... -# b="$_Cb_new_repo_$b$R" -# elif [ "$w" = 'yes' ]; then -# b="$_Cb_dirty_$b$R" +# if [ "$w" = 'yes' ]; then +# b="%{$fg_no_bold[red]%}$b$R" # elif [ "$w" = 'no' ]; then -# b="$_Cb_clean_$b$R" +# b="%{$fg_no_bold[green]%}$b$R" # fi # fi # -# if [ -n "$r" ]; then -# r="$_Cr_$r$R" -# fi -# -# local _prompt="$b$r$i$s$p" -# # add ( ) around _prompt: -# if [ "$u" = "yes" ]; then -# _prompt="$_Cu_dirty_($_prompt$_Cu_dirty_)" -# elif [ "$u" = "no" ]; then -# _prompt="$_Cu_clean_($_prompt$_Cu_clean_)" -# else -# _prompt="($_prompt$)" -# fi -# -# __GIT_PROMPT_INFO="$R$_prompt$R" +# __GIT_PROMPT_INFO="$R($b$i)$R" # } # ----------------------------------------------------------------- # @@ -438,6 +335,40 @@ _git_prompt__stash () # This is the short-circuit logic: +# +# Set GIT_PROMPT_SHORTCIRCUIT='off' to turn the short-circuit logic off. +# +# Gathering dirty-state info can take a long time on large repositories. The +# short-circuit logic is engaged by pressing ctrl-c while the prompt is trying +# to gather information about a large repository. When this happens the +# short-circuit logic will display a warning and turn off the showing of dirty +# state in your git prompt (for the local repo only). +# +# NOTE: To make the short-circuit logic work, the GIT_PROMPT_INFO_FUNC function +# must set a global variable (with your git prompt format), rather than echo it. +# Correct: +# +# PROMPT='$__GIT_PROMPT_INFO > ' +# +# # this function sets $__GIT_PROMPT_INFO +# function update_prompt_func () +# { +# #... +# __GIT_PROMPT_INFO="$info" +# } +# GIT_PROMPT_INFO_FUNC=update_prompt_func +# +# Incorrect: +# +# PROMPT='$(update_prompt_func) > ' +# +# function update_prompt_func () +# { +# #... +# echo "$info" +# } +# GIT_PROMPT_INFO_FUNC=update_prompt_func +# local _big_repo='init' __git_prompt_shortcircuit () { From e2955b4901ff14a9e797e542669ce03119fd5bce Mon Sep 17 00:00:00 2001 From: Ashley Dev Date: Thu, 2 Jun 2011 17:07:14 -0700 Subject: [PATCH 55/64] add some more comments --- plugins/git/git-prompt.plugin.zsh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/git/git-prompt.plugin.zsh b/plugins/git/git-prompt.plugin.zsh index da166d6a7..2871180de 100644 --- a/plugins/git/git-prompt.plugin.zsh +++ b/plugins/git/git-prompt.plugin.zsh @@ -212,6 +212,8 @@ _git_prompt__upstream () GIT_PROMPT_UPSTREAM_STATE=$p } +# sets GIT_PROMPT_REBASE_INFO +# with info about a rebase/merge/etc if it's in progress. _git_prompt__rebase_info () { GIT_PROMPT_REBASE_INFO='' @@ -256,6 +258,8 @@ _git_prompt__rebase_info () GIT_PROMPT_REBASE_INFO=$r } +# sets GIT_PROMPT_BRANCH +# with the branch name _git_prompt__branch () { GIT_PROMPT_BRANCH='' @@ -311,6 +315,8 @@ _git_prompt__branch () } +# sets GIT_PROMPT_STASH_STATE_DIRTY +# if the git stash state is dirty _git_prompt__stash () { GIT_PROMPT_STASH_STATE_DIRTY='' @@ -395,6 +401,7 @@ TRAPINT () return $(( 128 + $1 )) } +# sets a bunch of variables, see below: _git_prompt__dirty_state () { GIT_PROMPT_DIRTY_STATE_FRESH_REPO='' From b5179f6c490a3410b9a355549bba1b9da044f01f Mon Sep 17 00:00:00 2001 From: Ashley Dev Date: Thu, 2 Jun 2011 17:52:02 -0700 Subject: [PATCH 56/64] fix spelling of _git_promt__git_dir --- plugins/git/git-prompt.plugin.zsh | 10 +++++----- themes/ashleydev.zsh-theme | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/git/git-prompt.plugin.zsh b/plugins/git/git-prompt.plugin.zsh index 2871180de..6d674158f 100644 --- a/plugins/git/git-prompt.plugin.zsh +++ b/plugins/git/git-prompt.plugin.zsh @@ -66,10 +66,10 @@ # https://github.com/git/git/blob/master/contrib/completion/git-completion.bash # -# _git_promt__git_dir accepts 0 or 1 arguments (i.e., location) +# _git_prompt__git_dir accepts 0 or 1 arguments (i.e., location) # echos the location of .git repo. # Useful for quickly figuring out if cwd is under a git repo. -_git_promt__git_dir () +_git_prompt__git_dir () { if [ -z "${1-}" ]; then if [ -d .git ]; then @@ -229,7 +229,7 @@ _git_prompt__rebase_info () fi local r="" - local g="$(_git_promt__git_dir)" + local g="$(_git_prompt__git_dir)" if [ -n "$g" ]; then if [ -f "$g/rebase-merge/interactive" ]; then r="|REBASE-i" @@ -276,7 +276,7 @@ _git_prompt__branch () fi local b="" - local g="$(_git_promt__git_dir)" + local g="$(_git_prompt__git_dir)" if [ -n "$g" ]; then if [ -f "$g/rebase-merge/interactive" ]; then b="$(cat "$g/rebase-merge/head-name")" @@ -421,7 +421,7 @@ _git_prompt__dirty_state () return fi - local g="$(_git_promt__git_dir)" + local g="$(_git_prompt__git_dir)" if [ -z "$g" ]; then return fi diff --git a/themes/ashleydev.zsh-theme b/themes/ashleydev.zsh-theme index 2cd37341e..5fcd132ef 100644 --- a/themes/ashleydev.zsh-theme +++ b/themes/ashleydev.zsh-theme @@ -57,7 +57,7 @@ local __GIT_PROMPT_INFO='' # will set __GIT_PROMPT_INFO update__GIT_PROMPT_INFO () { - local g="$(_git_promt__git_dir)" + local g="$(_git_prompt__git_dir)" if [ -z "$g" ]; then __GIT_PROMPT_INFO='' return From 51e7a6ebe1795598dbf833522fcda41bfaeb2804 Mon Sep 17 00:00:00 2001 From: Ashley Dev Date: Thu, 2 Jun 2011 18:01:44 -0700 Subject: [PATCH 57/64] update git-prompt.plugin.zsh to coding standards: shiftwidth=2, and rename some variable names to remove leading underscores --- plugins/git/git-prompt.plugin.zsh | 738 +++++++++++++++--------------- themes/ashleydev.zsh-theme | 26 +- 2 files changed, 382 insertions(+), 382 deletions(-) diff --git a/plugins/git/git-prompt.plugin.zsh b/plugins/git/git-prompt.plugin.zsh index 6d674158f..35bc0e8f5 100644 --- a/plugins/git/git-prompt.plugin.zsh +++ b/plugins/git/git-prompt.plugin.zsh @@ -16,46 +16,46 @@ # (See the ashleydev theme for more complex usage.) # ---------------------- SAMPLE THEME FILE ------------------------ # -# # this is a simple example PROMPT with only git -# # info from this plugin in it: -# PROMPT='$__GIT_PROMPT_INFO# ' +# # this is a simple example PROMPT with only git +# # info from this plugin in it: +# PROMPT='$_GIT_PROMPT_INFO# ' # -# #GIT_PROMPT_SHORTCIRCUIT='off' -# -# # GIT_PROMPT_INFO_FUNC must be set to the -# # function that defines your prompt info -# # in order to turn this plugin on. -# GIT_PROMPT_INFO_FUNC='update__GIT_PROMPT_INFO' +# #GIT_PROMPT_SHORTCIRCUIT='off' +# +# # GIT_PROMPT_INFO_FUNC must be set to the +# # function that defines your prompt info +# # in order to turn this plugin on. +# GIT_PROMPT_INFO_FUNC='update__GIT_PROMPT_INFO' # -# local __GIT_PROMPT_INFO='' -# update__GIT_PROMPT_INFO () -# { -# _git_prompt__branch -# local b=$GIT_PROMPT_BRANCH -# -# _git_prompt__dirty_state -# local w=$GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY -# local i=$GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY -# -# # Reset color -# local R="%{$terminfo[sgr0]%}" +# local _GIT_PROMPT_INFO='' +# update__GIT_PROMPT_INFO () +# { +# git_prompt__branch +# local b=$GIT_PROMPT_BRANCH +# +# git_prompt__dirty_state +# local w=$GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY +# local i=$GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY +# +# # Reset color +# local R="%{$terminfo[sgr0]%}" # -# if [ "$i" = "yes" ]; then -# i="%{$bold_color$fg[red]%}+$R" -# else -# i="" -# fi -# -# if [ -n "$b" ]; then -# if [ "$w" = 'yes' ]; then -# b="%{$fg_no_bold[red]%}$b$R" -# elif [ "$w" = 'no' ]; then -# b="%{$fg_no_bold[green]%}$b$R" -# fi -# fi -# -# __GIT_PROMPT_INFO="$R($b$i)$R" -# } +# if [[ "$i" = "yes" ]]; then +# i="%{$bold_color$fg[red]%}+$R" +# else +# i="" +# fi +# +# if [[ -n "$b" ]]; then +# if [[ "$w" = 'yes' ]]; then +# b="%{$fg_no_bold[red]%}$b$R" +# elif [[ "$w" = 'no' ]]; then +# b="%{$fg_no_bold[green]%}$b$R" +# fi +# fi +# +# __GIT_PROMPT_INFO="$R($b$i)$R" +# } # ----------------------------------------------------------------- # # @@ -66,22 +66,22 @@ # https://github.com/git/git/blob/master/contrib/completion/git-completion.bash # -# _git_prompt__git_dir accepts 0 or 1 arguments (i.e., location) +# git_prompt__git_dir accepts 0 or 1 arguments (i.e., location) # echos the location of .git repo. # Useful for quickly figuring out if cwd is under a git repo. -_git_prompt__git_dir () +git_prompt__git_dir () { - if [ -z "${1-}" ]; then - if [ -d .git ]; then - echo .git - else - git rev-parse --git-dir 2>/dev/null - fi - elif [ -d "$1/.git" ]; then - echo "$1/.git" + if [[ -z "${1-}" ]]; then + if [[ -d .git ]]; then + echo .git else - echo "$1" + git rev-parse --git-dir 2>/dev/null fi + elif [[ -d "$1/.git" ]]; then + echo "$1/.git" + else + echo "$1" + fi } # sets GIT_PROMPT_UPSTREAM_STATE @@ -100,243 +100,243 @@ _git_prompt__git_dir () # versions of git-rev-list # git always compare HEAD to @{upstream} # svn always compare HEAD to your SVN upstream -# By default, _git_prompt__upstream will compare HEAD to your SVN upstream +# By default, git_prompt__upstream will compare HEAD to your SVN upstream # if it can find one, or @{upstream} otherwise. Once you have # set GIT_PROMPT_SHOWUPSTREAM, you can override it on a # per-repository basis by setting the prompt.showUpstream config # variable (i.e. `git config prompt.showUpstream 'verbose legacy'`). # -# _git_prompt__upstream accepts 0 or 1 arguments. If an argument is given, it +# git_prompt__upstream accepts 0 or 1 arguments. If an argument is given, it # must be a string of the form specified above for GIT_PROMPT_SHOWUPSTREAM. # Setting this argument will override any value set for GIT_PROMPT_SHOWUPSTREAM # or in the .git/config. -_git_prompt__upstream () +git_prompt__upstream () { - GIT_PROMPT_UPSTREAM_STATE='' + GIT_PROMPT_UPSTREAM_STATE='' - if [ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then - return - fi + if [[ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then + return + fi - local key value - local svn_remote svn_url_pattern count n - local upstream=git legacy="" verbose="" - local p + local key value + local svn_remote svn_url_pattern count n + local upstream=git legacy="" verbose="" + local p - # get some config options from git-config - while read key value; do - case "$key" in - prompt.showupstream*) - GIT_PROMPT_SHOWUPSTREAM="$value" - ;; - svn-remote.*.url) - svn_remote=( "${svn_remote[@]}" $value ) - svn_url_pattern="$svn_url_pattern\\|$value" - upstream=svn+git # default upstream is SVN if available, else git - ;; - esac - done < <(git config --get-regexp '^(svn-remote\..*\.url|prompt\.showupstream)' 2>/dev/null) - - if [ -n "${1-}" ]; then - GIT_PROMPT_SHOWUPSTREAM=$1 - fi - - # parse configuration values - for option in ${GIT_PROMPT_SHOWUPSTREAM}; do - case "$option" in - off) return ;; - git|svn) upstream="$option" ;; - verbose) verbose=1 ;; - legacy) legacy=1 ;; - esac - done - - # Find our upstream - case "$upstream" in - git) upstream="@{upstream}" ;; - svn*) - # get the upstream from the "git-svn-id: ..." in a commit message - # (git-svn uses essentially the same procedure internally) - local svn_upstream=$(git log --first-parent -1 --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null | awk '/commit / { print $2 }') - if [[ 0 -ne ${#svn_upstream[@]} ]]; then - if [[ -z "$svn_upstream" ]]; then - # default branch name for checkouts with no layout: - upstream='git-svn' - else - upstream=${svn_upstream#/} - fi - elif [[ "svn+git" = "$upstream" ]]; then - upstream="@{upstream}" - fi - ;; + # get some config options from git-config + while read key value; do + case "$key" in + prompt.showupstream*) + GIT_PROMPT_SHOWUPSTREAM="$value" + ;; + svn-remote.*.url) + svn_remote=( "${svn_remote[@]}" $value ) + svn_url_pattern="$svn_url_pattern\\|$value" + upstream=svn+git # default upstream is SVN if available, else git + ;; esac + done < <(git config --get-regexp '^(svn-remote\..*\.url|prompt\.showupstream)' 2>/dev/null) - # Find how many commits we are ahead/behind our upstream - # produce equivalent output to --count for older versions of git - local ahead behind - if git rev-list --left-right "$upstream"...HEAD >/dev/null 2>&1; then - behind="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null | grep '^<' | wc -l | tr -d ' ' 2>/dev/null)" - ahead="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null | grep '^[^<]' | wc -l | tr -d ' ' 2>/dev/null)" - count="$behind $ahead" + if [[ -n "${1-}" ]]; then + GIT_PROMPT_SHOWUPSTREAM=$1 + fi + + # parse configuration values + for option in ${GIT_PROMPT_SHOWUPSTREAM}; do + case "$option" in + off) return ;; + git|svn) upstream="$option" ;; + verbose) verbose=1 ;; + legacy) legacy=1 ;; + esac + done + + # Find our upstream + case "$upstream" in + git) upstream="@{upstream}" ;; + svn*) + # get the upstream from the "git-svn-id: ..." in a commit message + # (git-svn uses essentially the same procedure internally) + local svn_upstream=$(git log --first-parent -1 --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null | awk '/commit / { print $2 }') + if [[ 0 -ne ${#svn_upstream[@]} ]]; then + if [[ -z "$svn_upstream" ]]; then + # default branch name for checkouts with no layout: + upstream='git-svn' + else + upstream=${svn_upstream#/} + fi + elif [[ "svn+git" = "$upstream" ]]; then + upstream="@{upstream}" fi + ;; + esac - # calculate the result - if [[ -z "$verbose" ]]; then - case "$count" in - "") # no upstream - p="" ;; - "0 0") # equal to upstream - p="=" ;; - "0 "*) # ahead of upstream - p=">" ;; - *" 0") # behind upstream - p="<" ;; - *) # diverged from upstream - p="<>" ;; - esac - else - case "$count" in - "") # no upstream - p="" ;; - "0 0") # equal to upstream - p="=" ;; - "0 "*) # ahead of upstream - p="+${count#0 }" ;; - *" 0") # behind upstream - p="-${count% 0}" ;; - *) # diverged from upstream - p="-${count% *}+${count#* }" ;; - esac - fi + # Find how many commits we are ahead/behind our upstream + # produce equivalent output to --count for older versions of git + local ahead behind + if git rev-list --left-right "$upstream"...HEAD >/dev/null 2>&1; then + behind="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null | grep '^<' | wc -l | tr -d ' ' 2>/dev/null)" + ahead="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null | grep '^[^<]' | wc -l | tr -d ' ' 2>/dev/null)" + count="$behind $ahead" + fi - GIT_PROMPT_UPSTREAM_STATE=$p + # calculate the result + if [[ -z "$verbose" ]]; then + case "$count" in + "") # no upstream + p="" ;; + "0 0") # equal to upstream + p="=" ;; + "0 "*) # ahead of upstream + p=">" ;; + *" 0") # behind upstream + p="<" ;; + *) # diverged from upstream + p="<>" ;; + esac + else + case "$count" in + "") # no upstream + p="" ;; + "0 0") # equal to upstream + p="=" ;; + "0 "*) # ahead of upstream + p="+${count#0 }" ;; + *" 0") # behind upstream + p="-${count% 0}" ;; + *) # diverged from upstream + p="-${count% *}+${count#* }" ;; + esac + fi + + GIT_PROMPT_UPSTREAM_STATE=$p } # sets GIT_PROMPT_REBASE_INFO # with info about a rebase/merge/etc if it's in progress. -_git_prompt__rebase_info () +git_prompt__rebase_info () { - GIT_PROMPT_REBASE_INFO='' + GIT_PROMPT_REBASE_INFO='' - if [ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then - return - fi - if [ "$GIT_PROMPT_SHOWREBASEINFO" = 'off' ]; then - return - fi - if [ "$(git config --bool prompt.showRebaseInfo)" = "false" ]; then - return - fi + if [[ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then + return + fi + if [[ "$GIT_PROMPT_SHOWREBASEINFO" = 'off' ]]; then + return + fi + if [[ "$(git config --bool prompt.showRebaseInfo)" = "false" ]]; then + return + fi - local r="" - local g="$(_git_prompt__git_dir)" - if [ -n "$g" ]; then - if [ -f "$g/rebase-merge/interactive" ]; then - r="|REBASE-i" - elif [ -d "$g/rebase-merge" ]; then - r="|REBASE-m" + local r="" + local g="$(git_prompt__git_dir)" + if [[ -n "$g" ]]; then + if [[ -f "$g/rebase-merge/interactive" ]]; then + r="|REBASE-i" + elif [[ -d "$g/rebase-merge" ]]; then + r="|REBASE-m" + else + if [[ -d "$g/rebase-apply" ]]; then + if [[ -f "$g/rebase-apply/rebasing" ]]; then + r="|REBASE" + elif [[ -f "$g/rebase-apply/applying" ]]; then + r="|AM" else - if [ -d "$g/rebase-apply" ]; then - if [ -f "$g/rebase-apply/rebasing" ]; then - r="|REBASE" - elif [ -f "$g/rebase-apply/applying" ]; then - r="|AM" - else - r="|AM/REBASE" - fi - elif [ -f "$g/MERGE_HEAD" ]; then - r="|MERGING" - elif [ -f "$g/CHERRY_PICK_HEAD" ]; then - r="|CHERRY-PICKING" - elif [ -f "$g/BISECT_LOG" ]; then - r="|BISECTING" - fi - + r="|AM/REBASE" fi - fi + elif [[ -f "$g/MERGE_HEAD" ]]; then + r="|MERGING" + elif [[ -f "$g/CHERRY_PICK_HEAD" ]]; then + r="|CHERRY-PICKING" + elif [[ -f "$g/BISECT_LOG" ]]; then + r="|BISECTING" + fi - GIT_PROMPT_REBASE_INFO=$r + fi + fi + + GIT_PROMPT_REBASE_INFO=$r } # sets GIT_PROMPT_BRANCH # with the branch name -_git_prompt__branch () +git_prompt__branch () { - GIT_PROMPT_BRANCH='' + GIT_PROMPT_BRANCH='' - if [ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then - return + if [[ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then + return + fi + + if [[ "$GIT_PROMPT_SHOWBRANCH" = 'off' ]]; then + return + fi + if [[ "$(git config --bool prompt.showBranch)" = "false" ]]; then + return + fi + + local b="" + local g="$(git_prompt__git_dir)" + if [[ -n "$g" ]]; then + if [[ -f "$g/rebase-merge/interactive" ]]; then + b="$(cat "$g/rebase-merge/head-name")" + elif [[ -d "$g/rebase-merge" ]]; then + b="$(cat "$g/rebase-merge/head-name")" + else + b="$(git symbolic-ref HEAD 2>/dev/null)" || { + + b="$( + case "${GIT_PROMPT_DESCRIBE_STYLE-}" in + (contains) + git describe --contains HEAD ;; + (branch) + git describe --contains --all HEAD ;; + (describe) + git describe HEAD ;; + (* | default) + git describe --tags --exact-match HEAD ;; + esac 2>/dev/null)" || + + b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)" || + b="$b" + } fi - - if [ "$GIT_PROMPT_SHOWBRANCH" = 'off' ]; then - return - fi - if [ "$(git config --bool prompt.showBranch)" = "false" ]; then - return + b=${b##refs/heads/} + if [[ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]]; then + if [[ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]]; then + b="BARE:$b" + else + b="GIT_DIR!" + fi fi + fi - local b="" - local g="$(_git_prompt__git_dir)" - if [ -n "$g" ]; then - if [ -f "$g/rebase-merge/interactive" ]; then - b="$(cat "$g/rebase-merge/head-name")" - elif [ -d "$g/rebase-merge" ]; then - b="$(cat "$g/rebase-merge/head-name")" - else - b="$(git symbolic-ref HEAD 2>/dev/null)" || { - - b="$( - case "${GIT_PROMPT_DESCRIBE_STYLE-}" in - (contains) - git describe --contains HEAD ;; - (branch) - git describe --contains --all HEAD ;; - (describe) - git describe HEAD ;; - (* | default) - git describe --tags --exact-match HEAD ;; - esac 2>/dev/null)" || - - b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)" || - b="$b" - } - fi - b=${b##refs/heads/} - if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then - if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then - b="BARE:$b" - else - b="GIT_DIR!" - fi - fi - fi - - GIT_PROMPT_BRANCH=$b + GIT_PROMPT_BRANCH=$b } # sets GIT_PROMPT_STASH_STATE_DIRTY # if the git stash state is dirty -_git_prompt__stash () +git_prompt__stash () { - GIT_PROMPT_STASH_STATE_DIRTY='' + GIT_PROMPT_STASH_STATE_DIRTY='' - if [ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then - return - fi + if [[ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then + return + fi - if [ "$GIT_PROMPT_SHOWSTASHSTATE" = 'off' ]; then - return - fi - if [ "$(git config --bool prompt.showStashState)" = "false" ]; then - return - fi + if [[ "$GIT_PROMPT_SHOWSTASHSTATE" = 'off' ]]; then + return + fi + if [[ "$(git config --bool prompt.showStashState)" = "false" ]]; then + return + fi - if git rev-parse --verify refs/stash >/dev/null 2>&1; then - GIT_PROMPT_STASH_STATE_DIRTY='yes' - else - GIT_PROMPT_STASH_STATE_DIRTY='no' - fi + if git rev-parse --verify refs/stash >/dev/null 2>&1; then + GIT_PROMPT_STASH_STATE_DIRTY='yes' + else + GIT_PROMPT_STASH_STATE_DIRTY='no' + fi } @@ -352,146 +352,146 @@ _git_prompt__stash () # # NOTE: To make the short-circuit logic work, the GIT_PROMPT_INFO_FUNC function # must set a global variable (with your git prompt format), rather than echo it. -# Correct: +# Correct: # -# PROMPT='$__GIT_PROMPT_INFO > ' +# PROMPT='$__GIT_PROMPT_INFO > ' # -# # this function sets $__GIT_PROMPT_INFO -# function update_prompt_func () -# { -# #... -# __GIT_PROMPT_INFO="$info" -# } -# GIT_PROMPT_INFO_FUNC=update_prompt_func +# # this function sets $__GIT_PROMPT_INFO +# function update_prompt_func () +# { +# #... +# __GIT_PROMPT_INFO="$info" +# } +# GIT_PROMPT_INFO_FUNC=update_prompt_func # # Incorrect: -# -# PROMPT='$(update_prompt_func) > ' +# +# PROMPT='$(update_prompt_func) > ' # -# function update_prompt_func () -# { -# #... -# echo "$info" -# } -# GIT_PROMPT_INFO_FUNC=update_prompt_func +# function update_prompt_func () +# { +# #... +# echo "$info" +# } +# GIT_PROMPT_INFO_FUNC=update_prompt_func # local _big_repo='init' __git_prompt_shortcircuit () { - if [[ "$_big_repo" == 'yes' ]]; then - _big_repo='' - if [ "$GIT_PROMPT_SHORTCIRCUIT" != 'off' ]; then - echo "$fg[red]" > /dev/stderr - echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: Looks like you hit ctrl-c." > /dev/stderr - echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: So for this repo I'm setting:" > /dev/stderr - echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: git config prompt.showDirtyState false" > /dev/stderr - echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: On big git repos it takes a long time to get info for your prompt." > /dev/stderr - echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: To revert it, run:" > /dev/stderr - echo "${bold_color}SHELL PROMPT$fg_no_bold[red]:$reset_color git config prompt.showDirtyState true" > /dev/stderr - echo '' > /dev/stderr + if [[ "$_big_repo" == 'yes' ]]; then + _big_repo='' + if [[ "$GIT_PROMPT_SHORTCIRCUIT" != 'off' ]]; then + echo "$fg[red]" > /dev/stderr + echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: Looks like you hit ctrl-c." > /dev/stderr + echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: So for this repo I'm setting:" > /dev/stderr + echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: git config prompt.showDirtyState false" > /dev/stderr + echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: On big git repos it takes a long time to get info for your prompt." > /dev/stderr + echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: To revert it, run:" > /dev/stderr + echo "${bold_color}SHELL PROMPT$fg_no_bold[red]:$reset_color git config prompt.showDirtyState true" > /dev/stderr + echo '' > /dev/stderr - git config prompt.showDirtyState 'false' - $GIT_PROMPT_INFO_FUNC - fi + git config prompt.showDirtyState 'false' + $GIT_PROMPT_INFO_FUNC fi + fi } TRAPINT () { - __git_prompt_shortcircuit - return $(( 128 + $1 )) + __git_prompt_shortcircuit + return $(( 128 + $1 )) } # sets a bunch of variables, see below: -_git_prompt__dirty_state () +git_prompt__dirty_state () { - GIT_PROMPT_DIRTY_STATE_FRESH_REPO='' - GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='' - GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='' - GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='' - GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='' - GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='' - GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='' - GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='' - GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='' - GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='' - GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='' - GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='' + GIT_PROMPT_DIRTY_STATE_FRESH_REPO='' + GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='' + GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='' + GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='' + GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='' + GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='' + GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='' + GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='' + GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='' - if [ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then - return + if [[ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then + return + fi + + local g="$(git_prompt__git_dir)" + if [[ -z "$g" ]]; then + return + fi + if [[ "$GIT_PROMPT_SHOWDIRTYSTATE" = 'off' ]]; then + return + fi + if [[ "$(git config --bool prompt.showDirtyState)" = "false" ]]; then + return + fi + + GIT_PROMPT_DIRTY_STATE_FRESH_REPO='no' + GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='no' + GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='no' + GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='no' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='no' + GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='no' + GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='no' + GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='no' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='no' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='no' + GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='no' + GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='no' + + if git rev-parse --quiet --verify HEAD >/dev/null; then + else + GIT_PROMPT_DIRTY_STATE_FRESH_REPO='yes' + fi + + _big_repo='yes' + local line + while IFS=$'\n' read line; do + if [[ "$line" = M* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' + fi + if [[ "$line" = A* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' + fi + if [[ "$line" = R* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' + fi + if [[ "$line" = C* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' + fi + if [[ "$line" = D* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' fi - local g="$(_git_prompt__git_dir)" - if [ -z "$g" ]; then - return + if [[ "$line" = \?\?* ]]; then + GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='yes' fi - if [ "$GIT_PROMPT_SHOWDIRTYSTATE" = 'off' ]; then - return + if [[ "$line" = ?M* ]]; then + GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='yes' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='yes' fi - if [ "$(git config --bool prompt.showDirtyState)" = "false" ]; then - return + if [[ "$line" = ?D* ]]; then + GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='yes' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='yes' fi - GIT_PROMPT_DIRTY_STATE_FRESH_REPO='no' - GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='no' - GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='no' - GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='no' - GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='no' - GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='no' - GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='no' - GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='no' - GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='no' - GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='no' - GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='no' - GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='no' - - if git rev-parse --quiet --verify HEAD >/dev/null; then - else - GIT_PROMPT_DIRTY_STATE_FRESH_REPO='yes' + if [[ "$line" = UU* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' fi - - _big_repo='yes' - local line - while IFS=$'\n' read line; do - if [[ "$line" = M* ]]; then - GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='yes' - GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' - fi - if [[ "$line" = A* ]]; then - GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='yes' - GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' - fi - if [[ "$line" = R* ]]; then - GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='yes' - GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' - fi - if [[ "$line" = C* ]]; then - GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='yes' - GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' - fi - if [[ "$line" = D* ]]; then - GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='yes' - GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' - fi - - if [[ "$line" = \?\?* ]]; then - GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='yes' - fi - if [[ "$line" = ?M* ]]; then - GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='yes' - GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='yes' - fi - if [[ "$line" = ?D* ]]; then - GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='yes' - GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='yes' - fi - - if [[ "$line" = UU* ]]; then - GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='yes' - GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' - fi - done < <(git status --porcelain 2> /dev/null) - _big_repo='' + done < <(git status --porcelain 2> /dev/null) + _big_repo='' } #------------------ Fast Prompt ------------------ @@ -518,25 +518,25 @@ _git_prompt_info _git_prompt__precmd_update_git_vars() { - if [[ $ZSH_VERSION = *\ 4.2* ]]; then - # some older versions of zsh don't have periodic_functions, so do the - # slow path if that's the case: - $GIT_PROMPT_INFO_FUNC + if [[ $ZSH_VERSION = *\ 4.2* ]]; then + # some older versions of zsh don't have periodic_functions, so do the + # slow path if that's the case: + $GIT_PROMPT_INFO_FUNC - elif [ -n "$__EXECUTED_GIT_COMMAND" ]; then - $GIT_PROMPT_INFO_FUNC - unset __EXECUTED_GIT_COMMAND - fi + elif [[ -n "$__EXECUTED_GIT_COMMAND" ]]; then + $GIT_PROMPT_INFO_FUNC + unset __EXECUTED_GIT_COMMAND + fi } _git_prompt__preexec_update_git_vars () { - case "$1" in - $EDITOR*) __EXECUTED_GIT_COMMAND=1 ;; - g*) __EXECUTED_GIT_COMMAND=1 ;; - rm*) __EXECUTED_GIT_COMMAND=1 ;; - touch*) __EXECUTED_GIT_COMMAND=1 ;; - mkdir*) __EXECUTED_GIT_COMMAND=1 ;; - esac + case "$1" in + $EDITOR*) __EXECUTED_GIT_COMMAND=1 ;; + g*) __EXECUTED_GIT_COMMAND=1 ;; + rm*) __EXECUTED_GIT_COMMAND=1 ;; + touch*) __EXECUTED_GIT_COMMAND=1 ;; + mkdir*) __EXECUTED_GIT_COMMAND=1 ;; + esac } #-------------------------------------------------- diff --git a/themes/ashleydev.zsh-theme b/themes/ashleydev.zsh-theme index 5fcd132ef..83c41dfd6 100644 --- a/themes/ashleydev.zsh-theme +++ b/themes/ashleydev.zsh-theme @@ -48,34 +48,34 @@ fi # git prompt info: # The git prompt plugin will cause $GIT_PROMPT_INFO_FUNC to be called -# when $__GIT_PROMPT_INFO needs to be updated. +# when $_GIT_PROMPT_INFO needs to be updated. GIT_PROMPT_INFO_FUNC="update__GIT_PROMPT_INFO" GIT_PROMPT_SHOWUPSTREAM="verbose" GIT_PROMPT_SHORTCIRCUIT='on' -local __GIT_PROMPT_INFO='' -# will set __GIT_PROMPT_INFO +local _GIT_PROMPT_INFO='' +# will set _GIT_PROMPT_INFO update__GIT_PROMPT_INFO () { - local g="$(_git_prompt__git_dir)" + local g="$(git_prompt__git_dir)" if [ -z "$g" ]; then - __GIT_PROMPT_INFO='' + _GIT_PROMPT_INFO='' return fi - _git_prompt__stash + git_prompt__stash local s=$GIT_PROMPT_STASH_STATE_DIRTY - _git_prompt__upstream + git_prompt__upstream local p=$GIT_PROMPT_UPSTREAM_STATE - _git_prompt__branch + git_prompt__branch local b=$GIT_PROMPT_BRANCH - _git_prompt__rebase_info + git_prompt__rebase_info local r=$GIT_PROMPT_REBASE_INFO - _git_prompt__dirty_state + git_prompt__dirty_state local w=$GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY local i=$GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY local u=$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED @@ -83,7 +83,7 @@ update__GIT_PROMPT_INFO () if [ -z "$b$i$w$u" ]; then if [ -n "$g" ]; then - __GIT_PROMPT_INFO="$R$_Cerror_(Error: bad ./$g dir)$R" + _GIT_PROMPT_INFO="$R$_Cerror_(Error: bad ./$g dir)$R" return fi fi @@ -129,7 +129,7 @@ update__GIT_PROMPT_INFO () _prompt="($_prompt$)" fi - __GIT_PROMPT_INFO="$R$_prompt$R" + _GIT_PROMPT_INFO="$R$_prompt$R" } @@ -140,7 +140,7 @@ 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_# ' +PROMPT='$user_$host_$path_ $_GIT_PROMPT_INFO$jobs_# ' local date_format_='%D{%a %b %d}, %*' local date_="${_Cdate_}[$date_format_]$R" From 8d819d2b074cf84c770365daf6c8242f454b7c5b Mon Sep 17 00:00:00 2001 From: Ashley Dev Date: Thu, 2 Jun 2011 19:46:42 -0700 Subject: [PATCH 58/64] API change, and move the ashleydev format into the plugin as the default format. - usage is now: PROMPT="$(git_prompt_info2) >". The legacy git-prompt-old.theme.zsh is using the git_prompt_info() function name and I don't want to override that so I set mine to git_prompt_info2 --- plugins/git/git-prompt.plugin.zsh | 276 +++++++++++++++++++----------- themes/ashleydev.zsh-theme | 106 +----------- 2 files changed, 177 insertions(+), 205 deletions(-) diff --git a/plugins/git/git-prompt.plugin.zsh b/plugins/git/git-prompt.plugin.zsh index 35bc0e8f5..d47459925 100644 --- a/plugins/git/git-prompt.plugin.zsh +++ b/plugins/git/git-prompt.plugin.zsh @@ -2,7 +2,7 @@ # FILE: git-prompt.plugin.zsh # DESCRIPTION: oh-my-zsh git information for your PROMPT. # AUTHOR: Ashley Dev (the.ashley.dev+git-prompt@gmail.com) -# VERSION: 2.1 +# VERSION: 3.0 # SCREENSHOT: http://i.imgur.com/Yw1KG.png # http://i.imgur.com/wx6MU.png # ------------------------------------------------------------------------------ @@ -18,43 +18,37 @@ # # # this is a simple example PROMPT with only git # # info from this plugin in it: -# PROMPT='$_GIT_PROMPT_INFO# ' +# PROMPT='$(git_prompt_info2)# ' # -# #GIT_PROMPT_SHORTCIRCUIT='off' -# -# # GIT_PROMPT_INFO_FUNC must be set to the -# # function that defines your prompt info -# # in order to turn this plugin on. -# GIT_PROMPT_INFO_FUNC='update__GIT_PROMPT_INFO' -# -# local _GIT_PROMPT_INFO='' -# update__GIT_PROMPT_INFO () +# # if you want to override the default format you can define your own +# # _git_prompt_info() function that sets $_GIT_PROMPT_INFO with your format +# _git_prompt_info () # { # git_prompt__branch -# local b=$GIT_PROMPT_BRANCH +# local branch_=$GIT_PROMPT_BRANCH # # git_prompt__dirty_state -# local w=$GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY -# local i=$GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY +# local work_=$GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY +# local index_=$GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY # # # Reset color # local R="%{$terminfo[sgr0]%}" # -# if [[ "$i" = "yes" ]]; then -# i="%{$bold_color$fg[red]%}+$R" +# if [[ "$index_" = "yes" ]]; then +# index_="%{$bold_color$fg[red]%}+$R" # else -# i="" +# index_="" # fi # -# if [[ -n "$b" ]]; then -# if [[ "$w" = 'yes' ]]; then -# b="%{$fg_no_bold[red]%}$b$R" -# elif [[ "$w" = 'no' ]]; then -# b="%{$fg_no_bold[green]%}$b$R" +# if [[ -n "$branch_" ]]; then +# if [[ "$work_" = 'yes' ]]; then +# branch_="%{$fg_no_bold[red]%}$branch_$R" +# elif [[ "$work_" = 'no' ]]; then +# branch_="%{$fg_no_bold[green]%}$branch_$R" # fi # fi # -# __GIT_PROMPT_INFO="$R($b$i)$R" +# _GIT_PROMPT_INFO="$R($branch_$index_)$R" # } # ----------------------------------------------------------------- # @@ -87,15 +81,17 @@ git_prompt__git_dir () # sets GIT_PROMPT_UPSTREAM_STATE # # output format: -# A "<" indicates you are behind, ">" indicates you are ahead, "<>" -# indicates you have diverged, "=" indicates no divergence, and "" indicates -# there is no upstream or this feature is turned 'off' (see below). +# A "-1" indicates you are behind by one commit, "+3" indicates you are ahead by +# 3 commits, "-1+3" indicates you have diverged, "=" indicates no divergence, +# and "" indicates there is no upstream or this feature is turned 'off' (see +# below). # # You can control behaviour by setting GIT_PROMPT_SHOWUPSTREAM to a # space-separated list of values: # off no output -# verbose show number of commits ahead/behind (+/-) upstream instead -# of using "<" and ">". +# simple Instead of '+/-', a "<" indicates you are behind, ">" +# indicates you are ahead, "<>" indicates you have diverged, +# "=" indicates no divergence. # legacy don't use the '--count' option available in recent # versions of git-rev-list # git always compare HEAD to @{upstream} @@ -104,7 +100,7 @@ git_prompt__git_dir () # if it can find one, or @{upstream} otherwise. Once you have # set GIT_PROMPT_SHOWUPSTREAM, you can override it on a # per-repository basis by setting the prompt.showUpstream config -# variable (i.e. `git config prompt.showUpstream 'verbose legacy'`). +# variable (i.e. `git config prompt.showUpstream 'simple legacy'`). # # git_prompt__upstream accepts 0 or 1 arguments. If an argument is given, it # must be a string of the form specified above for GIT_PROMPT_SHOWUPSTREAM. @@ -120,7 +116,7 @@ git_prompt__upstream () local key value local svn_remote svn_url_pattern count n - local upstream=git legacy="" verbose="" + local upstream=git legacy="" simple="" local p # get some config options from git-config @@ -146,8 +142,8 @@ git_prompt__upstream () case "$option" in off) return ;; git|svn) upstream="$option" ;; - verbose) verbose=1 ;; - legacy) legacy=1 ;; + simple) simple=1 ;; + legacy) legacy=1 ;; esac done @@ -181,7 +177,7 @@ git_prompt__upstream () fi # calculate the result - if [[ -z "$verbose" ]]; then + if [[ -n "$simple" ]]; then case "$count" in "") # no upstream p="" ;; @@ -228,34 +224,34 @@ git_prompt__rebase_info () return fi - local r="" - local g="$(git_prompt__git_dir)" - if [[ -n "$g" ]]; then - if [[ -f "$g/rebase-merge/interactive" ]]; then - r="|REBASE-i" - elif [[ -d "$g/rebase-merge" ]]; then - r="|REBASE-m" + local rebase_="" + local dir_="$(git_prompt__git_dir)" + if [[ -n "$dir_" ]]; then + if [[ -f "$dir_/rebase-merge/interactive" ]]; then + rebase_="|REBASE-i" + elif [[ -d "$dir_/rebase-merge" ]]; then + rebase_="|REBASE-m" else - if [[ -d "$g/rebase-apply" ]]; then - if [[ -f "$g/rebase-apply/rebasing" ]]; then - r="|REBASE" - elif [[ -f "$g/rebase-apply/applying" ]]; then - r="|AM" + if [[ -d "$dir_/rebase-apply" ]]; then + if [[ -f "$dir_/rebase-apply/rebasing" ]]; then + rebase_="|REBASE" + elif [[ -f "$dir_/rebase-apply/applying" ]]; then + rebase_="|AM" else - r="|AM/REBASE" + rebase_="|AM/REBASE" fi - elif [[ -f "$g/MERGE_HEAD" ]]; then - r="|MERGING" - elif [[ -f "$g/CHERRY_PICK_HEAD" ]]; then - r="|CHERRY-PICKING" - elif [[ -f "$g/BISECT_LOG" ]]; then - r="|BISECTING" + elif [[ -f "$dir_/MERGE_HEAD" ]]; then + rebase_="|MERGING" + elif [[ -f "$dir_/CHERRY_PICK_HEAD" ]]; then + rebase_="|CHERRY-PICKING" + elif [[ -f "$dir_/BISECT_LOG" ]]; then + rebase_="|BISECTING" fi fi fi - GIT_PROMPT_REBASE_INFO=$r + GIT_PROMPT_REBASE_INFO=$rebase_ } # sets GIT_PROMPT_BRANCH @@ -275,17 +271,17 @@ git_prompt__branch () return fi - local b="" - local g="$(git_prompt__git_dir)" - if [[ -n "$g" ]]; then - if [[ -f "$g/rebase-merge/interactive" ]]; then - b="$(cat "$g/rebase-merge/head-name")" - elif [[ -d "$g/rebase-merge" ]]; then - b="$(cat "$g/rebase-merge/head-name")" + local branch_="" + local dir_="$(git_prompt__git_dir)" + if [[ -n "$dir_" ]]; then + if [[ -f "$dir_/rebase-merge/interactive" ]]; then + branch_="$(cat "$dir_/rebase-merge/head-name")" + elif [[ -d "$dir_/rebase-merge" ]]; then + branch_="$(cat "$dir_/rebase-merge/head-name")" else - b="$(git symbolic-ref HEAD 2>/dev/null)" || { + branch_="$(git symbolic-ref HEAD 2>/dev/null)" || { - b="$( + branch_="$( case "${GIT_PROMPT_DESCRIBE_STYLE-}" in (contains) git describe --contains HEAD ;; @@ -297,21 +293,21 @@ git_prompt__branch () git describe --tags --exact-match HEAD ;; esac 2>/dev/null)" || - b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)" || - b="$b" + branch_="$(cut -c1-7 "$dir_/HEAD" 2>/dev/null)" || + branch_="$branch_" } fi - b=${b##refs/heads/} + branch_=${branch_##refs/heads/} if [[ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]]; then if [[ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]]; then - b="BARE:$b" + branch_="BARE:$branch_" else - b="GIT_DIR!" + branch_="GIT_DIR!" fi fi fi - GIT_PROMPT_BRANCH=$b + GIT_PROMPT_BRANCH=$branch_ } @@ -349,32 +345,6 @@ git_prompt__stash () # to gather information about a large repository. When this happens the # short-circuit logic will display a warning and turn off the showing of dirty # state in your git prompt (for the local repo only). -# -# NOTE: To make the short-circuit logic work, the GIT_PROMPT_INFO_FUNC function -# must set a global variable (with your git prompt format), rather than echo it. -# Correct: -# -# PROMPT='$__GIT_PROMPT_INFO > ' -# -# # this function sets $__GIT_PROMPT_INFO -# function update_prompt_func () -# { -# #... -# __GIT_PROMPT_INFO="$info" -# } -# GIT_PROMPT_INFO_FUNC=update_prompt_func -# -# Incorrect: -# -# PROMPT='$(update_prompt_func) > ' -# -# function update_prompt_func () -# { -# #... -# echo "$info" -# } -# GIT_PROMPT_INFO_FUNC=update_prompt_func -# local _big_repo='init' __git_prompt_shortcircuit () { @@ -391,7 +361,7 @@ __git_prompt_shortcircuit () echo '' > /dev/stderr git config prompt.showDirtyState 'false' - $GIT_PROMPT_INFO_FUNC + _git_prompt_info fi fi } @@ -421,8 +391,8 @@ git_prompt__dirty_state () return fi - local g="$(git_prompt__git_dir)" - if [[ -z "$g" ]]; then + local dir_="$(git_prompt__git_dir)" + if [[ -z "$dir_" ]]; then return fi if [[ "$GIT_PROMPT_SHOWDIRTYSTATE" = 'off' ]]; then @@ -494,6 +464,108 @@ git_prompt__dirty_state () _big_repo='' } +#------------------ Default Prompt Format ------------------ +# You can override this by defining your own _git_prompt_info in your theme that +# sets $_GIT_PROMPT_INFO. + +# You can override these colors if you like too. + +# Colors ('_C' for color): +if [[ "$DISABLE_COLOR" != "true" ]]; then + # git prompt info colors: + local _Cerror_="%{$fg[yellow]%}" # bad (empty) .git/ directory + local _Cbranch_new_repo_="%{$fg_bold[default]%}" # branch color of new repo + local _Cbranch_clean_="%{$fg_no_bold[green]%}" # branch color when clean + local _Cbranch_dirty_="%{$fg_no_bold[red]%}" # branch color when dirty + local _Crebase_="%{$bold_color$fg[yellow]%}" # rebase info + local _Cindex_="%{$bold_color$fg[red]%}" # index info + local _Cuntracked_clean_="" # untracked files state when clean + local _Cuntracked_dirty_="%{$fg_bold[red]%}" # untracked files state when dirty + local _Cupstream_="%{${fg[cyan]}%}" # upstream info + local _Cstash_="" # stash state + + # Reset formating: + local R="%{$terminfo[sgr0]%}" +fi + +# sets _GIT_PROMPT_INFO +_git_prompt_info () +{ + local dir_="$(git_prompt__git_dir)" + if [ -z "$dir_" ]; then + _GIT_PROMPT_INFO='' + return + fi + + git_prompt__stash + local stash_=$GIT_PROMPT_STASH_STATE_DIRTY + + git_prompt__upstream + local upstream_=$GIT_PROMPT_UPSTREAM_STATE + + git_prompt__branch + local branch_=$GIT_PROMPT_BRANCH + + git_prompt__rebase_info + local rebase_=$GIT_PROMPT_REBASE_INFO + + git_prompt__dirty_state + local work_=$GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY + local index_=$GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY + local untracked_=$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED + local freshy_=$GIT_PROMPT_DIRTY_STATE_FRESH_REPO + + if [ -z "$branch_$index_$work_$untracked_" ]; then + if [ -n "$dir_" ]; then + _GIT_PROMPT_INFO="$R$_Cerror_(Error: bad ./$dir_ dir)$R" + return + fi + fi + + if [ "$stash_" = 'yes' ]; then + stash_="$_Cstash_\$$R" + else + stash_="" + fi + + if [ -n "$upstream_" ]; then + upstream_="$_Cupstream_$upstream_$R" + fi + + if [ "$index_" = "yes" ]; then + index_="$_Cindex_+$R" + else + index_="" + fi + + if [ -n "$branch_" ]; then + if [ "$freshy_" = "yes" ]; then + # this is a fresh repo, nothing here... + branch_="$_Cbranch_new_repo_$branch_$R" + elif [ "$work_" = 'yes' ]; then + branch_="$_Cbranch_dirty_$branch_$R" + elif [ "$work_" = 'no' ]; then + branch_="$_Cbranch_clean_$branch_$R" + fi + fi + + if [ -n "$rebase_" ]; then + rebase_="$_Crebase_$rebase_$R" + fi + + local _prompt="$branch_$rebase_$index_$stash_$upstream_" + # add ( ) around _prompt: + if [ "$untracked_" = "yes" ]; then + _prompt="$_Cuntracked_dirty_($_prompt$_Cuntracked_dirty_)" + elif [ "$untracked_" = "no" ]; then + _prompt="$_Cuntracked_clean_($_prompt$_Cuntracked_clean_)" + else + _prompt="($_prompt)" + fi + + _GIT_PROMPT_INFO="$R$_prompt$R" +} + #------------------ Fast Prompt ------------------ # This section sets up some functions that get called infrequently as possible # and therefore don't slow your prompt down as you are using zsh. @@ -512,8 +584,6 @@ precmd_functions+='_git_prompt__precmd_update_git_vars' chpwd_functions+="_git_prompt_info" PERIOD=15 periodic_functions+="_git_prompt_info" - -_git_prompt_info () { $GIT_PROMPT_INFO_FUNC } _git_prompt_info _git_prompt__precmd_update_git_vars() @@ -521,10 +591,10 @@ _git_prompt__precmd_update_git_vars() if [[ $ZSH_VERSION = *\ 4.2* ]]; then # some older versions of zsh don't have periodic_functions, so do the # slow path if that's the case: - $GIT_PROMPT_INFO_FUNC + _git_prompt_info elif [[ -n "$__EXECUTED_GIT_COMMAND" ]]; then - $GIT_PROMPT_INFO_FUNC + _git_prompt_info unset __EXECUTED_GIT_COMMAND fi } @@ -536,7 +606,11 @@ _git_prompt__preexec_update_git_vars () rm*) __EXECUTED_GIT_COMMAND=1 ;; touch*) __EXECUTED_GIT_COMMAND=1 ;; mkdir*) __EXECUTED_GIT_COMMAND=1 ;; + echo*) __EXECUTED_GIT_COMMAND=1 ;; esac } #-------------------------------------------------- + +git_prompt_info2() { echo $_GIT_PROMPT_INFO } + diff --git a/themes/ashleydev.zsh-theme b/themes/ashleydev.zsh-theme index 83c41dfd6..ed174e653 100644 --- a/themes/ashleydev.zsh-theme +++ b/themes/ashleydev.zsh-theme @@ -3,7 +3,7 @@ # DESCRIPTION: oh-my-zsh prompt theme, shows vi mode, last shell return code, # and verbose git info. # AUTHOR: Ashley Dev (the.ashley.dev+zsh-theme@gmail.com) -# VERSION: 2.1 +# VERSION: 3.0 # SCREENSHOT: http://i.imgur.com/Yw1KG.png # http://i.imgur.com/wx6MU.png # ------------------------------------------------------------------------------ @@ -14,18 +14,6 @@ #-------------------- 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 - # Reset formating: local R="%{$terminfo[sgr0]%}" @@ -44,95 +32,6 @@ if [[ "$DISABLE_COLOR" != "true" ]]; then local _Cvi_mode_="%{$fg_bold[cyan]%}" fi -#----------------------------------------------------- -# git prompt info: - -# 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' - -local _GIT_PROMPT_INFO='' -# will set _GIT_PROMPT_INFO -update__GIT_PROMPT_INFO () -{ - local g="$(git_prompt__git_dir)" - if [ -z "$g" ]; then - _GIT_PROMPT_INFO='' - return - fi - - git_prompt__stash - local s=$GIT_PROMPT_STASH_STATE_DIRTY - - git_prompt__upstream - local p=$GIT_PROMPT_UPSTREAM_STATE - - git_prompt__branch - local b=$GIT_PROMPT_BRANCH - - git_prompt__rebase_info - local r=$GIT_PROMPT_REBASE_INFO - - git_prompt__dirty_state - local w=$GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY - local i=$GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY - local u=$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED - local f=$GIT_PROMPT_DIRTY_STATE_FRESH_REPO - - if [ -z "$b$i$w$u" ]; then - if [ -n "$g" ]; then - _GIT_PROMPT_INFO="$R$_Cerror_(Error: bad ./$g dir)$R" - return - fi - fi - - if [ "$s" = 'yes' ]; then - s="$_Cs_\$$R" - else - s="" - fi - - if [ -n "$p" ]; then - p="$_Cp_$p$R" - fi - - if [ "$i" = "yes" ]; then - i="$_Ci_+$R" - else - i="" - fi - - if [ -n "$b" ]; then - if [ "$f" = "yes" ]; then - # this is a fresh repo, nothing here... - b="$_Cb_new_repo_$b$R" - elif [ "$w" = 'yes' ]; then - b="$_Cb_dirty_$b$R" - elif [ "$w" = 'no' ]; then - b="$_Cb_clean_$b$R" - fi - fi - - if [ -n "$r" ]; then - r="$_Cr_$r$R" - fi - - local _prompt="$b$r$i$s$p" - # add ( ) around _prompt: - if [ "$u" = "yes" ]; then - _prompt="$_Cu_dirty_($_prompt$_Cu_dirty_)" - elif [ "$u" = "no" ]; then - _prompt="$_Cu_clean_($_prompt$_Cu_clean_)" - else - _prompt="($_prompt$)" - fi - - _GIT_PROMPT_INFO="$R$_prompt$R" -} - - #-------------------- PROMPT definition: ---------------------- # local user_="%(!.$_Cuser_root_.$_Cuser_)%n$R" @@ -140,7 +39,7 @@ 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_# ' +PROMPT='$user_$host_$path_ $(git_prompt_info2)$jobs_# ' local date_format_='%D{%a %b %d}, %*' local date_="${_Cdate_}[$date_format_]$R" @@ -150,4 +49,3 @@ RPROMPT='$return_code_$date_' # use the vi-mode oh-my-zsh plugin to get this: MODE_INDICATOR="${_Cvi_mode_}-- CMD MODE -- $R" - From 459ebef612907c823206088430e0d6c478cb03da Mon Sep 17 00:00:00 2001 From: Ashley Dev Date: Fri, 3 Jun 2011 09:35:33 -0700 Subject: [PATCH 59/64] add comment, fix a performance bug when $EDITOR is not set, reformat. --- plugins/git/git-prompt.plugin.zsh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/git/git-prompt.plugin.zsh b/plugins/git/git-prompt.plugin.zsh index d47459925..8fd9364cb 100644 --- a/plugins/git/git-prompt.plugin.zsh +++ b/plugins/git/git-prompt.plugin.zsh @@ -584,6 +584,10 @@ precmd_functions+='_git_prompt__precmd_update_git_vars' chpwd_functions+="_git_prompt_info" PERIOD=15 periodic_functions+="_git_prompt_info" + +# Prime the pump; this will be executed before PROMPT is defined by the theme, So +# make sure the first prompt when the shell is opened has the git info set +# properly. _git_prompt_info _git_prompt__precmd_update_git_vars() @@ -601,16 +605,23 @@ _git_prompt__precmd_update_git_vars() _git_prompt__preexec_update_git_vars () { case "$1" in - $EDITOR*) __EXECUTED_GIT_COMMAND=1 ;; g*) __EXECUTED_GIT_COMMAND=1 ;; rm*) __EXECUTED_GIT_COMMAND=1 ;; touch*) __EXECUTED_GIT_COMMAND=1 ;; mkdir*) __EXECUTED_GIT_COMMAND=1 ;; echo*) __EXECUTED_GIT_COMMAND=1 ;; + $EDITOR*) + if [[ -n "$EDITOR" ]]; then + __EXECUTED_GIT_COMMAND=1 + fi + ;; esac } #-------------------------------------------------- -git_prompt_info2() { echo $_GIT_PROMPT_INFO } +git_prompt_info2() +{ + echo $_GIT_PROMPT_INFO +} From b33e6b6598fe775c592d2562b4c0d3aa4d5c11a3 Mon Sep 17 00:00:00 2001 From: Ashley Dev Date: Fri, 3 Jun 2011 14:30:59 -0700 Subject: [PATCH 60/64] Change the api to use PROMPT='$GIT_PROMPT_INFO# ' instead of PROMPT='$(git_prompt_info)# ' --- plugins/git/git-prompt.plugin.zsh | 59 +++++++++++++++++-------------- themes/ashleydev.zsh-theme | 6 +++- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/plugins/git/git-prompt.plugin.zsh b/plugins/git/git-prompt.plugin.zsh index 8fd9364cb..cba6181c4 100644 --- a/plugins/git/git-prompt.plugin.zsh +++ b/plugins/git/git-prompt.plugin.zsh @@ -16,13 +16,29 @@ # (See the ashleydev theme for more complex usage.) # ---------------------- SAMPLE THEME FILE ------------------------ # -# # this is a simple example PROMPT with only git -# # info from this plugin in it: -# PROMPT='$(git_prompt_info2)# ' +# # GIT_PROMPT_INFO_FUNC has to be set to the function that updates the +# # global GIT_PROMPT_INFO variable(s). The GIT_PROMPT_INFO_FUNC function +# # should be run whenever your prompt should be updated, but no more. This +# # means it won't slow down your prompt when you're doing things that won't +# # change the git info in your prompt. +# # +# # So setting GIT_PROMPT_INFO_FUNC both turns on this plugin on and allows +# # you to set up your own custom git_prompt_format_* function. +# # +# GIT_PROMPT_INFO_FUNC=git_prompt_info_default +# +# # git_prompt_info_default() will set $GIT_PROMPT_INFO, use this variable +# # in your prompt: +# PROMPT='$GIT_PROMPT_INFO# ' # -# # if you want to override the default format you can define your own -# # _git_prompt_info() function that sets $_GIT_PROMPT_INFO with your format -# _git_prompt_info () +# ---------------------- SAMPLE THEME FILE 2 ---------------------- +# # If you want to override the default format you can define your own +# # format function: +# GIT_PROMPT_INFO_FUNC=git_prompt_format_simple +# +# PROMPT='$GIT_PROMPT_INFO# ' +# +# git_prompt_format_simple () # { # git_prompt__branch # local branch_=$GIT_PROMPT_BRANCH @@ -48,7 +64,7 @@ # fi # fi # -# _GIT_PROMPT_INFO="$R($branch_$index_)$R" +# GIT_PROMPT_INFO="$R($branch_$index_)$R" # } # ----------------------------------------------------------------- # @@ -465,10 +481,8 @@ git_prompt__dirty_state () } #------------------ Default Prompt Format ------------------ -# You can override this by defining your own _git_prompt_info in your theme that -# sets $_GIT_PROMPT_INFO. -# You can override these colors if you like too. +# You can override these colors if you like. # Colors ('_C' for color): if [[ "$DISABLE_COLOR" != "true" ]]; then @@ -488,12 +502,12 @@ if [[ "$DISABLE_COLOR" != "true" ]]; then local R="%{$terminfo[sgr0]%}" fi -# sets _GIT_PROMPT_INFO -_git_prompt_info () +# sets GIT_PROMPT_INFO +git_prompt_info_default () { local dir_="$(git_prompt__git_dir)" if [ -z "$dir_" ]; then - _GIT_PROMPT_INFO='' + GIT_PROMPT_INFO='' return fi @@ -517,7 +531,7 @@ _git_prompt_info () if [ -z "$branch_$index_$work_$untracked_" ]; then if [ -n "$dir_" ]; then - _GIT_PROMPT_INFO="$R$_Cerror_(Error: bad ./$dir_ dir)$R" + GIT_PROMPT_INFO="$R$_Cerror_(Error: bad ./$dir_ dir)$R" return fi fi @@ -563,7 +577,7 @@ _git_prompt_info () _prompt="($_prompt)" fi - _GIT_PROMPT_INFO="$R$_prompt$R" + GIT_PROMPT_INFO="$R$_prompt$R" } #------------------ Fast Prompt ------------------ @@ -585,10 +599,10 @@ chpwd_functions+="_git_prompt_info" PERIOD=15 periodic_functions+="_git_prompt_info" -# Prime the pump; this will be executed before PROMPT is defined by the theme, So -# make sure the first prompt when the shell is opened has the git info set -# properly. -_git_prompt_info +_git_prompt_info () +{ + $GIT_PROMPT_INFO_FUNC +} _git_prompt__precmd_update_git_vars() { @@ -618,10 +632,3 @@ _git_prompt__preexec_update_git_vars () esac } -#-------------------------------------------------- - -git_prompt_info2() -{ - echo $_GIT_PROMPT_INFO -} - diff --git a/themes/ashleydev.zsh-theme b/themes/ashleydev.zsh-theme index ed174e653..2d62c7558 100644 --- a/themes/ashleydev.zsh-theme +++ b/themes/ashleydev.zsh-theme @@ -34,12 +34,16 @@ fi #-------------------- 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_info2)$jobs_# ' +# git_prompt_info_default() will set $GIT_PROMPT_INFO +GIT_PROMPT_INFO_FUNC=git_prompt_info_default + +PROMPT='$user_$host_$path_ $GIT_PROMPT_INFO$jobs_# ' local date_format_='%D{%a %b %d}, %*' local date_="${_Cdate_}[$date_format_]$R" From 53da2d86f6bd2cae33430bae54e3badbcd28c794 Mon Sep 17 00:00:00 2001 From: Ashley Dev Date: Fri, 3 Jun 2011 17:37:06 -0700 Subject: [PATCH 61/64] Reorder functions in file, change default format, remove GIT_PROMPT_INFO_FUNC: - Reorder the git-prompt.plugin.zsh functions and file order to make it easier for beginners to scan and find things. - The previous default is now in the ashleydev file and the default format follows the robbierussle original (in bare basic form). - GIT_PROMPT_INFO_FUNC is no longer used. If you want to override the default format just define your own git_prompt_info() function in your theme file that sets what ever global variables you want to use in your prompt. --- plugins/git/git-prompt.plugin.zsh | 456 +++++++++++++----------------- themes/ashleydev.zsh-theme | 94 +++++- 2 files changed, 281 insertions(+), 269 deletions(-) diff --git a/plugins/git/git-prompt.plugin.zsh b/plugins/git/git-prompt.plugin.zsh index cba6181c4..91ea04caa 100644 --- a/plugins/git/git-prompt.plugin.zsh +++ b/plugins/git/git-prompt.plugin.zsh @@ -16,29 +16,15 @@ # (See the ashleydev theme for more complex usage.) # ---------------------- SAMPLE THEME FILE ------------------------ # -# # GIT_PROMPT_INFO_FUNC has to be set to the function that updates the -# # global GIT_PROMPT_INFO variable(s). The GIT_PROMPT_INFO_FUNC function -# # should be run whenever your prompt should be updated, but no more. This -# # means it won't slow down your prompt when you're doing things that won't -# # change the git info in your prompt. -# # -# # So setting GIT_PROMPT_INFO_FUNC both turns on this plugin on and allows -# # you to set up your own custom git_prompt_format_* function. -# # -# GIT_PROMPT_INFO_FUNC=git_prompt_info_default -# -# # git_prompt_info_default() will set $GIT_PROMPT_INFO, use this variable -# # in your prompt: +# # this is a simple example PROMPT with only git +# # info from this plugin in it: # PROMPT='$GIT_PROMPT_INFO# ' # -# ---------------------- SAMPLE THEME FILE 2 ---------------------- +# # ... # # If you want to override the default format you can define your own -# # format function: -# GIT_PROMPT_INFO_FUNC=git_prompt_format_simple -# -# PROMPT='$GIT_PROMPT_INFO# ' -# -# git_prompt_format_simple () +# # git_prompt_info() function that sets $GIT_PROMPT_INFO (or other variables) +# # with your format: +# git_prompt_info () # { # git_prompt__branch # local branch_=$GIT_PROMPT_BRANCH @@ -71,11 +57,140 @@ # +#------------------ Default Prompt Format ------------------ +# You can override this by defining your own git_prompt_info in your theme that +# sets some global variable(s); i.e. $GIT_PROMPT_INFO. +# (See the ashleydev theme for more complex usage). +git_prompt_info () +{ + git_prompt__branch + local branch=$GIT_PROMPT_BRANCH + + git_prompt__dirty_state + local dirty=$GIT_PROMPT_DIRTY_STATE_ANY_DIRTY + + if [[ -n "$branch" ]]; then + local prompt=$branch + + if [[ "$dirty" = 'yes' ]]; then + prompt="$prompt$ZSH_THEME_GIT_PROMPT_DIRTY" + elif [[ "$dirty" = 'no' ]]; then + prompt="$prompt$ZSH_THEME_GIT_PROMPT_CLEAN" + fi + + GIT_PROMPT_INFO="$ZSH_THEME_GIT_PROMPT_PREFIX$prompt$ZSH_THEME_GIT_PROMPT_SUFFIX" + fi +} + #------------------ git information utils ------------------ # For some of the following functions, I borrowed some from: # https://github.com/git/git/blob/master/contrib/completion/git-completion.bash # +# sets a bunch of variables, see below: +git_prompt__dirty_state () +{ + GIT_PROMPT_DIRTY_STATE_ANY_DIRTY='' + GIT_PROMPT_DIRTY_STATE_FRESH_REPO='' + GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='' + GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='' + GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='' + GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='' + GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='' + GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='' + GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='' + GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='' + + if [[ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then + return + fi + + local dir_="$(git_prompt__git_dir)" + if [[ -z "$dir_" ]]; then + return + fi + if [[ "$GIT_PROMPT_SHOWDIRTYSTATE" = 'off' ]]; then + return + fi + if [[ "$(git config --bool prompt.showDirtyState)" = "false" ]]; then + return + fi + + GIT_PROMPT_DIRTY_STATE_ANY_DIRTY='no' + GIT_PROMPT_DIRTY_STATE_FRESH_REPO='no' + GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='no' + GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='no' + GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='no' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='no' + GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='no' + GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='no' + GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='no' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='no' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='no' + GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='no' + GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='no' + + if git rev-parse --quiet --verify HEAD >/dev/null; then + else + GIT_PROMPT_DIRTY_STATE_FRESH_REPO='yes' + fi + + _big_repo='yes' + local line + while IFS=$'\n' read line; do + if [[ "$line" = M* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' + GIT_PROMPT_DIRTY_STATE_ANY_DIRTY='yes' + fi + if [[ "$line" = A* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' + GIT_PROMPT_DIRTY_STATE_ANY_DIRTY='yes' + fi + if [[ "$line" = R* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' + GIT_PROMPT_DIRTY_STATE_ANY_DIRTY='yes' + fi + if [[ "$line" = C* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' + GIT_PROMPT_DIRTY_STATE_ANY_DIRTY='yes' + fi + if [[ "$line" = D* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' + GIT_PROMPT_DIRTY_STATE_ANY_DIRTY='yes' + fi + + if [[ "$line" = \?\?* ]]; then + GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='yes' + GIT_PROMPT_DIRTY_STATE_ANY_DIRTY='yes' + fi + if [[ "$line" = ?M* ]]; then + GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='yes' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='yes' + GIT_PROMPT_DIRTY_STATE_ANY_DIRTY='yes' + fi + if [[ "$line" = ?D* ]]; then + GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='yes' + GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='yes' + GIT_PROMPT_DIRTY_STATE_ANY_DIRTY='yes' + fi + + if [[ "$line" = UU* ]]; then + GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='yes' + GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' + GIT_PROMPT_DIRTY_STATE_ANY_DIRTY='yes' + fi + done < <(git status --porcelain 2> /dev/null) + _big_repo='' +} + # git_prompt__git_dir accepts 0 or 1 arguments (i.e., location) # echos the location of .git repo. # Useful for quickly figuring out if cwd is under a git repo. @@ -351,7 +466,61 @@ git_prompt__stash () fi } +#------------------ Fast Prompt ------------------ +# This section sets up some functions that get called infrequently as possible +# and therefore don't slow your prompt down as you are using zsh. +# +# I borrowed from: http://sebastiancelis.com/2009/nov/16/zsh-prompt-git-users/ +# Enable auto-execution of functions. +typeset -Uga preexec_functions +typeset -Uga precmd_functions +typeset -Uga chpwd_functions +typeset -Uga periodic_functions + +# Append git functions needed for prompt. +preexec_functions+='_git_prompt__preexec_update_git_vars' +precmd_functions+='_git_prompt__precmd_update_git_vars' +chpwd_functions+="_git_prompt_info" +PERIOD=15 +periodic_functions+="_git_prompt_info" + +_git_prompt_info () +{ + if [[ -z $GIT_PROMPT_INFO_DISABLED ]]; then + git_prompt_info + fi +} + +_git_prompt__precmd_update_git_vars() +{ + if [[ $ZSH_VERSION = *\ 4.2* ]]; then + # some older versions of zsh don't have periodic_functions, so do the + # slow path if that's the case: + _git_prompt_info + + elif [[ -n "$__EXECUTED_GIT_COMMAND" ]]; then + _git_prompt_info + unset __EXECUTED_GIT_COMMAND + fi +} +_git_prompt__preexec_update_git_vars () +{ + case "$1" in + g*) __EXECUTED_GIT_COMMAND=1 ;; + rm*) __EXECUTED_GIT_COMMAND=1 ;; + touch*) __EXECUTED_GIT_COMMAND=1 ;; + mkdir*) __EXECUTED_GIT_COMMAND=1 ;; + echo*) __EXECUTED_GIT_COMMAND=1 ;; + $EDITOR*) + if [[ -n "$EDITOR" ]]; then + __EXECUTED_GIT_COMMAND=1 + fi + ;; + esac +} + +#------------------ Short Circuit ------------------ # This is the short-circuit logic: # # Set GIT_PROMPT_SHORTCIRCUIT='off' to turn the short-circuit logic off. @@ -386,249 +555,4 @@ TRAPINT () __git_prompt_shortcircuit return $(( 128 + $1 )) } - -# sets a bunch of variables, see below: -git_prompt__dirty_state () -{ - GIT_PROMPT_DIRTY_STATE_FRESH_REPO='' - GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='' - GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='' - GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='' - GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='' - GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='' - GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='' - GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='' - GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='' - GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='' - GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='' - GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='' - - if [[ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then - return - fi - - local dir_="$(git_prompt__git_dir)" - if [[ -z "$dir_" ]]; then - return - fi - if [[ "$GIT_PROMPT_SHOWDIRTYSTATE" = 'off' ]]; then - return - fi - if [[ "$(git config --bool prompt.showDirtyState)" = "false" ]]; then - return - fi - - GIT_PROMPT_DIRTY_STATE_FRESH_REPO='no' - GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='no' - GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='no' - GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='no' - GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='no' - GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='no' - GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='no' - GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='no' - GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='no' - GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='no' - GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='no' - GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='no' - - if git rev-parse --quiet --verify HEAD >/dev/null; then - else - GIT_PROMPT_DIRTY_STATE_FRESH_REPO='yes' - fi - - _big_repo='yes' - local line - while IFS=$'\n' read line; do - if [[ "$line" = M* ]]; then - GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='yes' - GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' - fi - if [[ "$line" = A* ]]; then - GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='yes' - GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' - fi - if [[ "$line" = R* ]]; then - GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='yes' - GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' - fi - if [[ "$line" = C* ]]; then - GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='yes' - GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' - fi - if [[ "$line" = D* ]]; then - GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='yes' - GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' - fi - - if [[ "$line" = \?\?* ]]; then - GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='yes' - fi - if [[ "$line" = ?M* ]]; then - GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='yes' - GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='yes' - fi - if [[ "$line" = ?D* ]]; then - GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='yes' - GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='yes' - fi - - if [[ "$line" = UU* ]]; then - GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='yes' - GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' - fi - done < <(git status --porcelain 2> /dev/null) - _big_repo='' -} - -#------------------ Default Prompt Format ------------------ - -# You can override these colors if you like. - -# Colors ('_C' for color): -if [[ "$DISABLE_COLOR" != "true" ]]; then - # git prompt info colors: - local _Cerror_="%{$fg[yellow]%}" # bad (empty) .git/ directory - local _Cbranch_new_repo_="%{$fg_bold[default]%}" # branch color of new repo - local _Cbranch_clean_="%{$fg_no_bold[green]%}" # branch color when clean - local _Cbranch_dirty_="%{$fg_no_bold[red]%}" # branch color when dirty - local _Crebase_="%{$bold_color$fg[yellow]%}" # rebase info - local _Cindex_="%{$bold_color$fg[red]%}" # index info - local _Cuntracked_clean_="" # untracked files state when clean - local _Cuntracked_dirty_="%{$fg_bold[red]%}" # untracked files state when dirty - local _Cupstream_="%{${fg[cyan]}%}" # upstream info - local _Cstash_="" # stash state - - # Reset formating: - local R="%{$terminfo[sgr0]%}" -fi - -# sets GIT_PROMPT_INFO -git_prompt_info_default () -{ - local dir_="$(git_prompt__git_dir)" - if [ -z "$dir_" ]; then - GIT_PROMPT_INFO='' - return - fi - - git_prompt__stash - local stash_=$GIT_PROMPT_STASH_STATE_DIRTY - - git_prompt__upstream - local upstream_=$GIT_PROMPT_UPSTREAM_STATE - - git_prompt__branch - local branch_=$GIT_PROMPT_BRANCH - - git_prompt__rebase_info - local rebase_=$GIT_PROMPT_REBASE_INFO - - git_prompt__dirty_state - local work_=$GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY - local index_=$GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY - local untracked_=$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED - local freshy_=$GIT_PROMPT_DIRTY_STATE_FRESH_REPO - - if [ -z "$branch_$index_$work_$untracked_" ]; then - if [ -n "$dir_" ]; then - GIT_PROMPT_INFO="$R$_Cerror_(Error: bad ./$dir_ dir)$R" - return - fi - fi - - if [ "$stash_" = 'yes' ]; then - stash_="$_Cstash_\$$R" - else - stash_="" - fi - - if [ -n "$upstream_" ]; then - upstream_="$_Cupstream_$upstream_$R" - fi - - if [ "$index_" = "yes" ]; then - index_="$_Cindex_+$R" - else - index_="" - fi - - if [ -n "$branch_" ]; then - if [ "$freshy_" = "yes" ]; then - # this is a fresh repo, nothing here... - branch_="$_Cbranch_new_repo_$branch_$R" - elif [ "$work_" = 'yes' ]; then - branch_="$_Cbranch_dirty_$branch_$R" - elif [ "$work_" = 'no' ]; then - branch_="$_Cbranch_clean_$branch_$R" - fi - fi - - if [ -n "$rebase_" ]; then - rebase_="$_Crebase_$rebase_$R" - fi - - local _prompt="$branch_$rebase_$index_$stash_$upstream_" - # add ( ) around _prompt: - if [ "$untracked_" = "yes" ]; then - _prompt="$_Cuntracked_dirty_($_prompt$_Cuntracked_dirty_)" - elif [ "$untracked_" = "no" ]; then - _prompt="$_Cuntracked_clean_($_prompt$_Cuntracked_clean_)" - else - _prompt="($_prompt)" - fi - - GIT_PROMPT_INFO="$R$_prompt$R" -} - -#------------------ Fast Prompt ------------------ -# This section sets up some functions that get called infrequently as possible -# and therefore don't slow your prompt down as you are using zsh. -# -# I borrowed from: http://sebastiancelis.com/2009/nov/16/zsh-prompt-git-users/ - -# Enable auto-execution of functions. -typeset -Uga preexec_functions -typeset -Uga precmd_functions -typeset -Uga chpwd_functions -typeset -Uga periodic_functions - -# Append git functions needed for prompt. -preexec_functions+='_git_prompt__preexec_update_git_vars' -precmd_functions+='_git_prompt__precmd_update_git_vars' -chpwd_functions+="_git_prompt_info" -PERIOD=15 -periodic_functions+="_git_prompt_info" - -_git_prompt_info () -{ - $GIT_PROMPT_INFO_FUNC -} - -_git_prompt__precmd_update_git_vars() -{ - if [[ $ZSH_VERSION = *\ 4.2* ]]; then - # some older versions of zsh don't have periodic_functions, so do the - # slow path if that's the case: - _git_prompt_info - - elif [[ -n "$__EXECUTED_GIT_COMMAND" ]]; then - _git_prompt_info - unset __EXECUTED_GIT_COMMAND - fi -} -_git_prompt__preexec_update_git_vars () -{ - case "$1" in - g*) __EXECUTED_GIT_COMMAND=1 ;; - rm*) __EXECUTED_GIT_COMMAND=1 ;; - touch*) __EXECUTED_GIT_COMMAND=1 ;; - mkdir*) __EXECUTED_GIT_COMMAND=1 ;; - echo*) __EXECUTED_GIT_COMMAND=1 ;; - $EDITOR*) - if [[ -n "$EDITOR" ]]; then - __EXECUTED_GIT_COMMAND=1 - fi - ;; - esac -} - +#---------------------------------------------------- diff --git a/themes/ashleydev.zsh-theme b/themes/ashleydev.zsh-theme index 2d62c7558..de9ba0133 100644 --- a/themes/ashleydev.zsh-theme +++ b/themes/ashleydev.zsh-theme @@ -17,6 +17,18 @@ if [[ "$DISABLE_COLOR" != "true" ]]; then # Reset formating: local R="%{$terminfo[sgr0]%}" + # git prompt info colors: + local _Cerror_="%{$fg[yellow]%}" # bad (empty) .git/ directory + local _Cbranch_new_repo_="%{$fg_bold[default]%}" # branch color of new repo + local _Cbranch_clean_="%{$fg_no_bold[green]%}" # branch color when clean + local _Cbranch_dirty_="%{$fg_no_bold[red]%}" # branch color when dirty + local _Crebase_="%{$bold_color$fg[yellow]%}" # rebase info + local _Cindex_="%{$bold_color$fg[red]%}" # index info + local _Cuntracked_clean_="" # untracked files state when clean + local _Cuntracked_dirty_="%{$fg_bold[red]%}" # untracked files state when dirty + local _Cupstream_="%{${fg[cyan]}%}" # upstream info + local _Cstash_="" # stash state + # PROMPT colors: local _Cuser_root_="%{$fg_bold[yellow]$bg[red]%}" local _Chost_root_="%{$fg[red]%}" @@ -40,9 +52,6 @@ local host_="%(!.$_Chost_root_.$_Chost_)%m$R" local path_="%(!.$_Cpath_root_.$_Cpath_)%~$R" local jobs_="%(1j.$_Cjobs_%j$R.)" -# git_prompt_info_default() will set $GIT_PROMPT_INFO -GIT_PROMPT_INFO_FUNC=git_prompt_info_default - PROMPT='$user_$host_$path_ $GIT_PROMPT_INFO$jobs_# ' local date_format_='%D{%a %b %d}, %*' @@ -53,3 +62,82 @@ RPROMPT='$return_code_$date_' # use the vi-mode oh-my-zsh plugin to get this: MODE_INDICATOR="${_Cvi_mode_}-- CMD MODE -- $R" + + +#-------------------- Git prompt info format: ---------------------- +git_prompt_info () +{ + local dir_="$(git_prompt__git_dir)" + if [ -z "$dir_" ]; then + GIT_PROMPT_INFO='' + return + fi + + git_prompt__stash + local stash_=$GIT_PROMPT_STASH_STATE_DIRTY + + git_prompt__upstream + local upstream_=$GIT_PROMPT_UPSTREAM_STATE + + git_prompt__branch + local branch_=$GIT_PROMPT_BRANCH + + git_prompt__rebase_info + local rebase_=$GIT_PROMPT_REBASE_INFO + + git_prompt__dirty_state + local work_=$GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY + local index_=$GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY + local untracked_=$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED + local freshy_=$GIT_PROMPT_DIRTY_STATE_FRESH_REPO + + if [ -z "$branch_$index_$work_$untracked_" ]; then + if [ -n "$dir_" ]; then + GIT_PROMPT_INFO="$R$_Cerror_(Error: bad ./$dir_ dir)$R" + return + fi + fi + + if [ "$stash_" = 'yes' ]; then + stash_="$_Cstash_\$$R" + else + stash_="" + fi + + if [ -n "$upstream_" ]; then + upstream_="$_Cupstream_$upstream_$R" + fi + + if [ "$index_" = "yes" ]; then + index_="$_Cindex_+$R" + else + index_="" + fi + + if [ -n "$branch_" ]; then + if [ "$freshy_" = "yes" ]; then + # this is a fresh repo, nothing here... + branch_="$_Cbranch_new_repo_$branch_$R" + elif [ "$work_" = 'yes' ]; then + branch_="$_Cbranch_dirty_$branch_$R" + elif [ "$work_" = 'no' ]; then + branch_="$_Cbranch_clean_$branch_$R" + fi + fi + + if [ -n "$rebase_" ]; then + rebase_="$_Crebase_$rebase_$R" + fi + + local _prompt="$branch_$rebase_$index_$stash_$upstream_" + # add ( ) around _prompt: + if [ "$untracked_" = "yes" ]; then + _prompt="$_Cuntracked_dirty_($_prompt$_Cuntracked_dirty_)" + elif [ "$untracked_" = "no" ]; then + _prompt="$_Cuntracked_clean_($_prompt$_Cuntracked_clean_)" + else + _prompt="($_prompt)" + fi + + GIT_PROMPT_INFO="$R$_prompt$R" +} From c661eedfb1263c39b17e35cf99084d745e5f676e Mon Sep 17 00:00:00 2001 From: Ashley Dev Date: Wed, 6 Jul 2011 18:50:15 -0700 Subject: [PATCH 62/64] Fix a bug in the default git_prompt_info () --- plugins/git/git-prompt.plugin.zsh | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/plugins/git/git-prompt.plugin.zsh b/plugins/git/git-prompt.plugin.zsh index 91ea04caa..6984397d8 100644 --- a/plugins/git/git-prompt.plugin.zsh +++ b/plugins/git/git-prompt.plugin.zsh @@ -26,6 +26,11 @@ # # with your format: # git_prompt_info () # { +# if [ -z "$(git_prompt__git_dir)" ]; then +# GIT_PROMPT_INFO='' +# return +# fi +# # git_prompt__branch # local branch_=$GIT_PROMPT_BRANCH # @@ -63,23 +68,26 @@ # (See the ashleydev theme for more complex usage). git_prompt_info () { + if [ -z "$(git_prompt__git_dir)" ]; then + GIT_PROMPT_INFO='' + return + fi + git_prompt__branch local branch=$GIT_PROMPT_BRANCH git_prompt__dirty_state local dirty=$GIT_PROMPT_DIRTY_STATE_ANY_DIRTY - if [[ -n "$branch" ]]; then - local prompt=$branch + local prompt=$branch - if [[ "$dirty" = 'yes' ]]; then - prompt="$prompt$ZSH_THEME_GIT_PROMPT_DIRTY" - elif [[ "$dirty" = 'no' ]]; then - prompt="$prompt$ZSH_THEME_GIT_PROMPT_CLEAN" - fi - - GIT_PROMPT_INFO="$ZSH_THEME_GIT_PROMPT_PREFIX$prompt$ZSH_THEME_GIT_PROMPT_SUFFIX" + if [[ "$dirty" = 'yes' ]]; then + prompt="$prompt$ZSH_THEME_GIT_PROMPT_DIRTY" + elif [[ "$dirty" = 'no' ]]; then + prompt="$prompt$ZSH_THEME_GIT_PROMPT_CLEAN" fi + + GIT_PROMPT_INFO="$ZSH_THEME_GIT_PROMPT_PREFIX$prompt$ZSH_THEME_GIT_PROMPT_SUFFIX" } #------------------ git information utils ------------------ From 723c2c43c8bd9f65fcaed121cc34979cbed97554 Mon Sep 17 00:00:00 2001 From: Ashley Dev Date: Wed, 6 Jul 2011 18:58:59 -0700 Subject: [PATCH 63/64] Change all the themes to use the new git plugin and rm the old git plugin code. --- plugins/git/git-prompt-old.plugin.zsh | 79 -------------------- plugins/git/git.plugin.zsh | 1 - themes/Soliah.zsh-theme | 53 ++++++------- themes/afowler.zsh-theme | 2 +- themes/arrow.zsh-theme | 2 +- themes/aussiegeek.zsh-theme | 2 +- themes/awesomepanda.zsh-theme | 2 +- themes/bira.zsh-theme | 2 +- themes/candy.zsh-theme | 2 +- themes/clean.zsh-theme | 2 +- themes/cloud.zsh-theme | 2 +- themes/dallas.zsh-theme | 2 +- themes/darkblood.zsh-theme | 2 +- themes/daveverwer.zsh-theme | 2 +- themes/dieter.zsh-theme | 2 +- themes/dogenpunk.zsh-theme | 87 ++++++++++++++++------ themes/dst.zsh-theme | 2 +- themes/dstufft.zsh-theme | 33 +++++++-- themes/eastwood.zsh-theme | 33 ++++++--- themes/edvardm.zsh-theme | 2 +- themes/fishy.zsh-theme | 53 ++++++++++--- themes/flazz.zsh-theme | 2 +- themes/fletcherm.zsh-theme | 2 +- themes/frisk.zsh-theme | 2 +- themes/fwalch.zsh-theme | 2 +- themes/gallifrey.zsh-theme | 2 +- themes/gallois.zsh-theme | 33 ++++++--- themes/garyblessington.zsh-theme | 2 +- themes/gentoo.zsh-theme | 2 +- themes/geoffgarside.zsh-theme | 4 +- themes/gozilla.zsh-theme | 60 ++++++++++++--- themes/jbergantine.zsh-theme | 2 +- themes/jonathan.zsh-theme | 62 ++++++++++++---- themes/josh.zsh-theme | 2 +- themes/jreese.zsh-theme | 2 +- themes/jtriley.zsh-theme | 2 +- themes/juanghurtado.zsh-theme | 86 ++++++++++++++------- themes/kardan.zsh-theme | 2 +- themes/kennethreitz.zsh-theme | 2 +- themes/kphoen.zsh-theme | 101 +++++++++++++++---------- themes/lambda.zsh-theme | 2 +- themes/lukerandall.zsh-theme | 2 +- themes/macovsky-ruby.zsh-theme | 2 +- themes/macovsky.zsh-theme | 2 +- themes/maran.zsh-theme | 2 +- themes/mgutz.zsh-theme | 2 +- themes/minimal.zsh-theme | 10 +-- themes/mrtazz.zsh-theme | 2 +- themes/murilasso.zsh-theme | 2 +- themes/muse.zsh-theme | 69 +++++++++++++---- themes/nanotech.zsh-theme | 2 +- themes/obraun.zsh-theme | 2 +- themes/philips.zsh-theme | 2 +- themes/pmcgee.zsh-theme | 2 +- themes/re5et.zsh-theme | 32 +++++++- themes/rgm.zsh-theme | 2 +- themes/risto.zsh-theme | 2 +- themes/rixius.zsh-theme | 2 +- themes/robbyrussell.zsh-theme | 2 +- themes/simple.zsh-theme | 2 +- themes/skaro.zsh-theme | 2 +- themes/sorin.zsh-theme | 103 ++++++++++++++++---------- themes/sporty_256.zsh-theme | 2 +- themes/takashiyoshida.zsh-theme | 2 - themes/theunraveler.zsh-theme | 59 +++++++++++---- themes/thomasjbradley.zsh-theme | 2 +- themes/tjkirch.zsh-theme | 2 +- themes/tonotdo.zsh-theme | 2 +- themes/wezm+.zsh-theme | 2 +- themes/wezm.zsh-theme | 2 +- themes/xiong-chiamiov-plus.zsh-theme | 2 +- 71 files changed, 672 insertions(+), 392 deletions(-) delete mode 100644 plugins/git/git-prompt-old.plugin.zsh diff --git a/plugins/git/git-prompt-old.plugin.zsh b/plugins/git/git-prompt-old.plugin.zsh deleted file mode 100644 index ece86e6d3..000000000 --- a/plugins/git/git-prompt-old.plugin.zsh +++ /dev/null @@ -1,79 +0,0 @@ -# Renders the name of the current branch. -function git_prompt_info() { - local branch=$(git_current_branch) - if [[ -n "$branch" ]]; then - echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${branch}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}" - fi -} - -# Gets the current branch. -function git_current_branch() { - local ref=$(git symbolic-ref HEAD 2> /dev/null) - if [[ -n "$ref" ]]; then - echo "${ref#refs/heads/}" - fi -} - -# Checks if the working tree is dirty. -function parse_git_dirty() { - if [[ -n $(git status -s 2> /dev/null) ]]; then - echo "$ZSH_THEME_GIT_PROMPT_DIRTY" - else - echo "$ZSH_THEME_GIT_PROMPT_CLEAN" - fi -} - -# Checks if there are commits ahead from remote. -function git_prompt_ahead() { - if $(echo "$(git log origin/$(git_current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then - echo "$ZSH_THEME_GIT_PROMPT_AHEAD" - fi -} - -# Formats the prompt string for current git commit short SHA. -function git_prompt_short_sha() { - local sha=$(git rev-parse --short HEAD 2> /dev/null) - if [[ -n "$sha" ]]; then - echo "${ZSH_THEME_GIT_PROMPT_SHA_BEFORE}${sha}${ZSH_THEME_GIT_PROMPT_SHA_AFTER}" - fi -} - -# Formats the prompt string for current git commit long SHA. -function git_prompt_long_sha() { - local sha=$(git rev-parse HEAD 2> /dev/null) - if [[ -n "$sha" ]]; then - echo "${ZSH_THEME_GIT_PROMPT_SHA_BEFORE}${sha}${ZSH_THEME_GIT_PROMPT_SHA_AFTER}" - fi -} - -# Gets the status of the working tree. -function git_prompt_status() { - local indicators line untracked added modified renamed deleted - while IFS=$'\n' read line; do - if [[ "$line" =~ '^\?\? ' ]]; then - [[ -n $untracked ]] && continue || untracked='yes' - indicators="${ZSH_THEME_GIT_PROMPT_UNTRACKED}${indicators}" - fi - if [[ "$line" =~ '^(((A|M|D|T) )|(AD|AM|AT|MM)) ' ]]; then - [[ -n $added ]] && continue || added='yes' - indicators="${ZSH_THEME_GIT_PROMPT_ADDED}${indicators}" - fi - if [[ "$line" =~ '^(( (M|T))|(AM|AT|MM)) ' ]]; then - [[ -n $modified ]] && continue || modified='yes' - indicators="${ZSH_THEME_GIT_PROMPT_MODIFIED}${indicators}" - fi - if [[ "$line" =~ '^R ' ]]; then - [[ -n $renamed ]] && continue || renamed='yes' - indicators="${ZSH_THEME_GIT_PROMPT_RENAMED}${indicators}" - fi - if [[ "$line" =~ '^( D|AD) ' ]]; then - [[ -n $deleted ]] && continue || deleted='yes' - indicators="${ZSH_THEME_GIT_PROMPT_DELETED}${indicators}" - fi - if [[ "$line" =~ '^UU ' ]]; then - [[ -n $unmerged ]] && continue || unmerged='yes' - indicators="${ZSH_THEME_GIT_PROMPT_UNMERGED}${indicators}" - fi - done < <(git status --porcelain 2> /dev/null) - echo $indicators -} diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index bb515c73a..8bfe492bd 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -1,3 +1,2 @@ source $ZSH/plugins/git/git-aliases.plugin.zsh -source $ZSH/plugins/git/git-prompt-old.plugin.zsh source $ZSH/plugins/git/git-prompt.plugin.zsh diff --git a/themes/Soliah.zsh-theme b/themes/Soliah.zsh-theme index e0932c4b5..2f3fbbde1 100644 --- a/themes/Soliah.zsh-theme +++ b/themes/Soliah.zsh-theme @@ -1,14 +1,30 @@ -PROMPT='%{$fg[blue]%}%n%{$reset_color%} on %{$fg[red]%}%M%{$reset_color%} in %{$fg[blue]%}%~%b%{$reset_color%}$(git_time_since_commit)$(check_git_prompt_info) +local R="%{$terminfo[sgr0]%}" + +PROMPT='%{$fg[blue]%}%n$R on %{$fg[red]%}%M$R in %{$fg[blue]%}%~%b$R$GIT_PROMPT_INFO $ ' -ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[white]%}" -ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%})" +git_prompt_info () +{ + if [ -z "$(git_prompt__git_dir)" ]; then + GIT_PROMPT_INFO="($(rvm_gemset)$R)" + return + fi -# Text to display if the branch is dirty -ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}" + local prompt='' -# Text to display if the branch is clean -ZSH_THEME_GIT_PROMPT_CLEAN="" + git_prompt__branch + prompt="%{$fg[white]%}$GIT_PROMPT_BRANCH" + + git_prompt__rebase_info + prompt="${prompt}$GIT_PROMPT_REBASE_INFO" + + git_prompt__dirty_state + if [[ "$GIT_PROMPT_DIRTY_STATE_ANY_DIRTY" = 'yes' ]]; then + prompt="${prompt}%{$fg[red]%}*" + fi + + GIT_PROMPT_INFO="($(rvm_gemset)$(git_time_since_commit)$prompt$R)" +} # Colors vary depending on time lapsed. ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}" @@ -17,24 +33,11 @@ ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}" ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[cyan]%}" -# Git sometimes goes into a detached head state. git_prompt_info doesn't -# return anything in this case. So wrap it in another function and check -# for an empty string. -function check_git_prompt_info() { - if git rev-parse --git-dir > /dev/null 2>&1; then - if [[ -z $(git_prompt_info) ]]; then - echo "%{$fg[magenta]%}detached-head%{$reset_color%})" - else - echo "$(git_prompt_info)" - fi - fi -} - # Determine if we are using a gemset. function rvm_gemset() { GEMSET=`rvm gemset list | grep '=>' | cut -b4-` if [[ -n $GEMSET ]]; then - echo "%{$fg[yellow]%}$GEMSET%{$reset_color%}|" + echo "%{$fg[yellow]%}${GEMSET}$R|" fi } @@ -72,15 +75,15 @@ function git_time_since_commit() { fi if [ "$HOURS" -gt 24 ]; then - echo "($(rvm_gemset)$COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%}|" + echo "$COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m$R|" elif [ "$MINUTES" -gt 60 ]; then - echo "($(rvm_gemset)$COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}|" + echo "$COLOR${HOURS}h${SUB_MINUTES}m$R|" else - echo "($(rvm_gemset)$COLOR${MINUTES}m%{$reset_color%}|" + echo "$COLOR${MINUTES}m$R|" fi else COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL" - echo "($(rvm_gemset)$COLOR~|" + echo "$COLOR~|" fi fi } diff --git a/themes/afowler.zsh-theme b/themes/afowler.zsh-theme index 3a4753fc1..136286d71 100644 --- a/themes/afowler.zsh-theme +++ b/themes/afowler.zsh-theme @@ -2,7 +2,7 @@ if [ $UID -eq 0 ]; then CARETCOLOR="red"; else CARETCOLOR="blue"; fi local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" -PROMPT='%m %{${fg_bold[blue]}%}:: %{$reset_color%}%{${fg[green]}%}%3~ $(git_prompt_info)%{${fg_bold[$CARETCOLOR]}%}»%{${reset_color}%} ' +PROMPT='%m %{${fg_bold[blue]}%}:: %{$reset_color%}%{${fg[green]}%}%3~ $GIT_PROMPT_INFO%{${fg_bold[$CARETCOLOR]}%}»%{${reset_color}%} ' RPS1="${return_code}" diff --git a/themes/arrow.zsh-theme b/themes/arrow.zsh-theme index d62dcdcb9..a2ef03a8f 100644 --- a/themes/arrow.zsh-theme +++ b/themes/arrow.zsh-theme @@ -1,7 +1,7 @@ if [ $UID -eq 0 ]; then NCOLOR="red"; else NCOLOR="yellow"; fi PROMPT='%{$fg[$NCOLOR]%}%c ➤ %{$reset_color%}' -RPROMPT='%{$fg[$NCOLOR]%}%p $(git_prompt_info)%{$reset_color%}' +RPROMPT='%{$fg[$NCOLOR]%}%p $GIT_PROMPT_INFO%{$reset_color%}' ZSH_THEME_GIT_PROMPT_PREFIX="git:" ZSH_THEME_GIT_PROMPT_SUFFIX="" diff --git a/themes/aussiegeek.zsh-theme b/themes/aussiegeek.zsh-theme index c2c7f65b9..2bed46d7b 100644 --- a/themes/aussiegeek.zsh-theme +++ b/themes/aussiegeek.zsh-theme @@ -1,5 +1,5 @@ -PROMPT='$fg_bold[blue][ $fg[red]%t $fg_bold[blue]] $fg_bold[blue] [ $fg[red]%n@%m:%~$(git_prompt_info)$fg[yellow]$(rvm_prompt_info)$fg_bold[blue] ]$reset_color +PROMPT='$fg_bold[blue][ $fg[red]%t $fg_bold[blue]] $fg_bold[blue] [ $fg[red]%n@%m:%~$GIT_PROMPT_INFO$fg[yellow]$(rvm_prompt_info)$fg_bold[blue] ]$reset_color $ ' # git theming ZSH_THEME_GIT_PROMPT_PREFIX="$fg_bold[green](" diff --git a/themes/awesomepanda.zsh-theme b/themes/awesomepanda.zsh-theme index 1915bd13c..3e29ef553 100644 --- a/themes/awesomepanda.zsh-theme +++ b/themes/awesomepanda.zsh-theme @@ -1,6 +1,6 @@ # the svn plugin has to be activated for this to work. -PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%}$(svn_prompt_info)%{$reset_color%}' +PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$GIT_PROMPT_INFO%{$fg_bold[blue]%}$(svn_prompt_info)%{$reset_color%}' ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" diff --git a/themes/bira.zsh-theme b/themes/bira.zsh-theme index 5642eaeb8..437c8c153 100644 --- a/themes/bira.zsh-theme +++ b/themes/bira.zsh-theme @@ -4,7 +4,7 @@ local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" local user_host='%{$terminfo[bold]$fg[green]%}%n@%m%{$reset_color%}' local current_dir='%{$terminfo[bold]$fg[blue]%} %~%{$reset_color%}' local rvm_ruby='%{$fg[red]%}‹$(rvm-prompt i v g)›%{$reset_color%}' -local git_branch='$(git_prompt_info)%{$reset_color%}' +local git_branch='$GIT_PROMPT_INFO%{$reset_color%}' PROMPT="╭─${user_host} ${current_dir} ${rvm_ruby} ${git_branch} ╰─%B$%b " diff --git a/themes/candy.zsh-theme b/themes/candy.zsh-theme index bc125c5ce..28fb2c1ea 100644 --- a/themes/candy.zsh-theme +++ b/themes/candy.zsh-theme @@ -1,4 +1,4 @@ -PROMPT=$'%{$fg_bold[green]%}%n@%m %{$fg[blue]%}%D{[%I:%M:%S]} %{$reset_color%}%{$fg[white]%}[%~]%{$reset_color%} $(git_prompt_info)\ +PROMPT=$'%{$fg_bold[green]%}%n@%m %{$fg[blue]%}%D{[%I:%M:%S]} %{$reset_color%}%{$fg[white]%}[%~]%{$reset_color%} $GIT_PROMPT_INFO\ %{$fg[blue]%}->%{$fg_bold[blue]%} %#%{$reset_color%} ' ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}[" diff --git a/themes/clean.zsh-theme b/themes/clean.zsh-theme index 7ee29cb8c..7ae26bcf9 100644 --- a/themes/clean.zsh-theme +++ b/themes/clean.zsh-theme @@ -1,6 +1,6 @@ if [ $UID -eq 0 ]; then NCOLOR="red"; else NCOLOR="white"; fi -PROMPT='%{$fg[$NCOLOR]%}%B%n%b%{$reset_color%}:%{$fg[blue]%}%B%c/%b%{$reset_color%} $(git_prompt_info)%(!.#.$) ' +PROMPT='%{$fg[$NCOLOR]%}%B%n%b%{$reset_color%}:%{$fg[blue]%}%B%c/%b%{$reset_color%} $GIT_PROMPT_INFO%(!.#.$) ' RPROMPT='[%*]' # git theming diff --git a/themes/cloud.zsh-theme b/themes/cloud.zsh-theme index 4e94f61a7..e4fbbfc6c 100644 --- a/themes/cloud.zsh-theme +++ b/themes/cloud.zsh-theme @@ -1,4 +1,4 @@ -PROMPT='%{$fg_bold[cyan]%}☁ %{$fg_bold[green]%}%p %{$fg[green]%}%c %{$fg_bold[cyan]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}' +PROMPT='%{$fg_bold[cyan]%}☁ %{$fg_bold[green]%}%p %{$fg[green]%}%c %{$fg_bold[cyan]%}$GIT_PROMPT_INFO%{$fg_bold[blue]%} % %{$reset_color%}' ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}[%{$fg[cyan]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" diff --git a/themes/dallas.zsh-theme b/themes/dallas.zsh-theme index eef32e998..c62b92769 100644 --- a/themes/dallas.zsh-theme +++ b/themes/dallas.zsh-theme @@ -8,7 +8,7 @@ DALLAS_CURRENT_RUBY_="%{$fg[white]%}[%{$fg[magenta]%}\$(~/.rvm/bin/rvm-prompt i DALLAS_CURRENT_MACH_="%{$fg[green]%}%m%{$fg[white]%}:%{$reset_color%}" # Grab the current filepath, use shortcuts: ~/Desktop # Append the current git branch, if in a git repository: ~aw@master -DALLAS_CURRENT_LOCA_="%{$fg[cyan]%}%~\$(git_prompt_info)%{$reset_color%}" +DALLAS_CURRENT_LOCA_="%{$fg[cyan]%}%~\$GIT_PROMPT_INFO%{$reset_color%}" # Grab the current username: dallas DALLAS_CURRENT_USER_="%{$fg[red]%}%n%{$reset_color%}" # Use a % for normal users and a # for privelaged (root) users. diff --git a/themes/darkblood.zsh-theme b/themes/darkblood.zsh-theme index 33508fbd2..7c7d2485c 100644 --- a/themes/darkblood.zsh-theme +++ b/themes/darkblood.zsh-theme @@ -1,6 +1,6 @@ # meh. Dark Blood Rewind, a new beginning. -PROMPT=$'%{$fg[red]%}┌[%{$fg_bold[white]%}%n%{$reset_color%}%{$fg[red]%}@%{$fg_bold[white]%}%m%{$reset_color%}%{$fg[red]%}] [%{$fg_bold[white]%}/dev/%y%{$reset_color%}%{$fg[red]%}] %{$(git_prompt_info)%}%(?,,%{$fg[red]%}[%{$fg_bold[white]%}%?%{$reset_color%}%{$fg[red]%}]) +PROMPT=$'%{$fg[red]%}┌[%{$fg_bold[white]%}%n%{$reset_color%}%{$fg[red]%}@%{$fg_bold[white]%}%m%{$reset_color%}%{$fg[red]%}] [%{$fg_bold[white]%}/dev/%y%{$reset_color%}%{$fg[red]%}] %{$GIT_PROMPT_INFO%}%(?,,%{$fg[red]%}[%{$fg_bold[white]%}%?%{$reset_color%}%{$fg[red]%}]) %{$fg[red]%}└[%{$fg_bold[white]%}%~%{$reset_color%}%{$fg[red]%}]>%{$reset_color%} ' PS2=$' %{$fg[red]%}|>%{$reset_color%} ' diff --git a/themes/daveverwer.zsh-theme b/themes/daveverwer.zsh-theme index 89aef926e..d2cd2b46a 100644 --- a/themes/daveverwer.zsh-theme +++ b/themes/daveverwer.zsh-theme @@ -1,7 +1,7 @@ # Copied and modified from the oh-my-zsh theme from geoffgarside # Red server name, green cwd, blue git status -PROMPT='%{$fg[red]%}%m%{$reset_color%}:%{$fg[green]%}%c%{$reset_color%}$(git_prompt_info) %(!.#.$) ' +PROMPT='%{$fg[red]%}%m%{$reset_color%}:%{$fg[green]%}%c%{$reset_color%}$GIT_PROMPT_INFO %(!.#.$) ' ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[blue]%}(" ZSH_THEME_GIT_PROMPT_SUFFIX=")%{$reset_color%}" diff --git a/themes/dieter.zsh-theme b/themes/dieter.zsh-theme index 0a5e9265b..d71a810c1 100644 --- a/themes/dieter.zsh-theme +++ b/themes/dieter.zsh-theme @@ -26,7 +26,7 @@ local host="@${host_repr[$(hostname)]:-$(hostname)}%{$reset_color%}" # Compacted $PWD local pwd="%{$fg[blue]%}%c%{$reset_color%}" -PROMPT='${time} ${user}${host} ${pwd} $(git_prompt_info)' +PROMPT='${time} ${user}${host} ${pwd} $GIT_PROMPT_INFO' # i would prefer 1 icon that shows the "most drastic" deviation from HEAD, # but lets see how this works out diff --git a/themes/dogenpunk.zsh-theme b/themes/dogenpunk.zsh-theme index f4d65ab74..85eec6f03 100644 --- a/themes/dogenpunk.zsh-theme +++ b/themes/dogenpunk.zsh-theme @@ -6,30 +6,70 @@ # SCREENSHOT: coming soon # ----------------------------------------------------------------------------- -MODE_INDICATOR="%{$fg_bold[red]%}❮%{$reset_color%}%{$fg[red]%}❮❮%{$reset_color%}" -local return_status="%{$fg[red]%}%(?..⏎)%{$reset_color%}" +local R="%{$terminfo[sgr0]%}" -PROMPT='%{$fg[blue]%}%m%{$reset_color%}%{$fg_bold[white]%} ओम् %{$reset_color%}%{$fg[cyan]%}%~:%{$reset_color%}$(git_time_since_commit)$(git_prompt_info) -%{$fg[red]%}%!%{$reset_color%} $(prompt_char) ' +MODE_INDICATOR="%{$fg_bold[red]%}❮$R%{$fg[red]%}❮❮$R" +local return_status="%{$fg[red]%}%(?..⏎)$R" -ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[green]%}git%{$reset_color%}@%{$bg[white]%}%{$fg[black]%}" -ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%})" -ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}!%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_CLEAN="" +PROMPT='%{$fg[blue]%}%m$R%{$fg_bold[white]%} ओम् $R%{$fg[cyan]%}%~:$R$GIT_PROMPT_INFO +%{$fg[red]%}%!$R $(prompt_char) ' -RPROMPT='${return_status}$(git_prompt_status)%{$reset_color%}' +git_prompt_info () +{ + if [ -z "$(git_prompt__git_dir)" ]; then + GIT_PROMPT_INFO='' + GIT_RPROMPT_INFO='' + return + fi -ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[green]%} ✚" -ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[blue]%} ✹" -ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%} ✖" -ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[magenta]%} ➜" -ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[yellow]%} ═" -ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%} ✭" + local prompt='' + + git_prompt__branch + prompt="%{$fg_bold[green]%}git$R@%{$bg[white]%}%{$fg[black]%}$GIT_PROMPT_BRANCH" + + git_prompt__rebase_info + prompt="${prompt}$GIT_PROMPT_REBASE_INFO" + + git_prompt__dirty_state + if [[ "$GIT_PROMPT_DIRTY_STATE_ANY_DIRTY" = 'yes' ]]; then + prompt="${prompt}%{$fg[red]%}!" + fi + GIT_PROMPT_INFO="($(git_time_since_commit)$prompt$R)" + + local rprompt='' + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_ADDED" = 'yes' ]]; then + rprompt="%{$fg[green]%} ✚" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[blue]%} ✹" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[blue]%} ✹" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_DELETED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[red]%} ✖" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[red]%} ✖" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[magenta]%} ➜" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[yellow]%} ═" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[cyan]%} ✭" + fi + GIT_RPROMPT_INFO=$rprompt +} + +RPROMPT='${return_status}$GIT_RPROMPT_INFO$R' function prompt_char() { - git branch >/dev/null 2>/dev/null && echo "%{$fg[green]%}±%{$reset_color%}" && return - hg root >/dev/null 2>/dev/null && echo "%{$fg_bold[red]%}☿%{$reset_color%}" && return - echo "%{$fg[cyan]%}◯ %{$reset_color%}" + git branch >/dev/null 2>/dev/null && echo "%{$fg[green]%}±$R" && return + hg root >/dev/null 2>/dev/null && echo "%{$fg_bold[red]%}☿$R" && return + echo "%{$fg[cyan]%}◯ $R" } # Colors vary depending on time lapsed. @@ -40,7 +80,8 @@ ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[cyan]%}" # Determine the time since last commit. If branch is clean, # use a neutral color, otherwise colors will vary according to time. -function git_time_since_commit() { +git_time_since_commit () +{ if git rev-parse --git-dir > /dev/null 2>&1; then # Only proceed if there is actually a commit. if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then @@ -71,15 +112,15 @@ function git_time_since_commit() { fi if [ "$HOURS" -gt 24 ]; then - echo "($COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%}|" + echo "$COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m$R|" elif [ "$MINUTES" -gt 60 ]; then - echo "($COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}|" + echo "$COLOR${HOURS}h${SUB_MINUTES}m$R|" else - echo "($COLOR${MINUTES}m%{$reset_color%}|" + echo "$COLOR${MINUTES}m$R|" fi else COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL" - echo "($COLOR~|" + echo "$COLOR~|" fi fi } diff --git a/themes/dst.zsh-theme b/themes/dst.zsh-theme index 3e2539d57..d7fde7649 100644 --- a/themes/dst.zsh-theme +++ b/themes/dst.zsh-theme @@ -10,7 +10,7 @@ function prompt_char { PROMPT='%(?, ,%{$fg[red]%}FAIL%{$reset_color%} ) -%{$fg[magenta]%}%n%{$reset_color%}@%{$fg[yellow]%}%m%{$reset_color%}: %{$fg_bold[blue]%}%~%{$reset_color%}$(git_prompt_info) +%{$fg[magenta]%}%n%{$reset_color%}@%{$fg[yellow]%}%m%{$reset_color%}: %{$fg_bold[blue]%}%~%{$reset_color%}$GIT_PROMPT_INFO %_ $(prompt_char) ' RPROMPT='%{$fg[green]%}[%*]%{$reset_color%}' diff --git a/themes/dstufft.zsh-theme b/themes/dstufft.zsh-theme index 5a23fcea5..c0326da16 100644 --- a/themes/dstufft.zsh-theme +++ b/themes/dstufft.zsh-theme @@ -9,11 +9,32 @@ function virtualenv_info { } PROMPT=' -%{$fg[magenta]%}%n%{$reset_color%} at %{$fg[yellow]%}%m%{$reset_color%} in %{$fg_bold[green]%}${PWD/#$HOME/~}%{$reset_color%}$(git_prompt_info) +%{$fg[magenta]%}%n%{$reset_color%} at %{$fg[yellow]%}%m%{$reset_color%} in %{$fg_bold[green]%}${PWD/#$HOME/~}%{$reset_color%}$GIT_PROMPT_INFO $(virtualenv_info)$(prompt_char) ' -ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[magenta]%}" -ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[green]%}!" -ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[green]%}?" -ZSH_THEME_GIT_PROMPT_CLEAN="" +git_prompt_info () +{ + if [ -z "$(git_prompt__git_dir)" ]; then + GIT_PROMPT_INFO='' + return + fi + + local prompt="" + git_prompt__branch + prompt=$GIT_PROMPT_BRANCH + + git_prompt__rebase_info + prompt="${prompt}$GIT_PROMPT_REBASE_INFO" + + if [[ -n "$prompt" ]]; then + git_prompt__dirty_state + if [[ "$GIT_PROMPT_DIRTY_STATE_ANY_DIRTY" = 'yes' ]]; then + prompt="$prompt%{$fg[green]%}!" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED" = 'yes' ]]; then + prompt="$prompt%{$fg[green]%}?" + fi + + GIT_PROMPT_INFO=" on %{$fg[magenta]%}$prompt%{$reset_color%}" + fi +} diff --git a/themes/eastwood.zsh-theme b/themes/eastwood.zsh-theme index 8f15f367f..cd8a5dc72 100644 --- a/themes/eastwood.zsh-theme +++ b/themes/eastwood.zsh-theme @@ -3,17 +3,28 @@ if [[ -s ~/.rvm/scripts/rvm ]] ; then RPS1="%{$fg[yellow]%}rvm:%{$reset_color%}%{$fg[red]%}\$(~/.rvm/bin/rvm-prompt)%{$reset_color%} $EPS1" fi -ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}[" -ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_CLEAN="" +local R="%{$terminfo[sgr0]%}" -#Customized git status, oh-my-zsh currently does not allow render dirty status before branch -git_custom_status() { - local cb=$(current_branch) - if [ -n "$cb" ]; then - echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX" - fi +git_prompt_info () +{ + if [ -z "$(git_prompt__git_dir)" ]; then + GIT_PROMPT_INFO='' + return + fi + + git_prompt__branch + local cb=$GIT_PROMPT_BRANCH + + git_prompt__rebase_info + cb="${cb}$GIT_PROMPT_REBASE_INFO" + + local dirty + git_prompt__dirty_state + if [[ "$GIT_PROMPT_DIRTY_STATE_ANY_DIRTY" = 'yes' ]]; then + dirty="%{$fg[red]%}*%{$reset_color%}" + fi + + GIT_PROMPT_INFO="$dirty$R%{$fg[green]%}[$cb]$R" } -PROMPT='$(git_custom_status)%{$fg[cyan]%}[%~% ]%{$reset_color%}%B$%b ' +PROMPT='$GIT_PROMPT_INFO%{$fg[cyan]%}[%~% ]%{$reset_color%}%B$%b ' diff --git a/themes/edvardm.zsh-theme b/themes/edvardm.zsh-theme index f9ca1a9e2..625517239 100644 --- a/themes/edvardm.zsh-theme +++ b/themes/edvardm.zsh-theme @@ -1,4 +1,4 @@ -PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg_bold[white]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}' +PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg_bold[white]%}%c %{$fg_bold[blue]%}$GIT_PROMPT_INFO%{$fg_bold[blue]%} % %{$reset_color%}' ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" diff --git a/themes/fishy.zsh-theme b/themes/fishy.zsh-theme index f9e506cae..6fe339bcf 100644 --- a/themes/fishy.zsh-theme +++ b/themes/fishy.zsh-theme @@ -5,16 +5,47 @@ PROMPT='%n@%m %{$fg[$user_color]%}%~%{$reset_color%}%(!.#.>) ' PROMPT2='%{$fg[red]%}\ %{$reset_color%}' local return_status="%{$fg_bold[red]%}%(?..%?)%{$reset_color%}" -RPROMPT='${return_status}$(git_prompt_info)$(git_prompt_status)%{$reset_color%}' +RPROMPT='${return_status}$GIT_PROMPT_INFO%{$reset_color%}' -ZSH_THEME_GIT_PROMPT_PREFIX=" " -ZSH_THEME_GIT_PROMPT_SUFFIX="" -ZSH_THEME_GIT_PROMPT_DIRTY="" -ZSH_THEME_GIT_PROMPT_CLEAN="" +git_prompt_info () +{ + if [ -z "$(git_prompt__git_dir)" ]; then + GIT_PROMPT_INFO='' + return + fi -ZSH_THEME_GIT_PROMPT_ADDED="%{$fg_bold[green]%}+" -ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg_bold[blue]%}!" -ZSH_THEME_GIT_PROMPT_DELETED="%{$fg_bold[red]%}-" -ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg_bold[magenta]%}>" -ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg_bold[yellow]%}#" -ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[cyan]%}?" + local prompt='' + + git_prompt__branch + prompt=" $GIT_PROMPT_BRANCH" + + git_prompt__rebase_info + prompt="${prompt}$GIT_PROMPT_REBASE_INFO" + + git_prompt__dirty_state + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_ADDED" = 'yes' ]]; then + prompt="${prompt}%{$fg[green]%} +" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED" = 'yes' ]]; then + prompt="${prompt}%{$fg[blue]%} !" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED" = 'yes' ]]; then + prompt="${prompt}%{$fg[blue]%} !" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_DELETED" = 'yes' ]]; then + prompt="${prompt}%{$fg[red]%} -" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED" = 'yes' ]]; then + prompt="${prompt}%{$fg[red]%} -" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED" = 'yes' ]]; then + prompt="${prompt}%{$fg[magenta]%} >" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED" = 'yes' ]]; then + prompt="${prompt}%{$fg[yellow]%} #" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED" = 'yes' ]]; then + prompt="${prompt}%{$fg[cyan]%} ?" + fi + GIT_PROMPT_INFO=$prompt +} diff --git a/themes/flazz.zsh-theme b/themes/flazz.zsh-theme index 280794f2b..d4233a40d 100644 --- a/themes/flazz.zsh-theme +++ b/themes/flazz.zsh-theme @@ -5,7 +5,7 @@ fi local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" -PROMPT='%m%{${fg_bold[magenta]}%} :: %{$reset_color%}%{${fg[green]}%}%3~ $(git_prompt_info)%{${fg_bold[$CARETCOLOR]}%}%#%{${reset_color}%} ' +PROMPT='%m%{${fg_bold[magenta]}%} :: %{$reset_color%}%{${fg[green]}%}%3~ $GIT_PROMPT_INFO%{${fg_bold[$CARETCOLOR]}%}%#%{${reset_color}%} ' RPS1='$(vi_mode_prompt_info) ${return_code}' diff --git a/themes/fletcherm.zsh-theme b/themes/fletcherm.zsh-theme index e96188544..dfa6c444b 100644 --- a/themes/fletcherm.zsh-theme +++ b/themes/fletcherm.zsh-theme @@ -1,5 +1,5 @@ # Copied from old version of tonotdo's theme. LSCOLORS modified. -PROMPT='%{$fg_no_bold[cyan]%}%n%{$fg_no_bold[magenta]%}•%{$fg_no_bold[green]%}%3~$(git_prompt_info)%{$reset_color%}» ' +PROMPT='%{$fg_no_bold[cyan]%}%n%{$fg_no_bold[magenta]%}•%{$fg_no_bold[green]%}%3~$GIT_PROMPT_INFO%{$reset_color%}» ' RPROMPT='[%*]' # git theming diff --git a/themes/frisk.zsh-theme b/themes/frisk.zsh-theme index f181aec90..3d91c0052 100644 --- a/themes/frisk.zsh-theme +++ b/themes/frisk.zsh-theme @@ -1,5 +1,5 @@ PROMPT=$' -%{$fg[blue]%}%/%{$reset_color%} $(git_prompt_info)%{$fg[white]%}[%n@%m]%{$reset_color%} %{$fg[white]%}[%T]%{$reset_color%} +%{$fg[blue]%}%/%{$reset_color%} $GIT_PROMPT_INFO%{$fg[white]%}[%n@%m]%{$reset_color%} %{$fg[white]%}[%T]%{$reset_color%} %{$fg_bold[black]%}>%{$reset_color%} ' PROMPT2="%{$fg_blod[black]%}%_> %{$reset_color%}" diff --git a/themes/fwalch.zsh-theme b/themes/fwalch.zsh-theme index 24edf55c0..0c9c936bd 100644 --- a/themes/fwalch.zsh-theme +++ b/themes/fwalch.zsh-theme @@ -1,4 +1,4 @@ -PROMPT='%{$fg_bold[green]%}%p %{$fg[cyan]%}%c%{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}' +PROMPT='%{$fg_bold[green]%}%p %{$fg[cyan]%}%c%{$fg_bold[blue]%}$GIT_PROMPT_INFO%{$fg_bold[blue]%} % %{$reset_color%}' ZSH_THEME_GIT_PROMPT_PREFIX=" (%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" diff --git a/themes/gallifrey.zsh-theme b/themes/gallifrey.zsh-theme index fce7cb923..598e41510 100644 --- a/themes/gallifrey.zsh-theme +++ b/themes/gallifrey.zsh-theme @@ -1,7 +1,7 @@ # ZSH Theme - Preview: http://img.skitch.com/20091113-qqtd3j8xinysujg5ugrsbr7x1y.jpg local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" -PROMPT='%{$fg[green]%}%m%{$reset_color%} %2~ $(git_prompt_info)%{$reset_color%}%B»%b ' +PROMPT='%{$fg[green]%}%m%{$reset_color%} %2~ $GIT_PROMPT_INFO%{$reset_color%}%B»%b ' RPS1="${return_code}" ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[yellow]%}‹" diff --git a/themes/gallois.zsh-theme b/themes/gallois.zsh-theme index be8fe0999..278435e83 100644 --- a/themes/gallois.zsh-theme +++ b/themes/gallois.zsh-theme @@ -1,19 +1,30 @@ -ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}[" -ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_CLEAN="" +git_prompt_info () +{ + if [ -z "$(git_prompt__git_dir)" ]; then + GIT_PROMPT_INFO='' + return + fi -#Customized git status, oh-my-zsh currently does not allow render dirty status before branch -git_custom_status() { - local cb=$(current_branch) - if [ -n "$cb" ]; then - echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX" - fi + git_prompt__branch + local cb=$GIT_PROMPT_BRANCH + + git_prompt__rebase_info + cb="${cb}$GIT_PROMPT_REBASE_INFO" + + local dirty + git_prompt__dirty_state + if [[ "$GIT_PROMPT_DIRTY_STATE_ANY_DIRTY" = 'yes' ]]; then + dirty="%{$fg[red]%}*%{$reset_color%}" + fi + + local R="%{$terminfo[sgr0]%}" + + GIT_PROMPT_INFO="$dirty$R%{$fg[green]%}[$cb]$R" } #RVM and git settings if [[ -s ~/.rvm/scripts/rvm ]] ; then - RPS1='$(git_custom_status)%{$fg[red]%}[`~/.rvm/bin/rvm-prompt`]%{$reset_color%} $EPS1' + RPS1='$GIT_PROMPT_INFO%{$fg[red]%}[`~/.rvm/bin/rvm-prompt`]%{$reset_color%} $EPS1' fi PROMPT='%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b ' diff --git a/themes/garyblessington.zsh-theme b/themes/garyblessington.zsh-theme index b4f84a71c..27a27e9b1 100644 --- a/themes/garyblessington.zsh-theme +++ b/themes/garyblessington.zsh-theme @@ -1,4 +1,4 @@ -PROMPT='%{$fg[cyan]%}%c%{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%}% %{$reset_color%}: ' +PROMPT='%{$fg[cyan]%}%c%{$fg_bold[blue]%}$GIT_PROMPT_INFO%{$fg_bold[blue]%}% %{$reset_color%}: ' ZSH_THEME_GIT_PROMPT_PREFIX="(%{$fg[blue]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" diff --git a/themes/gentoo.zsh-theme b/themes/gentoo.zsh-theme index cba143d42..be0a6cc0c 100644 --- a/themes/gentoo.zsh-theme +++ b/themes/gentoo.zsh-theme @@ -1,4 +1,4 @@ -PROMPT='%(!.%{$fg_bold[red]%}.%{$fg_bold[green]%}%n@)%m %{$fg_bold[blue]%}%(!.%1~.%~) $(git_prompt_info)%#%{$reset_color%} ' +PROMPT='%(!.%{$fg_bold[red]%}.%{$fg_bold[green]%}%n@)%m %{$fg_bold[blue]%}%(!.%1~.%~) $GIT_PROMPT_INFO%#%{$reset_color%} ' ZSH_THEME_GIT_PROMPT_PREFIX="(" ZSH_THEME_GIT_PROMPT_SUFFIX=") " diff --git a/themes/geoffgarside.zsh-theme b/themes/geoffgarside.zsh-theme index 675ec7206..20a85c1df 100644 --- a/themes/geoffgarside.zsh-theme +++ b/themes/geoffgarside.zsh-theme @@ -1,5 +1,5 @@ -# PROMPT="[%*] %n:%c $(git_prompt_info)%(!.#.$) " -PROMPT='[%*] %{$fg[cyan]%}%n%{$reset_color%}:%{$fg[green]%}%c%{$reset_color%}$(git_prompt_info) %(!.#.$) ' +# PROMPT="[%*] %n:%c $GIT_PROMPT_INFO%(!.#.$) " +PROMPT='[%*] %{$fg[cyan]%}%n%{$reset_color%}:%{$fg[green]%}%c%{$reset_color%}$GIT_PROMPT_INFO %(!.#.$) ' ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[yellow]%}git:(" ZSH_THEME_GIT_PROMPT_SUFFIX=")%{$reset_color%}" diff --git a/themes/gozilla.zsh-theme b/themes/gozilla.zsh-theme index c6b752e9b..ace15be24 100644 --- a/themes/gozilla.zsh-theme +++ b/themes/gozilla.zsh-theme @@ -1,15 +1,51 @@ -PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}' +local R="%{$terminfo[sgr0]%}" -ZSH_THEME_GIT_PROMPT_PREFIX="(" -ZSH_THEME_GIT_PROMPT_SUFFIX=")" -ZSH_THEME_GIT_PROMPT_DIRTY="" -ZSH_THEME_GIT_PROMPT_CLEAN="" +PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$GIT_PROMPT_INFO % $R' +RPROMPT='$GIT_RPROMPT_INFO$R' -RPROMPT='$(git_prompt_status)%{$reset_color%}' +git_prompt_info () +{ + if [ -z "$(git_prompt__git_dir)" ]; then + GIT_PROMPT_INFO='' + GIT_RPROMPT_INFO='' + return + fi -ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[cyan]%} ✈" -ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[yellow]%} ✭" -ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%} ✗" -ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[blue]%} ➦" -ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[magenta]%} ✂" -ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[grey]%} ✱" + local prompt='' + + git_prompt__branch + prompt="$GIT_PROMPT_BRANCH" + + git_prompt__rebase_info + prompt="${prompt}$GIT_PROMPT_REBASE_INFO" + + GIT_PROMPT_INFO="($prompt)" + + local rprompt='' + git_prompt__dirty_state + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_ADDED" = 'yes' ]]; then + rprompt="%{$fg[cyan]%} ✈" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[yellow]%} ✭" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[yellow]%} ✭" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_DELETED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[red]%} ✗" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[red]%} ✗" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[blue]%} ➦" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[magenta]%} ✂" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[grey]%} ✱" + fi + GIT_RPROMPT_INFO=$rprompt +} diff --git a/themes/jbergantine.zsh-theme b/themes/jbergantine.zsh-theme index d84247cff..0232fdb10 100644 --- a/themes/jbergantine.zsh-theme +++ b/themes/jbergantine.zsh-theme @@ -1,4 +1,4 @@ -PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[white]%}$(git_prompt_info)%{$fg_bold[white]%} % %{$reset_color%}' +PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[white]%}$GIT_PROMPT_INFO%{$fg_bold[white]%} % %{$reset_color%}' ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" diff --git a/themes/jonathan.zsh-theme b/themes/jonathan.zsh-theme index 79d0d21ff..491dbd49e 100644 --- a/themes/jonathan.zsh-theme +++ b/themes/jonathan.zsh-theme @@ -32,7 +32,51 @@ preexec () { } -setprompt () { +git_prompt_info () +{ + if [ -z "$(git_prompt__git_dir)" ]; then + GIT_PROMPT_INFO='' + return + fi + + local prompt='' + + git_prompt__branch + prompt=" on %{$fg[green]%}$GIT_PROMPT_BRANCH" + + git_prompt__rebase_info + prompt="${prompt}$GIT_PROMPT_REBASE_INFO%{$terminfo[sgr0]%}" + + git_prompt__dirty_state + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_ADDED" = 'yes' ]]; then + prompt="${prompt}%{$fg[green]%} ✚" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED" = 'yes' ]]; then + prompt="${prompt}%{$fg[blue]%} ✹" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED" = 'yes' ]]; then + prompt="${prompt}%{$fg[blue]%} ✹" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_DELETED" = 'yes' ]]; then + prompt="${prompt}%{$fg[red]%} ✖" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED" = 'yes' ]]; then + prompt="${prompt}%{$fg[red]%} ✖" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED" = 'yes' ]]; then + prompt="${prompt}%{$fg[magenta]%} ➜" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED" = 'yes' ]]; then + prompt="${prompt}%{$fg[yellow]%} ═" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED" = 'yes' ]]; then + prompt="${prompt}%{$fg[cyan]%} ✭" + fi + GIT_PROMPT_INFO=$prompt +} + +setprompt () +{ ### # Need this so the prompt will work. @@ -53,20 +97,6 @@ setprompt () { done PR_NO_COLOUR="%{$terminfo[sgr0]%}" - ### - # Modify Git prompt - ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[green]%}" - ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" - ZSH_THEME_GIT_PROMPT_DIRTY="" - ZSH_THEME_GIT_PROMPT_CLEAN="" - - ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[green]%} ✚" - ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[blue]%} ✹" - ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%} ✖" - ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[magenta]%} ➜" - ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[yellow]%} ═" - ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%} ✭" - ### # See if we can use extended characters to look nicer. @@ -119,7 +149,7 @@ $PR_GREY)$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_URCORNER$PR_SHIFT_OUT\ $PR_CYAN$PR_SHIFT_IN$PR_LLCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\ $PR_YELLOW%D{%H:%M:%S}\ -$PR_LIGHT_BLUE%{$reset_color%}`git_prompt_info``git_prompt_status`$PR_BLUE)$PR_CYAN$PR_SHIFT_IN$PR_HBAR\ +$PR_LIGHT_BLUE%{$reset_color%}$GIT_PROMPT_INFO$PR_BLUE)$PR_CYAN$PR_SHIFT_IN$PR_HBAR\ $PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\ >$PR_NO_COLOUR ' diff --git a/themes/josh.zsh-theme b/themes/josh.zsh-theme index d6c64da8e..b3ed027ed 100644 --- a/themes/josh.zsh-theme +++ b/themes/josh.zsh-theme @@ -31,7 +31,7 @@ function josh_prompt { prompt=" $prompt" done - prompt="%{%F{green}%}$PWD$prompt%{%F{red}%}$(rvm_prompt_info)%{$reset_color%} $(git_prompt_info)" + prompt="%{%F{green}%}$PWD$prompt%{%F{red}%}$(rvm_prompt_info)%{$reset_color%} $GIT_PROMPT_INFO" echo $prompt } diff --git a/themes/jreese.zsh-theme b/themes/jreese.zsh-theme index 0fa6b4ecd..339509239 100644 --- a/themes/jreese.zsh-theme +++ b/themes/jreese.zsh-theme @@ -4,7 +4,7 @@ if [ $UID -eq 0 ]; then NCOLOR="red"; else NCOLOR="green"; fi local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" PROMPT='%{$fg[$NCOLOR]%}%n%{$fg[green]%}@%m%{$reset_color%} %~ \ -$(git_prompt_info)\ +$GIT_PROMPT_INFO\ %{$fg[red]%}%(!.#.»)%{$reset_color%} ' PROMPT2='%{$fg[red]%}\ %{$reset_color%}' RPS1='${return_code}' diff --git a/themes/jtriley.zsh-theme b/themes/jtriley.zsh-theme index 15d77ed23..aad8af24a 100644 --- a/themes/jtriley.zsh-theme +++ b/themes/jtriley.zsh-theme @@ -1,4 +1,4 @@ -#PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}' +#PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$GIT_PROMPT_INFO%{$fg_bold[blue]%} % %{$reset_color%}' PROMPT="%{$fg_bold[cyan]%}%T%{$fg_bold[green]%} %{$fg_bold[white]%}%n%{$fg[magenta]%}@%{$fg_bold[white]%}%m %{$fg_bold[green]%}%d %{$fg_bold[yellow]%}%% %{$reset_color%}" diff --git a/themes/juanghurtado.zsh-theme b/themes/juanghurtado.zsh-theme index 3ca50cee8..4dff6255e 100644 --- a/themes/juanghurtado.zsh-theme +++ b/themes/juanghurtado.zsh-theme @@ -1,6 +1,5 @@ # ------------------------------------------------------------------------ # Juan G. Hurtado oh-my-zsh theme -# (Needs Git plugin for current_branch method) # ------------------------------------------------------------------------ # Color shortcuts @@ -16,31 +15,68 @@ WHITE_BOLD=$fg_bold[white] BLUE_BOLD=$fg_bold[blue] RESET_COLOR=$reset_color -# Format for git_prompt_info() -ZSH_THEME_GIT_PROMPT_PREFIX="" -ZSH_THEME_GIT_PROMPT_SUFFIX="" - -# Format for parse_git_dirty() -ZSH_THEME_GIT_PROMPT_DIRTY=" %{$RED%}(*)" -ZSH_THEME_GIT_PROMPT_CLEAN="" - -# Format for git_prompt_status() -ZSH_THEME_GIT_PROMPT_UNMERGED=" %{$RED%}unmerged" -ZSH_THEME_GIT_PROMPT_DELETED=" %{$RED%}deleted" -ZSH_THEME_GIT_PROMPT_RENAMED=" %{$YELLOW%}renamed" -ZSH_THEME_GIT_PROMPT_MODIFIED=" %{$YELLOW%}modified" -ZSH_THEME_GIT_PROMPT_ADDED=" %{$GREEN%}added" -ZSH_THEME_GIT_PROMPT_UNTRACKED=" %{$WHITE%}untracked" - -# Format for git_prompt_ahead() -ZSH_THEME_GIT_PROMPT_AHEAD=" %{$RED%}(!)" - -# Format for git_prompt_long_sha() and git_prompt_short_sha() -ZSH_THEME_GIT_PROMPT_SHA_BEFORE=" %{$WHITE%}[%{$YELLOW%}" -ZSH_THEME_GIT_PROMPT_SHA_AFTER="%{$WHITE%}]" # Prompt format PROMPT=' -%{$GREEN_BOLD%}%n@%m%{$WHITE%}:%{$YELLOW%}%~%u$(parse_git_dirty)$(git_prompt_ahead)%{$RESET_COLOR%} +%{$GREEN_BOLD%}%n@%m%{$WHITE%}:%{$YELLOW%}%~%u$GIT_PROMPT_INFO%{$RESET_COLOR%} %{$BLUE%}>%{$RESET_COLOR%} ' -RPROMPT='%{$GREEN_BOLD%}$(current_branch)$(git_prompt_short_sha)$(git_prompt_status)%{$RESET_COLOR%}' +RPROMPT='%{$GREEN_BOLD%}$GIT_RPROMPT_INFO%{$RESET_COLOR%}' + +git_prompt_info () +{ + if [ -z "$(git_prompt__git_dir)" ]; then + GIT_PROMPT_INFO='' + GIT_RPROMPT_INFO='' + return + fi + + local dirty='' + git_prompt__dirty_state + if [[ "$GIT_PROMPT_DIRTY_STATE_ANY_DIRTY" = 'yes' ]]; then + dirty=" %{$RED%}(*)" + fi + git_prompt__upstream + if [[ "$GIT_PROMPT_UPSTREAM_STATE" != "=" ]]; then + local upstream=" %{$RED%}($GIT_PROMPT_UPSTREAM_STATE)" + fi + + GIT_PROMPT_INFO="$dirty$upstream" + + git_prompt__branch + local current_branch="$GIT_PROMPT_BRANCH" + + git_prompt__rebase_info + current_branch="${current_branch}$GIT_PROMPT_REBASE_INFO" + + local sha=$(git rev-parse --short HEAD 2> /dev/null) + if [[ -n "$sha" ]]; then + sha=" %{$WHITE%}[%{$YELLOW%}$sha%{$WHITE%}]" + fi + + local git_status='' + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_ADDED" = 'yes' ]]; then + git_status="%{$GREEN%} added" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED" = 'yes' ]]; then + git_status="${git_status}%{$YELLOW%} modified" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED" = 'yes' ]]; then + git_status="${git_status}%{$YELLOW%} modified" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_DELETED" = 'yes' ]]; then + git_status="${git_status}%{$RED%} deleted" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED" = 'yes' ]]; then + git_status="${git_status}%{$RED%} deleted" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED" = 'yes' ]]; then + git_status="${git_status}%{$YELLOW%} renamed" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED" = 'yes' ]]; then + git_status="${git_status}%{$RED%} unmerged" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED" = 'yes' ]]; then + git_status="${git_status}%{$WHITE%} untracked" + fi + GIT_RPROMPT_INFO="$current_branch$sha$git_status" +} diff --git a/themes/kardan.zsh-theme b/themes/kardan.zsh-theme index 59c938037..33002a8e1 100644 --- a/themes/kardan.zsh-theme +++ b/themes/kardan.zsh-theme @@ -5,7 +5,7 @@ function get_host { } PROMPT='> ' -RPROMPT='%~$(git_prompt_info)$(get_host)' +RPROMPT='%~$GIT_PROMPT_INFO$(get_host)' ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[yellow]%}✗%{$reset_color%}" ZSH_THEME_GIT_PROMPT_PREFIX="(" diff --git a/themes/kennethreitz.zsh-theme b/themes/kennethreitz.zsh-theme index 109be0c22..897e243d2 100644 --- a/themes/kennethreitz.zsh-theme +++ b/themes/kennethreitz.zsh-theme @@ -1,7 +1,7 @@ local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" PROMPT='%{$fg[green]%}%c \ -$(git_prompt_info)\ +$GIT_PROMPT_INFO\ %{$fg[red]%}%(!.#.»)%{$reset_color%} ' PROMPT2='%{$fg[red]%}\ %{$reset_color%}' RPS1='%{$fg[blue]%}%~%{$reset_color%} ${return_code} ' diff --git a/themes/kphoen.zsh-theme b/themes/kphoen.zsh-theme index 0e9b5e73c..6c3b216e4 100644 --- a/themes/kphoen.zsh-theme +++ b/themes/kphoen.zsh-theme @@ -6,45 +6,66 @@ # SCREENSHOT: # ------------------------------------------------------------------------------ - if [[ "$TERM" != "dumb" ]] && [[ "$DISABLE_LS_COLORS" != "true" ]]; then - PROMPT='[%{$fg[red]%}%n%{$reset_color%}@%{$fg[magenta]%}%m%{$reset_color%}:%{$fg[blue]%}%~%{$reset_color%}$(git_prompt_info)] -%# ' - - ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[green]%}" - ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" - ZSH_THEME_GIT_PROMPT_DIRTY="" - ZSH_THEME_GIT_PROMPT_CLEAN="" - - # display exitcode on the right when >0 - return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" - - RPROMPT='${return_code}$(git_prompt_status)%{$reset_color%}' - - ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[green]%} ✚" - ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[blue]%} ✹" - ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%} ✖" - ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[magenta]%} ➜" - ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[yellow]%} ═" - ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%} ✭" -else - PROMPT='[%n@%m:%~$(git_prompt_info)] -%# ' - - ZSH_THEME_GIT_PROMPT_PREFIX=" on" - ZSH_THEME_GIT_PROMPT_SUFFIX="" - ZSH_THEME_GIT_PROMPT_DIRTY="" - ZSH_THEME_GIT_PROMPT_CLEAN="" - - # display exitcode on the right when >0 - return_code="%(?..%? ↵)" - - RPROMPT='${return_code}$(git_prompt_status)' - - ZSH_THEME_GIT_PROMPT_ADDED=" ✚" - ZSH_THEME_GIT_PROMPT_MODIFIED=" ✹" - ZSH_THEME_GIT_PROMPT_DELETED=" ✖" - ZSH_THEME_GIT_PROMPT_RENAMED=" ➜" - ZSH_THEME_GIT_PROMPT_UNMERGED=" ═" - ZSH_THEME_GIT_PROMPT_UNTRACKED=" ✭" + local R="%{$terminfo[sgr0]%}" + local MAGENTA="%{$fg[magenta]%}" + local YELLOW="%{$fg[yellow]%}" + local GREEN="%{$fg[green]%}" + local BLUE="%{$fg[blue]%}" + local CYAN="%{$fg[cyan]%}" + local RED="%{$fg[red]%}" fi + +PROMPT='[$RED%n$R@$MAGENTA%m$R:$BLUE%~$R$GIT_PROMPT_INFO] +%# ' + +# display exitcode on the right when >0 +return_code="%(?..$RED%? ↵$R)" +RPROMPT='${return_code}$GIT_RPROMPT_INFO$R' + +git_prompt_info () +{ + if [ -z "$(git_prompt__git_dir)" ]; then + GIT_PROMPT_INFO='' + GIT_RPROMPT_INFO='' + return + fi + + local branch='' + + git_prompt__branch + branch="$GIT_PROMPT_BRANCH" + + git_prompt__rebase_info + branch="${branch}$GIT_PROMPT_REBASE_INFO" + + GIT_PROMPT_INFO=" on $GREEN${branch}$R" + + local rprompt='' + git_prompt__dirty_state + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_ADDED" = 'yes' ]]; then + rprompt="$GREEN ✚" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED" = 'yes' ]]; then + rprompt="${rprompt}$BLUE ✹" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED" = 'yes' ]]; then + rprompt="${rprompt}$BLUE ✹" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_DELETED" = 'yes' ]]; then + rprompt="${rprompt}$RED ✖" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED" = 'yes' ]]; then + rprompt="${rprompt}$RED ✖" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED" = 'yes' ]]; then + rprompt="${rprompt}$MAGENTA ➜" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED" = 'yes' ]]; then + rprompt="${rprompt}$YELLOW ═" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED" = 'yes' ]]; then + rprompt="${rprompt}$CYAN ✭" + fi + GIT_RPROMPT_INFO=$rprompt +} diff --git a/themes/lambda.zsh-theme b/themes/lambda.zsh-theme index 63292d331..56f1ab5b8 100644 --- a/themes/lambda.zsh-theme +++ b/themes/lambda.zsh-theme @@ -1,6 +1,6 @@ # ZSH Theme - Preview: http://cl.ly/350F0F0k1M2y3A2i3p1S -PROMPT='λ %~/ $(git_prompt_info)%{$reset_color%}' +PROMPT='λ %~/ $GIT_PROMPT_INFO%{$reset_color%}' ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " diff --git a/themes/lukerandall.zsh-theme b/themes/lukerandall.zsh-theme index 24a0612b7..54007aa79 100644 --- a/themes/lukerandall.zsh-theme +++ b/themes/lukerandall.zsh-theme @@ -3,7 +3,7 @@ local return_code="%(?..%{$fg_bold[red]%}%? ↵%{$reset_color%})" -PROMPT='%{$fg_bold[green]%}%n@%m%{$reset_color%} %{$fg_bold[blue]%}%2~%{$reset_color%} $(git_prompt_info)%{$reset_color%}%B»%b ' +PROMPT='%{$fg_bold[green]%}%n@%m%{$reset_color%} %{$fg_bold[blue]%}%2~%{$reset_color%} $GIT_PROMPT_INFO%{$reset_color%}%B»%b ' RPS1="${return_code}" ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[yellow]%}(" diff --git a/themes/macovsky-ruby.zsh-theme b/themes/macovsky-ruby.zsh-theme index 4eb410233..be4e8d512 100644 --- a/themes/macovsky-ruby.zsh-theme +++ b/themes/macovsky-ruby.zsh-theme @@ -1,7 +1,7 @@ # ZSH Theme - Preview: http://gyazo.com/8becc8a7ed5ab54a0262a470555c3eed.png local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" -PROMPT='%{$fg[green]%}%~%{$reset_color%} %{$fg[red]%}‹$(~/.rvm/bin/rvm-prompt i v)› %{$reset_color%} $(git_prompt_info)%{$reset_color%}%B$%b ' +PROMPT='%{$fg[green]%}%~%{$reset_color%} %{$fg[red]%}‹$(~/.rvm/bin/rvm-prompt i v)› %{$reset_color%} $GIT_PROMPT_INFO%{$reset_color%}%B$%b ' RPS1="${return_code}" ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[yellow]%}‹" diff --git a/themes/macovsky.zsh-theme b/themes/macovsky.zsh-theme index 4eb410233..be4e8d512 100644 --- a/themes/macovsky.zsh-theme +++ b/themes/macovsky.zsh-theme @@ -1,7 +1,7 @@ # ZSH Theme - Preview: http://gyazo.com/8becc8a7ed5ab54a0262a470555c3eed.png local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" -PROMPT='%{$fg[green]%}%~%{$reset_color%} %{$fg[red]%}‹$(~/.rvm/bin/rvm-prompt i v)› %{$reset_color%} $(git_prompt_info)%{$reset_color%}%B$%b ' +PROMPT='%{$fg[green]%}%~%{$reset_color%} %{$fg[red]%}‹$(~/.rvm/bin/rvm-prompt i v)› %{$reset_color%} $GIT_PROMPT_INFO%{$reset_color%}%B$%b ' RPS1="${return_code}" ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[yellow]%}‹" diff --git a/themes/maran.zsh-theme b/themes/maran.zsh-theme index 6fba04688..e196cd8d6 100644 --- a/themes/maran.zsh-theme +++ b/themes/maran.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]%}%/%{$reset_color%} $(git_prompt_info) %(!.#.$) ' +PROMPT='%{$fg[cyan]%}%n%{$reset_color%}@%{$fg[yellow]%}%M:%{$fg[green]%}%/%{$reset_color%} $GIT_PROMPT_INFO %(!.#.$) ' ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[cyan]%}git:(" ZSH_THEME_GIT_PROMPT_SUFFIX=")%{$reset_color%}" diff --git a/themes/mgutz.zsh-theme b/themes/mgutz.zsh-theme index dcf327041..b3fb8767e 100644 --- a/themes/mgutz.zsh-theme +++ b/themes/mgutz.zsh-theme @@ -1,4 +1,4 @@ -PROMPT='%{$fg_bold[magenta]%}%1~$(git_prompt_info) %{$fg_bold[magenta]%}%# %{$reset_color%}' +PROMPT='%{$fg_bold[magenta]%}%1~$GIT_PROMPT_INFO %{$fg_bold[magenta]%}%# %{$reset_color%}' ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[yellow]%}[" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" diff --git a/themes/minimal.zsh-theme b/themes/minimal.zsh-theme index d3c9e3663..eb999d3cf 100644 --- a/themes/minimal.zsh-theme +++ b/themes/minimal.zsh-theme @@ -3,13 +3,5 @@ ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}" ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}●%{$reset_color%}" ZSH_THEME_GIT_PROMPT_CLEAN="" -#Customized git status, oh-my-zsh currently does not allow render dirty status before branch -git_custom_status() { - local cb=$(current_branch) - if [ -n "$cb" ]; then - echo "- $ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX" - fi -} - -PROMPT='%2~ $(git_custom_status) »%b ' +PROMPT='%2~ $GIT_PROMPT_INFO »%b ' diff --git a/themes/mrtazz.zsh-theme b/themes/mrtazz.zsh-theme index 214ba5a47..d73e1ad7e 100644 --- a/themes/mrtazz.zsh-theme +++ b/themes/mrtazz.zsh-theme @@ -1,5 +1,5 @@ PROMPT='%{$fg_bold[red]%}%m%{$reset_color%}:%{$fg[cyan]%}%c%{$reset_color%}:%# ' -RPROMPT='%{$fg_bold[green]%}$(git_prompt_info)%{$reset_color%}% ' +RPROMPT='%{$fg_bold[green]%}$GIT_PROMPT_INFO%{$reset_color%}% ' ZSH_THEME_GIT_PROMPT_PREFIX="<%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" diff --git a/themes/murilasso.zsh-theme b/themes/murilasso.zsh-theme index 310357b45..9bf5e0b24 100644 --- a/themes/murilasso.zsh-theme +++ b/themes/murilasso.zsh-theme @@ -2,7 +2,7 @@ local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" local user_host='%{$terminfo[bold]$fg[green]%}%n@%m%{$reset_color%}' local current_dir='%{$terminfo[bold]$fg[blue]%}%~%{$reset_color%}' local rvm_ruby='%{$fg[red]%}$(rvm_prompt_info)%{$reset_color%}' -local git_branch='%{$fg[blue]%}$(git_prompt_info)%{$reset_color%}' +local git_branch='%{$fg[blue]%}$GIT_PROMPT_INFO%{$reset_color%}' PROMPT="${user_host}:${current_dir} ${rvm_ruby} ${git_branch} %B$%b " diff --git a/themes/muse.zsh-theme b/themes/muse.zsh-theme index 4bd8fb825..83f42431f 100644 --- a/themes/muse.zsh-theme +++ b/themes/muse.zsh-theme @@ -1,30 +1,71 @@ #!/usr/bin/env zsh -#local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" +local R="%{$terminfo[sgr0]%}" +#local return_code="%(?..%{$fg[red]%}%? ↵$R)" setopt promptsubst autoload -U add-zsh-hook -PROMPT_SUCCESS_COLOR=$FG[117] PROMPT_FAILURE_COLOR=$FG[124] PROMPT_VCS_INFO_COLOR=$FG[242] PROMPT_PROMPT=$FG[077] GIT_DIRTY_COLOR=$FG[133] GIT_CLEAN_COLOR=$FG[118] -GIT_PROMPT_INFO=$FG[012] +GIT_PROMPT_DEFAULT=$FG[012] -PROMPT='%{$PROMPT_SUCCESS_COLOR%}%~%{$reset_color%} %{$GIT_PROMPT_INFO%}$(git_prompt_info)%{$GIT_DIRTY_COLOR%}$(git_prompt_status) %{$reset_color%}%{$PROMPT_PROMPT%}ᐅ%{$reset_color%} ' +PROMPT='%{$FG[117]%}%~ $GIT_PROMPT_INFO $R%{$PROMPT_PROMPT%}ᐅ$R ' #RPS1="${return_code}" -ZSH_THEME_GIT_PROMPT_PREFIX="(" -ZSH_THEME_GIT_PROMPT_SUFFIX="%{$GIT_PROMPT_INFO%})" -ZSH_THEME_GIT_PROMPT_DIRTY=" %{$GIT_DIRTY_COLOR%}✘" -ZSH_THEME_GIT_PROMPT_CLEAN=" %{$GIT_CLEAN_COLOR%}✔" +git_prompt_info () +{ + if [ -z "$(git_prompt__git_dir)" ]; then + GIT_PROMPT_INFO='' + GIT_RPROMPT_INFO='' + return + fi -ZSH_THEME_GIT_PROMPT_ADDED="%{$FG[082]%}✚%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_MODIFIED="%{$FG[166]%}✹%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_DELETED="%{$FG[160]%}✖%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_RENAMED="%{$FG[220]%}➜%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_UNMERGED="%{$FG[082]%}═%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$FG[190]%}✭%{$reset_color%}" + local branch='' + + git_prompt__branch + branch="$GIT_PROMPT_BRANCH" + + git_prompt__rebase_info + branch="${branch}$GIT_PROMPT_REBASE_INFO" + + local dirty='' + git_prompt__dirty_state + if [[ "$GIT_PROMPT_DIRTY_STATE_ANY_DIRTY" = 'yes' ]]; then + dirty=" %{$GIT_DIRTY_COLOR%}✘" + else + dirty=" %{$GIT_CLEAN_COLOR%}✔" + fi + + local prompt="($R%{${branch}${dirty}%{$FG[012]%})" + + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_ADDED" = 'yes' ]]; then + prompt="${prompt}%{$FG[082]%}✚" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED" = 'yes' ]]; then + prompt="${prompt}%{$FG[166]%}✹" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED" = 'yes' ]]; then + prompt="${prompt}%{$FG[166]%}✹" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_DELETED" = 'yes' ]]; then + prompt="${prompt}%{$FG[160]%}✖" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED" = 'yes' ]]; then + prompt="${prompt}%{$FG[160]%}✖" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED" = 'yes' ]]; then + prompt="${prompt}%{$FG[220]%}➜" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED" = 'yes' ]]; then + prompt="${prompt}%{$FG[082]%}═" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED" = 'yes' ]]; then + prompt="${prompt}%{$FG[90]%}✭" + fi + GIT_PROMPT_INFO="$prompt$R" +} diff --git a/themes/nanotech.zsh-theme b/themes/nanotech.zsh-theme index 5d3331639..4bd1e876a 100644 --- a/themes/nanotech.zsh-theme +++ b/themes/nanotech.zsh-theme @@ -1,5 +1,5 @@ PROMPT='%F{green}%2c%F{blue} [%f ' -RPROMPT='$(git_prompt_info) %F{blue}] %F{green}%D{%L:%M} %F{yellow}%D{%p}%f' +RPROMPT='$GIT_PROMPT_INFO %F{blue}] %F{green}%D{%L:%M} %F{yellow}%D{%p}%f' ZSH_THEME_GIT_PROMPT_PREFIX="%F{yellow}" ZSH_THEME_GIT_PROMPT_SUFFIX="%f" diff --git a/themes/obraun.zsh-theme b/themes/obraun.zsh-theme index 08d137665..096fc470e 100644 --- a/themes/obraun.zsh-theme +++ b/themes/obraun.zsh-theme @@ -2,7 +2,7 @@ if [ "$(whoami)" = "root" ]; then CARETCOLOR="red"; else CARETCOLOR="blue"; fi local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" -PROMPT='%{$fg[green]%}[%*]%{$reset_color%} %{$fg_no_bold[cyan]%}%n %{${fg_bold[blue]}%}::%{$reset_color%} %{$fg[yellow]%}%m%{$reset_color%} %{$fg_no_bold[magenta]%} ➜ %{$reset_color%} %{${fg[green]}%}%3~ $(git_prompt_info)%{${fg_bold[$CARETCOLOR]}%}»%{${reset_color}%} ' +PROMPT='%{$fg[green]%}[%*]%{$reset_color%} %{$fg_no_bold[cyan]%}%n %{${fg_bold[blue]}%}::%{$reset_color%} %{$fg[yellow]%}%m%{$reset_color%} %{$fg_no_bold[magenta]%} ➜ %{$reset_color%} %{${fg[green]}%}%3~ $GIT_PROMPT_INFO%{${fg_bold[$CARETCOLOR]}%}»%{${reset_color}%} ' RPS1="${return_code}" diff --git a/themes/philips.zsh-theme b/themes/philips.zsh-theme index e7ea51a2f..86c682e81 100644 --- a/themes/philips.zsh-theme +++ b/themes/philips.zsh-theme @@ -1,6 +1,6 @@ if [ $UID -eq 0 ]; then NCOLOR="red"; else NCOLOR="green"; fi -PROMPT='%{$fg[$NCOLOR]%}%B%n%b%{$reset_color%}:%{$fg[blue]%}%B%c/%b%{$reset_color%} $(git_prompt_info)%(!.#.$) ' +PROMPT='%{$fg[$NCOLOR]%}%B%n%b%{$reset_color%}:%{$fg[blue]%}%B%c/%b%{$reset_color%} $GIT_PROMPT_INFO%(!.#.$) ' RPROMPT='[%*]' # git theming diff --git a/themes/pmcgee.zsh-theme b/themes/pmcgee.zsh-theme index e4e45c71a..ded6c2fc8 100644 --- a/themes/pmcgee.zsh-theme +++ b/themes/pmcgee.zsh-theme @@ -2,7 +2,7 @@ if [ $UID -eq 0 ]; then NCOLOR="red"; else NCOLOR="green"; fi PROMPT=' %{$fg[$NCOLOR]%}%B%n@%m%b%{$reset_color%} %{$fg[white]%}%B${PWD/#$HOME/~}%b%{$reset_color%} -$(git_prompt_info)%(!.#.$) ' +$GIT_PROMPT_INFO%(!.#.$) ' RPROMPT='[%*]' # git theming diff --git a/themes/re5et.zsh-theme b/themes/re5et.zsh-theme index 5bded76a3..36b98a28a 100644 --- a/themes/re5et.zsh-theme +++ b/themes/re5et.zsh-theme @@ -3,7 +3,7 @@ if [ "$(whoami)" = "root" ]; then CARETCOLOR="red"; else CARETCOLOR="magenta"; f local return_code="%(?..%{$fg_bold[red]%}:( %?%{$reset_color%})" PROMPT=' -%{$fg_bold[cyan]%}%n%{$reset_color%}%{$fg[yellow]%}@%{$reset_color%}%{$fg_bold[blue]%}%m%{$reset_color%}:%{${fg_bold[green]}%}%~%{$reset_color%}$(git_prompt_info) +%{$fg_bold[cyan]%}%n%{$reset_color%}%{$fg[yellow]%}@%{$reset_color%}%{$fg_bold[blue]%}%m%{$reset_color%}:%{${fg_bold[green]}%}%~%{$reset_color%}$GIT_PROMPT_INFO %{${fg[$CARETCOLOR]}%}%# %{${reset_color}%}' RPS1='${return_code} %D - %*' @@ -13,3 +13,33 @@ ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg_bold[red]%} ±" ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%} ?" ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[red]%} ♥" + +git_prompt_info () +{ + if [ -z "$(git_prompt__git_dir)" ]; then + GIT_PROMPT_INFO='' + return + fi + + local prompt="" + git_prompt__branch + prompt=$GIT_PROMPT_BRANCH + + git_prompt__rebase_info + prompt="${prompt}$GIT_PROMPT_REBASE_INFO" + + if [[ -n "$prompt" ]]; then + git_prompt__dirty_state + if [[ "$GIT_PROMPT_DIRTY_STATE_ANY_DIRTY" = 'yes' ]]; then + prompt="$prompt%{$fg_bold[red]%}±" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED" = 'yes' ]]; then + prompt="$prompt%{$fg[cyan]%}?" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_ANY_DIRTY" = 'no' ]]; then + prompt="$prompt%{$fg_bold[red]%}♥" + fi + + GIT_PROMPT_INFO="%{$fg_bold[magenta]%}^%{$reset_color%}%{$fg_bold[yellow]%}$prompt%{$reset_color%}" + fi +} diff --git a/themes/rgm.zsh-theme b/themes/rgm.zsh-theme index 9452a8b0d..7a50c2386 100644 --- a/themes/rgm.zsh-theme +++ b/themes/rgm.zsh-theme @@ -1,6 +1,6 @@ PROMPT=' %n@%m %{$fg[cyan]%}%~ -%? $(git_prompt_info)%{$fg_bold[blue]%}%% %{$reset_color%}' +%? $GIT_PROMPT_INFO%{$fg_bold[blue]%}%% %{$reset_color%}' ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " diff --git a/themes/risto.zsh-theme b/themes/risto.zsh-theme index cb773a64e..480899f1e 100644 --- a/themes/risto.zsh-theme +++ b/themes/risto.zsh-theme @@ -1,6 +1,6 @@ # -*- sh -*- vim:set ft=sh ai et sw=4 sts=4: # It might be bash like, but I can't have my co-workers knowing I use zsh -PROMPT='%{$fg[green]%}%n@%m:%{$fg_bold[blue]%}%2~ $(git_prompt_info)%{$reset_color%}%(!.#.$) ' +PROMPT='%{$fg[green]%}%n@%m:%{$fg_bold[blue]%}%2~ $GIT_PROMPT_INFO%{$reset_color%}%(!.#.$) ' ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[red]%}‹" ZSH_THEME_GIT_PROMPT_SUFFIX="›%{$reset_color%}" diff --git a/themes/rixius.zsh-theme b/themes/rixius.zsh-theme index 7e7c9c633..78b54c6dd 100644 --- a/themes/rixius.zsh-theme +++ b/themes/rixius.zsh-theme @@ -14,7 +14,7 @@ function prompt_char { RIXIUS_PRE="%{$bg[white]%}%{$fg[red]%}" PROMPT=' -%{$RIXIUS_PRE%}%n%{$reset_color%} in %{$fg_bold[green]%}$(collapse_pwd)%{$reset_color%}$(git_prompt_info) +%{$RIXIUS_PRE%}%n%{$reset_color%} in %{$fg_bold[green]%}$(collapse_pwd)%{$reset_color%}$GIT_PROMPT_INFO $(prompt_char) ' RPROMPT='%{$RIXIUS_PRE%}%T%{$reset_color%}' diff --git a/themes/robbyrussell.zsh-theme b/themes/robbyrussell.zsh-theme index 7b524e82d..4dcb77026 100644 --- a/themes/robbyrussell.zsh-theme +++ b/themes/robbyrussell.zsh-theme @@ -1,4 +1,4 @@ -PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}' +PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$GIT_PROMPT_INFO%{$fg_bold[blue]%} % %{$reset_color%}' ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" diff --git a/themes/simple.zsh-theme b/themes/simple.zsh-theme index a88d9d72a..d345a9f9b 100644 --- a/themes/simple.zsh-theme +++ b/themes/simple.zsh-theme @@ -1,4 +1,4 @@ -PROMPT='%{$fg[green]%}%~%{$fg_bold[blue]%}$(git_prompt_info)%{$reset_color%} ' +PROMPT='%{$fg[green]%}%~%{$fg_bold[blue]%}$GIT_PROMPT_INFO%{$reset_color%} ' ZSH_THEME_GIT_PROMPT_PREFIX="(" ZSH_THEME_GIT_PROMPT_SUFFIX=")" diff --git a/themes/skaro.zsh-theme b/themes/skaro.zsh-theme index 84b7b11b0..9d8dd151d 100644 --- a/themes/skaro.zsh-theme +++ b/themes/skaro.zsh-theme @@ -1,4 +1,4 @@ -PROMPT='%{$fg_bold[green]%}%h %{$fg[cyan]%}%2~ %{$fg_bold[blue]%}$(git_prompt_info) %{$reset_color%}» ' +PROMPT='%{$fg_bold[green]%}%h %{$fg[cyan]%}%2~ %{$fg_bold[blue]%}$GIT_PROMPT_INFO %{$reset_color%}» ' ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" diff --git a/themes/sorin.zsh-theme b/themes/sorin.zsh-theme index a63a98441..bd64866c6 100644 --- a/themes/sorin.zsh-theme +++ b/themes/sorin.zsh-theme @@ -2,47 +2,72 @@ # FILE: sorin.zsh-theme # DESCRIPTION: oh-my-zsh theme file. # AUTHOR: Sorin Ionescu (sorin.ionescu@gmail.com) -# VERSION: 1.0.3 +# VERSION: 1.0.4 # SCREENSHOT: http://i.imgur.com/aipDQ.png # ------------------------------------------------------------------------------ -if [[ "$DISABLE_COLOR" != "true" ]]; then - MODE_INDICATOR="%{$fg_bold[red]%}❮%{$reset_color%}%{$fg[red]%}❮❮%{$reset_color%}" - local return_status="%{$fg[red]%}%(?..⏎)%{$reset_color%}" - - PROMPT='%{$fg[cyan]%}%c$(git_prompt_info) %(!.%{$fg_bold[red]%}#.%{$fg_bold[green]%}❯)%{$reset_color%} ' - - ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[blue]%}git%{$reset_color%}:%{$fg[red]%}" - ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" - ZSH_THEME_GIT_PROMPT_DIRTY="" - ZSH_THEME_GIT_PROMPT_CLEAN="" - - RPROMPT='${return_status}$(git_prompt_status)%{$reset_color%}' - - ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[green]%} ✚" - ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[blue]%} ✹" - ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%} ✖" - ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[magenta]%} ➜" - ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[yellow]%} ═" - ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%} ✭" -else - MODE_INDICATOR="❮❮❮" - local return_status="%(?::⏎)" - - PROMPT='%c$(git_prompt_info) %(!.#.❯) ' - - ZSH_THEME_GIT_PROMPT_PREFIX=" git:" - ZSH_THEME_GIT_PROMPT_SUFFIX="" - ZSH_THEME_GIT_PROMPT_DIRTY="" - ZSH_THEME_GIT_PROMPT_CLEAN="" - - RPROMPT='${return_status}$(git_prompt_status)' - - ZSH_THEME_GIT_PROMPT_ADDED=" ✚" - ZSH_THEME_GIT_PROMPT_MODIFIED=" ✹" - ZSH_THEME_GIT_PROMPT_DELETED=" ✖" - ZSH_THEME_GIT_PROMPT_RENAMED=" ➜" - ZSH_THEME_GIT_PROMPT_UNMERGED=" ═" - ZSH_THEME_GIT_PROMPT_UNTRACKED=" ✭" +if [[ "$DISABLE_COLORS" != "true" ]]; then + local R="%{$terminfo[sgr0]%}" + local MAGENTA="%{$fg[magenta]%}" + local YELLOW="%{$fg[yellow]%}" + local GREEN="%{$fg[green]%}" + local B_GREEN="%{$fg_bold[green]%}" + local BLUE="%{$fg[blue]%}" + local CYAN="%{$fg[cyan]%}" + local RED="%{$fg[red]%}" + local B_RED="%{$fg_bold[red]%}" fi + +MODE_INDICATOR="$B_RED❮$R$RED❮❮$R" +local return_status="$RED%(?..⏎)$R" + +PROMPT='$CYAN%c$GIT_PROMPT_INFO %(!.$B_RED#.$B_GREEN❯)$R ' +RPROMPT='${return_status}$GIT_RPROMPT_INFO$R' + +git_prompt_info () +{ + if [ -z "$(git_prompt__git_dir)" ]; then + GIT_PROMPT_INFO='' + GIT_RPROMPT_INFO='' + return + fi + + local branch='' + + git_prompt__branch + branch="$GIT_PROMPT_BRANCH" + + git_prompt__rebase_info + branch="${branch}$GIT_PROMPT_REBASE_INFO" + + GIT_PROMPT_INFO=" ${BLUE}git$R:$RED${branch}$R" + + local rprompt='' + git_prompt__dirty_state + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_ADDED" = 'yes' ]]; then + rprompt="$GREEN ✚" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED" = 'yes' ]]; then + rprompt="${rprompt}$BLUE ✹" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED" = 'yes' ]]; then + rprompt="${rprompt}$BLUE ✹" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_DELETED" = 'yes' ]]; then + rprompt="${rprompt}$RED ✖" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED" = 'yes' ]]; then + rprompt="${rprompt}$RED ✖" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED" = 'yes' ]]; then + rprompt="${rprompt}$MAGENTA ➜" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED" = 'yes' ]]; then + rprompt="${rprompt}$YELLOW ═" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED" = 'yes' ]]; then + rprompt="${rprompt}$CYAN ✭" + fi + GIT_RPROMPT_INFO=$rprompt +} diff --git a/themes/sporty_256.zsh-theme b/themes/sporty_256.zsh-theme index db0fc4277..368c96139 100644 --- a/themes/sporty_256.zsh-theme +++ b/themes/sporty_256.zsh-theme @@ -3,7 +3,7 @@ # Preview - http://www.flickr.com/photos/adelcampo/4556482563/sizes/o/ # based on robbyrussell's shell but louder! -PROMPT='%{$fg_bold[blue]%}$(git_prompt_info) %F{208}%c%f +PROMPT='%{$fg_bold[blue]%}$GIT_PROMPT_INFO %F{208}%c%f %{$fg_bold[white]%}%# %{$reset_color%}' RPROMPT='%B%F{208}%n%f%{$fg_bold[white]%}@%F{039}%m%f%{$reset_color%}' diff --git a/themes/takashiyoshida.zsh-theme b/themes/takashiyoshida.zsh-theme index 419a8cf3f..d2ab18907 100644 --- a/themes/takashiyoshida.zsh-theme +++ b/themes/takashiyoshida.zsh-theme @@ -10,8 +10,6 @@ PROMPT_BRACKET_END='%{$fg_bold[white]%}]' PROMPT_USER='%{$fg_bold[white]%}%n' PROMPT_SIGN='%{$reset_color%}%#' -GIT_PROMPT_INFO='$(git_prompt_info)' - # My current prompt looks like: # [host:current_dir] (git_prompt_info) # [username]% diff --git a/themes/theunraveler.zsh-theme b/themes/theunraveler.zsh-theme index a896970df..765086376 100644 --- a/themes/theunraveler.zsh-theme +++ b/themes/theunraveler.zsh-theme @@ -1,16 +1,49 @@ -# Comment - PROMPT='%{$fg[magenta]%}[%c] %{$reset_color%}' +RPROMPT='%{$fg[magenta]%}$GIT_PROMPT_INFO%{$reset_color%} $GIT_RPROMPT_INFO%{$reset_color%}' -RPROMPT='%{$fg[magenta]%}$(git_prompt_info)%{$reset_color%} $(git_prompt_status)%{$reset_color%}' +git_prompt_info () +{ + if [ -z "$(git_prompt__git_dir)" ]; then + GIT_PROMPT_INFO='' + GIT_RPROMPT_INFO='' + return + fi -ZSH_THEME_GIT_PROMPT_PREFIX="" -ZSH_THEME_GIT_PROMPT_SUFFIX="" -ZSH_THEME_GIT_PROMPT_DIRTY="" -ZSH_THEME_GIT_PROMPT_CLEAN="" -ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[cyan]%} ✈" -ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[yellow]%} ✭" -ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%} ✗" -ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[blue]%} ➦" -ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[magenta]%} ✂" -ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[grey]%} ✱" + local prompt='' + + git_prompt__branch + prompt="$GIT_PROMPT_BRANCH" + + git_prompt__rebase_info + prompt="${prompt}$GIT_PROMPT_REBASE_INFO" + + GIT_PROMPT_INFO="$prompt" + + local rprompt='' + git_prompt__dirty_state + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_ADDED" = 'yes' ]]; then + rprompt="%{$fg[cyan]%} ✈" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[yellow]%} ✭" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[yellow]%} ✭" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_DELETED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[red]%} ✗" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[red]%} ✗" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[blue]%} ➦" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[magenta]%} ✂" + fi + if [[ "$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED" = 'yes' ]]; then + rprompt="${rprompt}%{$fg[grey]%} ✱" + fi + GIT_RPROMPT_INFO=$rprompt +} diff --git a/themes/thomasjbradley.zsh-theme b/themes/thomasjbradley.zsh-theme index 857301d19..a2c6a25c6 100644 --- a/themes/thomasjbradley.zsh-theme +++ b/themes/thomasjbradley.zsh-theme @@ -17,7 +17,7 @@ patches: %{\e[0m%}%b ' +%{\e[0;34m%}%B└─%B[%{\e[1;35m%}$%{\e[0;34m%}%B] <$GIT_PROMPT_INFO>%{\e[0m%}%b ' PS2=$' \e[0;34m%}%B>%{\e[0m%}%b ' From 7ce0ea31f06de22a92899e069a8d3ecf0b25fa9a Mon Sep 17 00:00:00 2001 From: Ashley Dev Date: Wed, 6 Jul 2011 19:00:06 -0700 Subject: [PATCH 64/64] rm glg alias (it's now ghhh), add gls alias to git aliases --- plugins/git/git-aliases.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/git/git-aliases.plugin.zsh b/plugins/git/git-aliases.plugin.zsh index 859b637c6..cf8d123c1 100644 --- a/plugins/git/git-aliases.plugin.zsh +++ b/plugins/git/git-aliases.plugin.zsh @@ -24,7 +24,7 @@ alias gba='git branch -a' ; compdef _git gba=git-branch alias gcount='git shortlog -sn' ; compdef gcount=git alias gcp='git cherry-pick' ; compdef _git gcp=git-cherry-pick alias gm='git merge' ; compdef _git gm=git-merge -alias glg='git log --stat --max-count=5'; compdef _git glg=git-log +alias gls='git shortlog' ; compdef _git gls=shortlog # Git history (pretty) local pretty_format_oneline='--pretty=format:"%C(yellow)%h %C(green)%cd %C(cyan)%an %C(bold cyan)%d%C(reset) %s" --date=short'