Remove silly message on logout display non-success exit value for every command Add first version of modules and load them up Add more paths Allow the sharing of prezto files by differentiating ZDOTDIR and where temp cache files will go: _ZDOTDIR/HOME remove Vim swap files Allow for both a shared and personal overriding .zpreztorc In shared system, put .zcompdump in user's home Fix path of .zcompdump Fixed names of prompt Support callbacks to override user & host value & style Fix transpose* bindings for vi and ^Y for emacs Fixed ordering of paths
229 lines
6.9 KiB
Text
229 lines
6.9 KiB
Text
# Progressive theme that displays only relevant information as needed.
|
||
# Builds on both sorin and nicoulaj theme.
|
||
#
|
||
# Features:
|
||
# - Multiple verbosity styles:
|
||
# - One or multiple lines
|
||
# - In minimal style, shows user@hostname if connected through SSH.
|
||
# - toggle with aliases "P 0" ... "P 5"
|
||
# - VCS information in the right prompt.
|
||
# - Supports prezto's git-info if 'git' module is loaded, or zsh's default vcs_info otherwise
|
||
# - If using the default vcs_info module:
|
||
# - Only shows the path on the left prompt by default.
|
||
# - Crops the path to a defined length and only shows the path relative to
|
||
# the current VCS repository root.
|
||
# - Shows if logged in as root or not.
|
||
# - Shows number of jobs
|
||
# - Shows shell level if greater than 1
|
||
# - Colors work with Solarized 8-bit ANSI colors
|
||
# - Supports callbacks for customizing style and value of user and hostname
|
||
|
||
# Load dependencies.
|
||
pmodload 'helper'
|
||
|
||
function prompt_progressive_precmd {
|
||
setopt LOCAL_OPTIONS
|
||
unsetopt XTRACE KSH_ARRAYS
|
||
|
||
# Get Git repository information.
|
||
if (( $+functions[git-info] )); then
|
||
if git-info; then
|
||
# Some functionality not provided by git-info
|
||
#git_info[remote]="$(git remote -v | fgrep fetch | sed 's/.*[\/:]\([^:\/][^:\/]*\)\.git.*/\1/')"
|
||
git_info[repo]=$(basename $(git rev-parse --show-toplevel))
|
||
fi
|
||
else
|
||
vcs_info
|
||
fi
|
||
}
|
||
|
||
function prompt_progressive_load() {
|
||
uptime | sed 's/.*: *//;s/,//g'
|
||
}
|
||
|
||
# @param verbosity From 0 to 5 with 2 as default
|
||
function prompt_progressive_setup {
|
||
setopt LOCAL_OPTIONS
|
||
unsetopt XTRACE KSH_ARRAYS
|
||
prompt_opts=(cr percent subst)
|
||
|
||
# Load required functions.
|
||
autoload -Uz add-zsh-hook
|
||
# If git module is loaded, use that, otherwise get standard zsh vcs_info
|
||
if (( $+functions[git-info] )); then
|
||
# Set git-info parameters (from sorin prompt)
|
||
zstyle ':prezto:module:editor:info:completing' format '%F{magenta}...%f'
|
||
zstyle ':prezto:module:editor:info:keymap:primary' format '%#'
|
||
zstyle ':prezto:module:editor:info:keymap:alternate' format '%F{yellow}⎋%f'
|
||
zstyle ':prezto:module:editor:info:keymap:primary:overwrite' format '%F{red}➨%f'
|
||
zstyle ':prezto:module:git:info:action' format '%F{yellow}%s%f%%b'
|
||
zstyle ':prezto:module:git:info:added' format ' %F{green}✚%f%%b'
|
||
zstyle ':prezto:module:git:info:ahead' format ' %F{yellow}⬆%f%%b'
|
||
zstyle ':prezto:module:git:info:behind' format ' %F{yellow}⬇%f%%b'
|
||
zstyle ':prezto:module:git:info:branch' format '%F{blue}%b%f'
|
||
zstyle ':prezto:module:git:info:commit' format '%F{blue}%.7c%f'
|
||
zstyle ':prezto:module:git:info:deleted' format ' %F{red}✖%f%%b'
|
||
zstyle ':prezto:module:git:info:modified' format ' %%B%F{magenta}✱%f%%b'
|
||
zstyle ':prezto:module:git:info:position' format '%F{blue}%p%f'
|
||
zstyle ':prezto:module:git:info:renamed' format ' %%B%F{magenta}➜%f%%b'
|
||
zstyle ':prezto:module:git:info:stashed' format ' %F{cyan}✭%f%%b'
|
||
zstyle ':prezto:module:git:info:unmerged' format ' %F{yellow}═%f%%b'
|
||
zstyle ':prezto:module:git:info:untracked' format ' %F{magenta}?%f%%b'
|
||
zstyle ':prezto:module:git:info:keys' format \
|
||
'prompt' '%F{green}${git_info[repo]:+$git_info[repo]:}%f$(coalesce "%b" "%p" "%c")%s' \
|
||
'rprompt' '%A%B%a%d%m%r%U%u%S'
|
||
|
||
# Our extensions
|
||
zstyle ':prezto:module:git:info:repo' format ':%%B%F{yellow}%R%f%%b'
|
||
else
|
||
autoload -Uz vcs_info
|
||
|
||
local vcs_info_color='%F{242}'
|
||
|
||
# Set vcs_info parameters.
|
||
zstyle ':vcs_info:*' enable git hg svn
|
||
zstyle ':vcs_info:*' check-for-changes true
|
||
zstyle ':vcs_info:*' stagedstr '%F{green}✚%{[m%}'
|
||
zstyle ':vcs_info:*' unstagedstr '%F{red}?%{[m%}'
|
||
|
||
# On OS X, see /usr/share/zsh/4.3.11/functions/VCS_INFO_formats for docs:
|
||
# %r: repo
|
||
# %s: VCS, e.g. 'git'
|
||
# %b: branch
|
||
# %u: unstaged
|
||
# %c: staged
|
||
#zstyle ':vcs_info:*' actionformats "%S" "%r/%s/%b %u%c (%a)"
|
||
#zstyle ':vcs_info:*' formats "%S" "%r/%s/%b %u%c"
|
||
zstyle ':vcs_info:*' actionformats "√%%S" "[%r:%B%F{magenta}%b%f %u%c (%a)"
|
||
zstyle ':vcs_info:*' formats "√%S" "[%r:%B%F{magenta}%b%{[m%} %u%c]"
|
||
zstyle ':vcs_info:*' nvcsformats "%~" ""
|
||
fi
|
||
|
||
# Add hook for calling vcs_info before each command.
|
||
add-zsh-hook precmd prompt_progressive_precmd
|
||
|
||
# Customizable parameters.
|
||
local max_path_chars=50
|
||
|
||
# Style
|
||
if [[ "$1" == --init ]]; then
|
||
local init=1
|
||
shift
|
||
fi
|
||
local style=''
|
||
case "$1" in
|
||
0) style=bare ;;
|
||
1) style=minimal ;;
|
||
3) style=unabbreviated ;;
|
||
4) style=multiline ;;
|
||
5) style=verbose ;;
|
||
2|) style=concise ;;
|
||
*) style="$1" ;;
|
||
esac
|
||
[[ -z "$init" ]] && print -P "Switching to '%F{blue}$style%f' style of '%F{green}progressive%f' prompt."
|
||
|
||
|
||
### Process username and hostname
|
||
|
||
local user host
|
||
|
||
user="%F{green}%n%f"
|
||
user_unformatted="%n"
|
||
if (( $+functions[prompt_map_user] )); then
|
||
prompt_map_user $USERNAME
|
||
user="$prompt_info_user"
|
||
user_unformatted="$prompt_info_user_unformatted"
|
||
fi
|
||
|
||
host="%m"
|
||
host_unformatted="%m"
|
||
if (( $+functions[prompt_map_host] )); then
|
||
prompt_map_host $HOST
|
||
host="$prompt_info_host"
|
||
host_unformatted="$prompt_info_host_unformatted"
|
||
fi
|
||
|
||
### Define prompt
|
||
|
||
if [[ $style == bare ]]; then
|
||
PS1='%# '
|
||
RPS1=''
|
||
return
|
||
fi
|
||
|
||
local P
|
||
|
||
if [[ $style == 'verbose' ]]; then
|
||
# Insert the time
|
||
P+='%F{blue}%*%f '
|
||
fi
|
||
|
||
if [[ $style != 'minimal' || -n "$SSH_TTY" ]]; then
|
||
# Username and host
|
||
P+="${user}@${host} "
|
||
fi
|
||
|
||
# Start coloring path
|
||
P+="%F{cyan}"
|
||
|
||
if [[ $style != (unabbreviated|multiline|verbose) ]]; then
|
||
# Limit the amount of space taken by the rest of the line
|
||
P+="%${max_path_chars}<…<"
|
||
fi
|
||
|
||
# Print up to 5 elements of the current directory
|
||
#P+="%5~%f"
|
||
if (( $+functions[git-info] )); then
|
||
P+='%~'
|
||
else
|
||
# Print current directory or, if inside repo, path relative to that
|
||
P+='${vcs_info_msg_0_}'
|
||
fi
|
||
# Stop coloring path
|
||
P+="%f"
|
||
# Number of background jobs
|
||
P+="%1(j. %jJ.)"
|
||
# Shell level if greater than 1
|
||
P+="%(2L/ L1/)"
|
||
|
||
if [[ $style == (multiline|verbose) ]]; then
|
||
P+="
|
||
"
|
||
else
|
||
# Separator
|
||
##P+=" "
|
||
fi
|
||
|
||
# Add names and titles to window and tab titles
|
||
# (not needed because that's handled by 'terminal' module)
|
||
#P+="%{]2;${user_unformatted}@${host_unformatted}: %~]1;%1~%}"
|
||
# Terminate the line with character that depends on mode
|
||
if (( $+functions[git-info] )); then
|
||
P+='${editor_info[overwrite]:-${editor_info[keymap]}} '
|
||
else
|
||
P+='%# '
|
||
fi
|
||
|
||
PS1="$P"
|
||
|
||
# Right prompt contains VCS info and maybe load
|
||
local R
|
||
if (( $+functions[git-info] )); then
|
||
R+='${git_info:+[${(e)git_info[prompt]}${git_info[rprompt]}]}'
|
||
else
|
||
R+="${vcs_info_color}"'${vcs_info_msg_1_}'"%f"
|
||
fi
|
||
if [[ $style == 'verbose' ]]; then
|
||
R+=" ($(prompt_progressive_load))"
|
||
fi
|
||
RPROMPT="$R"
|
||
}
|
||
|
||
# Allows quick switching of prompts at command line; e.g.
|
||
# P 0
|
||
# P 5
|
||
# P verbose
|
||
alias P='prompt_progressive_setup'
|
||
|
||
prompt_progressive_setup --init "$@"
|
||
|