From f83f7052050f0bf7f13dda807f6856f7db18c6a0 Mon Sep 17 00:00:00 2001 From: Avery Yen Date: Wed, 29 Aug 2012 23:55:35 -0400 Subject: [PATCH] Added my theme --- modules/prompt/functions/prompt_hapless_setup | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 modules/prompt/functions/prompt_hapless_setup diff --git a/modules/prompt/functions/prompt_hapless_setup b/modules/prompt/functions/prompt_hapless_setup new file mode 100644 index 00000000..61366da5 --- /dev/null +++ b/modules/prompt/functions/prompt_hapless_setup @@ -0,0 +1,96 @@ +# +# A compact and informative prompt theme +# by haplesshero13 +# Features VCS and RVM/rbenv info. +# +# The prompt borrows (steals) the fine work and ideas of +# Steve Losh +# Bart Trojanowski +# Brian Carper +# steeef +# Sorin Ionescu +# +# Screenshot can be found at: +# http://www.flickr.com/photos/79770035@N03/7867663652/ +# + +function prompt_char { + git branch >/dev/null 2>/dev/null && echo 'λ' && return + hg root >/dev/null 2>/dev/null && echo '☿' && return + echo '$' +} + +function rvm_info { + if which rvm-prompt &> /dev/null; then + echo "‹${_prompt_hapless_colors[5]}$(rvm-prompt i v g)%f›" + else + if which rbenv &> /dev/null; then + echo "‹${_prompt_hapless_colors[5]}$(rbenv version | sed -e "s/ (set.*$//")%f›" + fi + fi +} + +function prompt_hapless_precmd { + # Check for untracked files or updated submodules since vcs_info does not. + if [[ (-n $(git ls-files --others --exclude-standard 2> /dev/null)) || (-n $(hg status -u 2> /dev/null)) ]]; then + branch_format="(${_prompt_hapless_colors[1]}%b%f%u%c${_prompt_hapless_colors[4]}?%f)" + else + branch_format="(${_prompt_hapless_colors[1]}%b%f%u%c)" + fi + + zstyle ':vcs_info:*:prompt:*' formats "${branch_format}" + + vcs_info 'prompt' +} + +function prompt_hapless_setup { + setopt LOCAL_OPTIONS + unsetopt XTRACE KSH_ARRAYS + prompt_opts=(cr percent subst) + + # Load required functions. + autoload -Uz add-zsh-hook + autoload -Uz vcs_info + + # Add hook for calling vcs_info before each command. + add-zsh-hook precmd prompt_hapless_precmd + + _prompt_hapless_colors=( + "%F{cyan}" + "%F{yellow}" + "%F{magenta}" + "%F{red}" + "%F{green}" + ) + + # 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 branch_format="(${_prompt_hapless_colors[1]}%b%f%u%c)" + local action_format="(${_prompt_hapless_colors[5]}%a%f)" + local unstaged_format="${_prompt_hapless_colors[2]}!%f" + local staged_format="${_prompt_hapless_colors[5]}+%f" + local return_code='%(?..${_prompt_hapless_colors[4]}%? ↵%f)' + + # Set vcs_info parameters. + zstyle ':vcs_info:*' enable git hg + zstyle ':vcs_info:*:prompt:*' check-for-changes true + zstyle ':vcs_info:hg*:prompt:*' get-revision true + zstyle ':vcs_info:hg*:prompt:*' hgrevformat "" + zstyle ':vcs_info:*:prompt:*' unstagedstr "${unstaged_format}" + zstyle ':vcs_info:*:prompt:*' stagedstr "${staged_format}" + zstyle ':vcs_info:*:prompt:*' actionformats "${branch_format}${action_format}" + zstyle ':vcs_info:*:prompt:*' formats "${branch_format}" + zstyle ':vcs_info:*:prompt:*' nvcsformats "" + + # Define prompts. + PROMPT="${_prompt_hapless_colors[3]}%n%f@${_prompt_hapless_colors[2]}%m%f:${_prompt_hapless_colors[1]}%~%f"'$(prompt_char) ' + RPROMPT="${return_code} "'${vcs_info_msg_0_}$(rvm_info)' +} + +prompt_hapless_setup "$@" +