Only works in a two-line prompt in the upper line, that
is, a newline MUST appear in the setup!
- The actual configuration is done via zsh's \`zstyle' mechanism. The
- context, that is used while looking up styles is:
+ Should they not fit your need, there is an easy way to have the
+ prompt include basically anything you want. Just define your own
+ items. For that you simply define them inside the
+ ':prompt:ganneff:extra:' namespace.
+
+ Example: To have the prompt include the value of the variable
+ \$FOOBAR, in red and have the variable updated by the function
+ jj_foobar, use the following:
+
+ zstyle ':prompt:ganneff:extra:foobar' pre '${PR_RED}'
+ zstyle ':prompt:ganneff:extra:foobar' post '${PR_NO_COLOR}'
+ zstyle ':prompt:ganneff:extra:foobar' token '$FOOBAR'
+ zstyle ':prompt:ganneff:extra:foobar' precmd jj_foobar
+
+ Now you can add the token \`foobar' to the list of items and voila,
+ your own stuff appears.
+
+ Note that the function part only works in zsh 4.3.5 or later (I've
+ been to lazy to replace add-zsh-hook with something for the older
+ versions).
+
+
+ The configuration of the predefined items can also be changed using
+ zsh's \`zstyle' mechanism. The context, that is used while looking
+ up styles is:
':prompt:ganneff:<left-or-right>:<full-or-small>:<subcontext>'
- Here <left-or-right> is either \`left' or \`right', signifying whether the
- style should affect the left or the right prompt. <full-or-small> is
- either \`full' or \`small' and only valid in the item selection,
- signifying wether the item list should affect the full length or
- the "small terminal" prompt. As "small terminal" prompt does not
- display the right side prompt, <full-or-small> has no effect on the
- right side prompt.
+ Here <left-or-right> is either \`left' or \`right', signifying
+ whether the style should affect the left or the right prompt.
+
+ <full-or-small> is either \`full' or \`small' and only valid in the
+ item selection, signifying wether the item list should affect the
+ full length or the "small terminal" prompt. As "small terminal"
+ prompt does not display the right side prompt, <full-or-small> has
+ no effect on the right side prompt.
+
<subcontext> is either \`setup' or 'items:<item>', where \`<item>'
is one of the available items.
- The styles available under ':prompt:ganneff:':
+ The styles/settings available under ':prompt:ganneff:':
- vcs_info (boolean): If \`true' (the default), use \`vcs_info'.
- nicelines (boolean): If \`true' (the default), use special
magic to draw nice lines and corners. Might not work on every
terminal. If false, draws using plain ascii characters.
+ Linux console also seems to identify itself as if it could,
+ but then doesn't do drawing right (not in our way at least).
- battery (string): If \`none' then no battery function at all.
If either \`ibam' or \`acpi' then use those tools to gather
accordingly. Default (left): rc change-root user at host path vcs
percent; Default (right): sad-smiley
- Available styles in 'items:<item>' are: pre, post. These are strings that
- are inserted before (pre) and after (post) the item in question. Thus, the
- following would cause the user name to be printed in red instead of the
- default blue:
+ Note that both, nicelines and colors are forced to false in case the
+ TERM variable is set to dumb.
+
+ Available styles in 'items:<item>' are: pre, post, token and precmd.
+ Pre and Post are strings that are inserted before (pre) and after
+ (post) the item in question. Token is the token itself that gets
+ inserted into PS1. Thus, the following would cause the
+ user name to be printed in red instead of the default blue:
zstyle ':prompt:ganneff:*:items:user' pre '\${PR_RED}'
- Note, that the \`post' style may remain at its default value, because its
- default value is '\${PR_NO_COLOR}', which turns the foreground text
- attribute off (which is exactly, what is still required with the new
- \`pre' value).
+ and
+
+ zstyle ':prompt:ganneff:*:items:date' token '%D{%Y-%m-%d [d:%j/w:%V]}'
+
+ will output a very different date token compared with the default
+ definition of '%D{%Y-%m-%d}'.
+
+ Note, that in the above example the \`post' style may remain at its
+ default value, because its default value is '\${PR_NO_COLOR}', which
+ turns the foreground text attribute off (which is exactly, what is
+ still required with the new \`pre' value).
Possible values for the colors: \${PR_XXX} and \${PR_BOLD_XXX} with
- XXX replaced with one of: RED GREEN YELLOW BLUE MAGENTA CYAN WHITE
+ XXX replaced with one of: RED GREEN YELLOW BLUE MAGENTA CYAN WHITE BLACK.
\${PR_NO_COLOR} resets color.
Using the \${PR_XXX} values instead of zsh's internal \%F{xxx} allows
- the style to turn off colors to work.
+ the usage of the colors style to turn of prompt colors easily.
__EOF0__
}
emulate -L zsh
setopt nolocaltraps
+ # We forcefully overwrite colors and nicelines setting for a dumb
+ # terminal.
+ if [[ "$TERM" == "dumb" ]]; then
+ zstyle ':prompt:ganneff' colors false
+ zstyle ':prompt:ganneff' nicelines false
+ fi
+
# See if we can and should use extended characters to look nicer.
- if zstyle -t ':prompt:ganneff' nicelines && [[ "$TERM" != dumb ]] \
- && [[ "$TERM" != "linux" ]]; then
+ if zstyle -t ':prompt:ganneff' nicelines; then
typeset -A altchar
set -A altchar ${(s..)terminfo[acsc]}
# Some stuff to help us draw nice lines
PR_URCORNER=""
fi
- if zstyle -t ':prompt:ganneff' colors && [[ "$TERM" != dumb ]]; then
+ if zstyle -t ':prompt:ganneff' colors; then
if [[ -n "${BLUE}" ]] && [[ -n "${YELLOW}" ]]; then
# Two defined, so we assume someone already defined themself
# the colors. We just use them and not setup our own.
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
- eval PR_$color="%{${(P)color}%}"
- eval PR_BOLD_$color="%{$terminfo[bold]${(LP)color}%}"
+ eval PR_$color='%{${(P)color}%}'
+ eval PR_BOLD_$color='%{$terminfo[bold]${(LP)color}%}'
done
PR_NO_COLOR="%{${reset_color}%}"
else
# Seems like colors are not defined, so set them up
- docolors
+ # This duplicates docolors from 01_Terminfo.zsh, but is here to have
+ # prompt_ganneff_setup not require anything else from my dotfiles
+ if autoload -Uz colors && colors 2>/dev/null ; then
+ for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do
+ eval PR_$COLOR='%{$fg_no_bold[${(L)COLOR}]%}'
+ eval PR_BOLD_$COLOR='%{$fg_bold[${(L)COLOR}]%}'
+ done
+ eval PR_NO_COLOR='%{$reset_color%}'
+ else
+ PR_BLUE=$'%{\e[1;34m%}'
+ PR_RED=$'%{\e[1;31m%}'
+ PR_GREEN=$'%{\e[1;32m%}'
+ PR_CYAN=$'%{\e[1;36m%}'
+ PR_WHITE=$'%{\e[1;37m%}'
+ PR_MAGENTA=$'%{\e[1;35m%}'
+ PR_YELLOW=$'%{\e[1;33m%}'
+ PR_NO_COLOR=$'%{\e[0m%}'
+ fi
fi
else
PR_BLUE=''
# The secondary prompt, printed when the shell needs more
# information to complete a command. %_ displays any shell constructs
# or quotation marks which are currently being processed.
- if zstyle -t ':prompt:ganneff' colors && [[ "$TERM" != dumb ]]; then
+ if zstyle -t ':prompt:ganneff' nicelines; then
PS2='${PR_CYAN}${PR_SHIFT_IN}${PR_HBAR}${PR_BLUE}${PR_HBAR}${PR_SHIFT_OUT}\
(${PR_GREEN}%_${PR_BLUE})\
${PR_SHIFT_IN}${PR_HBAR}${PR_CYAN}${PR_HBAR}${PR_SHIFT_OUT}${PR_NO_COLOR} '
emulate -L zsh
local target="$1"
local size="$2"
- local lr it apre apost new v
+ local lr it apre apost new v prefunc
local -a items
shift
shift
typeset -g "${target}="
for it in "${items[@]}"; do
zstyle -s ":prompt:ganneff:${lr}:items:$it" pre apre \
+ || zstyle -s ":prompt:ganneff:extra:$it" pre apre \
|| apre=${ganneff_prompt_pre_default[$it]}
zstyle -s ":prompt:ganneff:${lr}:items:$it" post apost \
+ || zstyle -s ":prompt:ganneff:extra:$it" post apost \
|| apost=${ganneff_prompt_post_default[$it]}
zstyle -s ":prompt:ganneff:${lr}:items:$it" token new \
+ || zstyle -s ":prompt:ganneff:extra:$it" token new \
|| new=${ganneff_prompt_token_default[$it]}
+
+ # Now check if there is the wish for a precmd function and if so,
+ # fulfill it.
+ if is435; then
+ zstyle -s ":prompt:ganneff:extra:$it" precmd prefunc
+ if [[ -n "${prefunc}" ]]; then
+ add-zsh-hook precmd ${prefunc}
+ fi
+ fi
+
typeset -g "${target}=${(P)target}${apre}"
# Store the expanded value in PR_PS1, as we use that for length calculations
[[ $it == "newline" ]] && nomore=1