From c20f63d7586d0cd6e68c6c67e005ff934e18c4ef Mon Sep 17 00:00:00 2001 From: Ben O'Hara Date: Thu, 31 May 2012 00:44:58 +1000 Subject: [PATCH 01/10] Prompt based on the solarised theme --- .../prompt/functions/prompt_solarized_setup | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 modules/prompt/functions/prompt_solarized_setup diff --git a/modules/prompt/functions/prompt_solarized_setup b/modules/prompt/functions/prompt_solarized_setup new file mode 100644 index 0000000000..01fe8dd348 --- /dev/null +++ b/modules/prompt/functions/prompt_solarized_setup @@ -0,0 +1,144 @@ +# +# A theme based on Steve Losh's prompt with VCS_INFO integration +# Tweaked with solarized colors for 256/16 color modes +# +# Authors: +# Steve Losh +# Bart Trojanowski +# Brian Carper +# solarized +# Sorin Ionescu +# Ben O'Hara +# +# Activate in .zshrc: +# +# zstyle ':omz:module:prompt' theme 'solarized' +# +# and settings: +# +# zstyle ':omz:module:prompt:solarized' 256colors 'yes' +# zstyle ':omz:module:prompt:solarized' dark 'yes' + +function virtualenv_info { + if [[ -n "$VIRTUAL_ENV" ]]; then + print "(${VIRTUAL_ENV:t}) " + fi +} + +function prompt_solarized_precmd { + if [[ -n "$__PROMPT_solarized_VCS_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 + __PROMPT_solarized_VCS_UPDATE=1 + fmt_branch=" ($prompt_orange%b%f%u%c$prompt_red●%f)" + else + fmt_branch=" ($prompt_orange%b%f%u%c)" + fi + zstyle ':vcs_info:*:prompt:*' formats "${fmt_branch}" + + vcs_info 'prompt' + __PROMPT_solarized_VCS_UPDATE='' + fi +} + +function prompt_solarized_preexec { + case "$(history $HISTCMD)" in + (*git*) + __PROMPT_solarized_VCS_UPDATE=1 + ;; + (*svn*) + __PROMPT_solarized_VCS_UPDATE=1 + ;; + esac +} + +function prompt_solarized_chpwd { + __PROMPT_solarized_VCS_UPDATE=1 +} + +function prompt_solarized_setup { + setopt LOCAL_OPTIONS + unsetopt XTRACE KSH_ARRAYS + prompt_opts=(cr percent subst) + + autoload -Uz add-zsh-hook + autoload -Uz vcs_info + + add-zsh-hook precmd prompt_solarized_precmd + add-zsh-hook preexec prompt_solarized_preexec + add-zsh-hook chpwd prompt_solarized_chpwd + + __PROMPT_solarized_VCS_UPDATE=1 + + zstyle -b ':omz:module:prompt:solarized' 256colors '_prompt_256colors' + if is-true "${_prompt_256colors}"; then + prompt_base03="%F{234}" # brblack base03 + prompt_base02="%F{235}" # black base02 + prompt_base01="%F{240}" # brgreen base01 + prompt_base00="%F{241}" # bryellow base00 + prompt_base0="%F{244}" # brblue base0 + prompt_base1="%F{245}" # brcyan base1 + prompt_base2="%F{254}" # white base2 + prompt_base3="%F{230}" # brwhite base3 + prompt_yellow="%F{136}" # yellow yellow + prompt_orange="%F{166}" # brred orange + prompt_red="%F{160}" # red red + prompt_magenta="%F{125}" # magenta magenta + prompt_violet="%F{61}" # brmagenta violet + prompt_blue="%F{33}" # blue blue + prompt_cyan="%F{37}" # cyan cyan + prompt_green="%F{64}" # green green + else + prompt_base03="%F{black}%FX{bold}" # brblack base03 + prompt_base02="%F{black}" # black base02 + prompt_base01="%F{green}%FX{bold}" # brgreen base01 + prompt_base00="%F{yellow}%FX{bold}" # bryellow base00 + prompt_base0="%F{blue}%FX{bold}" # brblue base0 + prompt_base1="%F{cyan}%FX{bold}" # brcyan base1 + prompt_base2="%F{white}" # white base2 + prompt_base3="%F{white}%FX{bold}" # brwhite base3 + prompt_yellow="%F{yellow}" # yellow yellow + prompt_orange="%F{red}%FX{bold}" # brred orange + prompt_red="%F{red}" # red red + prompt_magenta="%F{magenta}" # magenta magenta + prompt_violet="%F{magenta}%FX{bold}" # brmagenta violet + prompt_blue="%F{blue}" # blue blue + prompt_cyan="%F{cyan}" # cyan cyan + prompt_green="%F{green}" # green green + fi + # Enable VCS systems you use. + zstyle ':vcs_info:*' enable git hg svn cvs + + # 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 + + # 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 + local fmt_branch=" ($prompt_orange%b%f%u%c)" + local fmt_action=" ($prompt_blue%a%f)" + local fmt_unstaged="$prompt_red+%f" + local fmt_staged="$prompt_green+%f" + + 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 "" + + zstyle -b ':omz:module:prompt:solarized' dark '_prompt_dark' + if is-true "${_prompt_dark}"; then + PROMPT="$prompt_green%n%f$prompt_base1 at $prompt_green%m%f$prompt_base1 in $prompt_base01%~%f"'${vcs_info_msg_0_}'" +"'$(virtualenv_info)'"$prompt_base1 $ $prompt_base0" + else + PROMPT="$prompt_green%n%f$prompt_base01 at $prompt_green%m%f$prompt_base01 in $prompt_base1%~%f"'${vcs_info_msg_0_}'" +"'$(virtualenv_info)'"$prompt_base01 $ $prompt_base00" + fi +} + +prompt_solarized_setup "$@" From 2369c5c79203fd7b0381bff4171d8d03caa3d104 Mon Sep 17 00:00:00 2001 From: Ben O'Hara Date: Thu, 31 May 2012 00:46:38 +1000 Subject: [PATCH 02/10] Dont run if not on darwin prepend /opt/local/{bin,sbin} to the path --- modules/macports/init.zsh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/macports/init.zsh b/modules/macports/init.zsh index c07ad2d629..2b881a2e75 100644 --- a/modules/macports/init.zsh +++ b/modules/macports/init.zsh @@ -5,6 +5,10 @@ # Matt Cable # +if [[ "$OSTYPE" != darwin* ]]; then + return 1 +fi + # Aliases alias pc="sudo port clean --all installed" alias pi="sudo port install $1" @@ -13,3 +17,7 @@ alias puni="sudo port uninstall inactive" alias puo="sudo port upgrade outdated" alias pup="psu && puo" +path=( + /opt/local/{bin,sbin} +$path +) From c561596687c7eb13bd0b5d4dba43cc4fe789989d Mon Sep 17 00:00:00 2001 From: Ben O'Hara Date: Fri, 1 Jun 2012 13:01:10 +1000 Subject: [PATCH 03/10] fix --- init.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/init.zsh b/init.zsh index 42c395adf7..a815724189 100644 --- a/init.zsh +++ b/init.zsh @@ -10,6 +10,7 @@ min_zsh_version='4.3.10' if ! autoload -Uz is-at-least || ! is-at-least "$min_zsh_version"; then print "omz: old shell detected, minimum required: $min_zsh_version" >&2 + return 1 fi unset min_zsh_version From ffca2870ffc0efd210b4f5f2d2be3e94b0ae1cc3 Mon Sep 17 00:00:00 2001 From: Ben O'Hara Date: Sat, 2 Jun 2012 19:41:28 +1000 Subject: [PATCH 04/10] fix for root user --- modules/prompt/functions/prompt_solarized_setup | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/prompt/functions/prompt_solarized_setup b/modules/prompt/functions/prompt_solarized_setup index 01fe8dd348..ecdae8b3d0 100644 --- a/modules/prompt/functions/prompt_solarized_setup +++ b/modules/prompt/functions/prompt_solarized_setup @@ -133,11 +133,11 @@ function prompt_solarized_setup { zstyle -b ':omz:module:prompt:solarized' dark '_prompt_dark' if is-true "${_prompt_dark}"; then - PROMPT="$prompt_green%n%f$prompt_base1 at $prompt_green%m%f$prompt_base1 in $prompt_base01%~%f"'${vcs_info_msg_0_}'" -"'$(virtualenv_info)'"$prompt_base1 $ $prompt_base0" + PROMPT="%(!.$prompt_red.$prompt_green)%n%f$prompt_base1 on $prompt_green%m%f$prompt_base1 in $prompt_base01%~%f"'${vcs_info_msg_0_}'" +"'$(virtualenv_info)'"$prompt_base1 %# $prompt_base0" else - PROMPT="$prompt_green%n%f$prompt_base01 at $prompt_green%m%f$prompt_base01 in $prompt_base1%~%f"'${vcs_info_msg_0_}'" -"'$(virtualenv_info)'"$prompt_base01 $ $prompt_base00" + PROMPT="%(!.$prompt_red.$prompt_green)%n%f$prompt_base01 on $prompt_green%m%f$prompt_base01 in $prompt_base1%~%f"'${vcs_info_msg_0_}'" +"'$(virtualenv_info)'"$prompt_base01 %# $prompt_base00" fi } From 53ea090710a2b6f7e60e565f0ef1f0b1fc1e2f72 Mon Sep 17 00:00:00 2001 From: Ben O'Hara Date: Sat, 2 Jun 2012 20:49:03 +1000 Subject: [PATCH 05/10] fix prompt --- modules/prompt/functions/prompt_solarized_setup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/prompt/functions/prompt_solarized_setup b/modules/prompt/functions/prompt_solarized_setup index ecdae8b3d0..60735ce70f 100644 --- a/modules/prompt/functions/prompt_solarized_setup +++ b/modules/prompt/functions/prompt_solarized_setup @@ -133,10 +133,10 @@ function prompt_solarized_setup { zstyle -b ':omz:module:prompt:solarized' dark '_prompt_dark' if is-true "${_prompt_dark}"; then - PROMPT="%(!.$prompt_red.$prompt_green)%n%f$prompt_base1 on $prompt_green%m%f$prompt_base1 in $prompt_base01%~%f"'${vcs_info_msg_0_}'" + PROMPT="%(!.$prompt_red.$prompt_green)%n%f$prompt_base1 at $prompt_green%m%f$prompt_base1 in $prompt_base01%~%f"'${vcs_info_msg_0_}'" "'$(virtualenv_info)'"$prompt_base1 %# $prompt_base0" else - PROMPT="%(!.$prompt_red.$prompt_green)%n%f$prompt_base01 on $prompt_green%m%f$prompt_base01 in $prompt_base1%~%f"'${vcs_info_msg_0_}'" + PROMPT="%(!.$prompt_red.$prompt_green)%n%f$prompt_base01 at $prompt_green%m%f$prompt_base01 in $prompt_base1%~%f"'${vcs_info_msg_0_}'" "'$(virtualenv_info)'"$prompt_base01 %# $prompt_base00" fi } From a3853ef5ae74f14617a59c9ce9af54059cb2a825 Mon Sep 17 00:00:00 2001 From: Ben O'Hara Date: Sat, 2 Jun 2012 23:51:03 +1000 Subject: [PATCH 06/10] host based prompt color --- modules/prompt/functions/prompt_solarized_setup | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/prompt/functions/prompt_solarized_setup b/modules/prompt/functions/prompt_solarized_setup index 60735ce70f..35711c11bd 100644 --- a/modules/prompt/functions/prompt_solarized_setup +++ b/modules/prompt/functions/prompt_solarized_setup @@ -131,12 +131,16 @@ function prompt_solarized_setup { zstyle ':vcs_info:*:prompt:*' formats "${fmt_branch}" zstyle ':vcs_info:*:prompt:*' nvcsformats "" + zstyle -a ':omz:module:prompt:solarized' $HOST '_prompt_host' + + prompt_host=$"prompt_$_prompt_host" + zstyle -b ':omz:module:prompt:solarized' dark '_prompt_dark' if is-true "${_prompt_dark}"; then - PROMPT="%(!.$prompt_red.$prompt_green)%n%f$prompt_base1 at $prompt_green%m%f$prompt_base1 in $prompt_base01%~%f"'${vcs_info_msg_0_}'" + PROMPT="%(!.$prompt_red.$prompt_green)%n%f$prompt_base1 at $prompt_host%m%f$prompt_base1 in $prompt_base01%~%f"'${vcs_info_msg_0_}'" "'$(virtualenv_info)'"$prompt_base1 %# $prompt_base0" else - PROMPT="%(!.$prompt_red.$prompt_green)%n%f$prompt_base01 at $prompt_green%m%f$prompt_base01 in $prompt_base1%~%f"'${vcs_info_msg_0_}'" + PROMPT="%(!.$prompt_red.$prompt_green)%n%f$prompt_base01 at $prompt_host%m%f$prompt_base01 in $prompt_base1%~%f"'${vcs_info_msg_0_}'" "'$(virtualenv_info)'"$prompt_base01 %# $prompt_base00" fi } From 11604c298e1418d7cffb43e4daf3ccefbef3403c Mon Sep 17 00:00:00 2001 From: Ben O'Hara Date: Sun, 3 Jun 2012 00:04:44 +1000 Subject: [PATCH 07/10] fix --- modules/prompt/functions/prompt_solarized_setup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/prompt/functions/prompt_solarized_setup b/modules/prompt/functions/prompt_solarized_setup index 35711c11bd..7c13c4a33b 100644 --- a/modules/prompt/functions/prompt_solarized_setup +++ b/modules/prompt/functions/prompt_solarized_setup @@ -132,9 +132,9 @@ function prompt_solarized_setup { zstyle ':vcs_info:*:prompt:*' nvcsformats "" zstyle -a ':omz:module:prompt:solarized' $HOST '_prompt_host' - - prompt_host=$"prompt_$_prompt_host" - + if [ ! -z $_prompt_host ]; then + prompt_host=$"prompt_$_prompt_host" + fi zstyle -b ':omz:module:prompt:solarized' dark '_prompt_dark' if is-true "${_prompt_dark}"; then PROMPT="%(!.$prompt_red.$prompt_green)%n%f$prompt_base1 at $prompt_host%m%f$prompt_base1 in $prompt_base01%~%f"'${vcs_info_msg_0_}'" From 64a93fd0ba234842894e4f6999a237ca96ba0e9d Mon Sep 17 00:00:00 2001 From: Ben O'Hara Date: Sun, 3 Jun 2012 00:08:51 +1000 Subject: [PATCH 08/10] doc --- modules/prompt/functions/prompt_solarized_setup | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/prompt/functions/prompt_solarized_setup b/modules/prompt/functions/prompt_solarized_setup index 7c13c4a33b..19678cb902 100644 --- a/modules/prompt/functions/prompt_solarized_setup +++ b/modules/prompt/functions/prompt_solarized_setup @@ -18,6 +18,13 @@ # # zstyle ':omz:module:prompt:solarized' 256colors 'yes' # zstyle ':omz:module:prompt:solarized' dark 'yes' +# +# custom hostname colours +# +# zstyle ':omz:module:prompt:solarized' hostname 'red' +# zstyle ':omz:module:prompt:solarized' hostname2 'blue' +# +# function virtualenv_info { if [[ -n "$VIRTUAL_ENV" ]]; then From e313cca59c2504624317bd35f84eb7463ba9e27d Mon Sep 17 00:00:00 2001 From: Ben O'Hara Date: Sun, 3 Jun 2012 00:10:42 +1000 Subject: [PATCH 09/10] default --- modules/prompt/functions/prompt_solarized_setup | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/prompt/functions/prompt_solarized_setup b/modules/prompt/functions/prompt_solarized_setup index 19678cb902..26fb3bc2ea 100644 --- a/modules/prompt/functions/prompt_solarized_setup +++ b/modules/prompt/functions/prompt_solarized_setup @@ -138,6 +138,7 @@ function prompt_solarized_setup { zstyle ':vcs_info:*:prompt:*' formats "${fmt_branch}" zstyle ':vcs_info:*:prompt:*' nvcsformats "" + prompt_host=$prompt_green zstyle -a ':omz:module:prompt:solarized' $HOST '_prompt_host' if [ ! -z $_prompt_host ]; then prompt_host=$"prompt_$_prompt_host" From 6015d5b0da59401f87898d06506f75be5f2eb02a Mon Sep 17 00:00:00 2001 From: Ben O'Hara Date: Sun, 3 Jun 2012 01:02:57 +1000 Subject: [PATCH 10/10] fix --- modules/prompt/functions/prompt_solarized_setup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/prompt/functions/prompt_solarized_setup b/modules/prompt/functions/prompt_solarized_setup index 26fb3bc2ea..8e92cc5d6b 100644 --- a/modules/prompt/functions/prompt_solarized_setup +++ b/modules/prompt/functions/prompt_solarized_setup @@ -145,10 +145,10 @@ function prompt_solarized_setup { fi zstyle -b ':omz:module:prompt:solarized' dark '_prompt_dark' if is-true "${_prompt_dark}"; then - PROMPT="%(!.$prompt_red.$prompt_green)%n%f$prompt_base1 at $prompt_host%m%f$prompt_base1 in $prompt_base01%~%f"'${vcs_info_msg_0_}'" + PROMPT="%(!.$prompt_red.$prompt_host)%n%f$prompt_base1 at $prompt_host%m%f$prompt_base1 in $prompt_base01%~%f"'${vcs_info_msg_0_}'" "'$(virtualenv_info)'"$prompt_base1 %# $prompt_base0" else - PROMPT="%(!.$prompt_red.$prompt_green)%n%f$prompt_base01 at $prompt_host%m%f$prompt_base01 in $prompt_base1%~%f"'${vcs_info_msg_0_}'" + PROMPT="%(!.$prompt_red.$prompt_host)%n%f$prompt_base01 at $prompt_host%m%f$prompt_base01 in $prompt_base1%~%f"'${vcs_info_msg_0_}'" "'$(virtualenv_info)'"$prompt_base01 %# $prompt_base00" fi }