Configure zprezto and setup command prompt

This commit is contained in:
Andrew Tomaka 2015-08-01 19:23:27 -04:00
parent 9ec4d4add2
commit 026fdae379
2 changed files with 111 additions and 143 deletions

148
zpreztorc
View file

@ -1,28 +1,10 @@
#
# Sets Prezto options.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
fpath=(
${HOME}/.zsh/modules/prompt/functions
${fpath}
)
#
# General
#
# Set case-sensitivity for completion, history lookup, etc.
# zstyle ':prezto:*:*' case-sensitive 'yes'
# Color output (auto set to 'no' on dumb terminals).
zstyle ':prezto:*:*' color 'yes'
# Set the Zsh modules to load (man zshmodules).
# zstyle ':prezto:load' zmodule 'attr' 'stat'
# Set the Zsh functions to load (man zshcontrib).
# zstyle ':prezto:load' zfunction 'zargs' 'zmv'
# Set the Prezto modules to load (browse modules).
# The order matters.
zstyle ':prezto:load' pmodule \
'environment' \
'terminal' \
@ -34,124 +16,4 @@ zstyle ':prezto:load' pmodule \
'completion' \
'prompt'
#
# Editor
#
# Set the key mapping style to 'emacs' or 'vi'.
zstyle ':prezto:module:editor' key-bindings 'emacs'
# Auto convert .... to ../..
# zstyle ':prezto:module:editor' dot-expansion 'yes'
#
# Git
#
# Ignore submodules when they are 'dirty', 'untracked', 'all', or 'none'.
# zstyle ':prezto:module:git:status:ignore' submodules 'all'
#
# GNU Utility
#
# Set the command prefix on non-GNU systems.
# zstyle ':prezto:module:gnu-utility' prefix 'g'
#
# History Substring Search
#
# Set the query found color.
# zstyle ':prezto:module:history-substring-search:color' found ''
# Set the query not found color.
# zstyle ':prezto:module:history-substring-search:color' not-found ''
# Set the search globbing flags.
# zstyle ':prezto:module:history-substring-search' globbing-flags ''
#
# Pacman
#
# Set the Pacman frontend.
# zstyle ':prezto:module:pacman' frontend 'yaourt'
#
# Prompt
#
# Set the prompt theme to load.
# Setting it to 'random' loads a random theme.
# Auto set to 'off' on dumb terminals.
zstyle ':prezto:module:prompt' theme 'sorin'
#
# Ruby
#
# Auto switch the Ruby version on directory change.
# zstyle ':prezto:module:ruby:chruby' auto-switch 'yes'
#
# Screen
#
# Auto start a session when Zsh is launched in a local terminal.
# zstyle ':prezto:module:screen:auto-start' local 'yes'
# Auto start a session when Zsh is launched in a SSH connection.
# zstyle ':prezto:module:screen:auto-start' remote 'yes'
#
# SSH
#
# Set the SSH identities to load into the agent.
# zstyle ':prezto:module:ssh:load' identities 'id_rsa' 'id_rsa2' 'id_github'
#
# Syntax Highlighting
#
# Set syntax highlighters.
# By default, only the main highlighter is enabled.
# zstyle ':prezto:module:syntax-highlighting' highlighters \
# 'main' \
# 'brackets' \
# 'pattern' \
# 'cursor' \
# 'root'
#
# Set syntax highlighting styles.
# zstyle ':prezto:module:syntax-highlighting' styles \
# 'builtin' 'bg=blue' \
# 'command' 'bg=blue' \
# 'function' 'bg=blue'
#
# Terminal
#
# Auto set the tab and window titles.
# zstyle ':prezto:module:terminal' auto-title 'yes'
# Set the window title format.
# zstyle ':prezto:module:terminal:window-title' format '%n@%m: %s'
# Set the tab title format.
# zstyle ':prezto:module:terminal:tab-title' format '%m: %s'
#
# Tmux
#
# Auto start a session when Zsh is launched in a local terminal.
# zstyle ':prezto:module:tmux:auto-start' local 'yes'
# Auto start a session when Zsh is launched in a SSH connection.
# zstyle ':prezto:module:tmux:auto-start' remote 'yes'
# Integrate with iTerm2.
# zstyle ':prezto:module:tmux:iterm' integrate 'yes'
zstyle ':prezto:module:prompt' theme 'atomaka'

View file

@ -0,0 +1,106 @@
pmodload 'helper'
function prompt_atomaka_pwd {
local pwd="${PWD/#$HOME/~}"
if [[ "$pwd" == (#m)[/~] ]]; then
_prompt_atomaka_pwd="$MATCH"
unset MATCH
else
_prompt_atomaka_pwd="${${${(@j:/:M)${(@s:/:)pwd}##.#?}:h}%/}/${pwd:t}"
fi
}
function prompt_atomaka_userhost {
eval PR_USER='%F{green}%n%f'
if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then
eval PR_HOST='%F{yellow}%M%f' #SSH
else
eval PR_HOST='%F{green}%M%f' # no SSH
fi
_prompt_atomaka_userhost='${PR_USER}%F{cyan}@${PR_HOST}%f'
}
function prompt_atomaka_ruby {
if which rvm-prompt &> /dev/null; then
_prompt_atomaka_ruby='[%F{red}$(rvm-prompt i v g s)%f]'
else
if which rbenv &> /dev/null; then
_prompt_atomaka_ruby='[%F{red}$(rbenv version | sed -e "s/ (set.*$//")%f]'
fi
fi
}
function prompt_atomaka_vcs {
local branch_format="(%F{yellow}%b%f%u%c)"
local action_format="(%F{yellow}%a%f)"
local unstaged_format="%F{green}*%f"
local staged_format="%F{yellow}*%f"
zstyle ':vcs_info:*' enable bzr git hg svn
zstyle ':vcs_info:*:prompt:*' check-for-changes true
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 ""
_prompt_atomaka_vcs="["'${vcs_info_msg_0_}'"]"
}
function prompt_atomaka_precmd {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS
# Format PWD.
prompt_atomaka_pwd
# vcs prompt
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
branch_format="%F{yellow}%b%f%u%c%F{yellow}*%f"
else
branch_format="%F{yellow}%b%f%u%c"
fi
zstyle ':vcs_info:*:prompt:*' formats "${branch_format}"
vcs_info 'prompt'
}
function prompt_atomaka_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 git-info before each command.
add-zsh-hook precmd prompt_atomaka_precmd
zstyle ':prezto:module:editor:info:completing' format '%B%F{red}...%f%b'
zstyle ':prezto:module:editor:info:keymap:primary:overwrite' format ' %F{red}♺%f'
# keep this
SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
# custom stuff
prompt_atomaka_ruby
prompt_atomaka_userhost
prompt_atomaka_vcs
local current_time="[%B%D{%I:%M:%S}%b]"
local current_dir='%B%F{blue}%~%f%b'
local return_code="%(?..%?)"
local user_host=$_prompt_atomaka_userhost
local ruby_info=$_prompt_atomaka_ruby
local git_info=$_prompt_atomaka_vcs
local PR_PROMPT="%(?.%F{green}->.%F{red}-%B${return_code}%b%F{red}->%{%})%f"
PROMPT="${current_time} ${user_host} ${current_dir} ${ruby_info} ${git_info}
|$PR_PROMPT "
}
prompt_atomaka_setup "$@"