[ZshWiki] page changed: config:prompt
A page in your DokuWiki was added or changed. Here are the details: Date : 2008/04/05 00:03 Browser : Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9b5) Gecko/2008040407 (Gentoo) Firefox/3.0b5 IP-Address : 87.0.139.111 Hostname : host111-139-dynamic.0-87-r.retail.telecomitalia.it Old Revision: http://zshwiki.org/home/config/prompt?rev=1191491386 New Revision: http://zshwiki.org/home/config/prompt Edit Summary: Add an example prompt theme. User : creidiki @@ -57,4 +57,142 @@ </code> Simple enough, isn't it? + ==== Prompt Examples ==== + + Some examples of what you can do with zsh prompts. + + Using styles to make flexible prompts: + <code> + prompt_soor_help () { + cat <<'EOF' + This prompt is configurable via styles: + + Context: :prompt:soor + + Colors (in zsh/terminfo value): + user-color - the color for user@host. defaults to 'green' + root-color - the color for the hostname for root. defaults to 'red' + prompt-color - the color for everything else. defaults to 'blue' + + Path type: + path - possible values: + ratio - use COLUMNS/ratio to clip the path. Default. + fixed - use a fixed maximum lenght. + subdir - clip by number of subdirectories. + full - show the full path + + Path lenght styles: + ratio - the ratio for the 'ratio' path style, funnily enough. + default to 6. + length - the maximin lenght for the 'fixed' path style. + defaults to 20 + subdir - the number of subdirs to show for the 'subdir' path style. + defaults to 3. + + You can set styles in the current terminal to test things out, values + will be updated. + + EOF + } + + prompt_soor_setup () { + setopt noxtrace localoptions + + precmd () { + + local p_full + local p_tchars p_temp p_done p_last + local maxlength ratio + local prompt_color + local user_color + local root_color + local path_style + + zstyle -s :prompt:soor prompt-color prompt_color + prompt_color=${prompt_color:-'blue'} + zstyle -s :prompt:soor user-color user_color + user_color=${user_color:-'green'} + zstyle -s :prompt:soor root-color root_color + root_color=${root_color:-'red'} + + [[ -z $(functions zsh/terminfo) ]] && autoload -Uz zsh/terminfo + + if [[ "$terminfo[colors]" -ge 8 ]]; then + if [[ "$EUID" = "0" ]] || [[ "$USER" = 'root' ]] + then + base_prompt="%{$fg_bold[$root_color]%}%m%{$fg_bold[$prompt_color]%} " + else + base_prompt="%{$fg_bold[$user_color]%}%n@%m%{$fg_bold[$prompt_color]%} " + fi + post_prompt="%{$reset_color%}" + else + base_prompt="%n@%m " + post_prompt="" + fi + + if zstyle -t :prompt:soor path full ratio fixed subdir; then + zstyle -s :prompt:soor path path_style + else + path_style='ratio' + fi + + case "${path_style}" in + ratio) + zstyle -s :prompt:soor ratio ratio + ratio=${ratio:-6} + maxlength=$(($COLUMNS/$ratio)) + ;; + fixed) + zstyle -s :prompt:soor length maxlength + maxlength=${maxlength:-20} + ;; + subdir) + zstyle -s :prompt:soor subdir maxlength + maxlength=${maxlength:-3} + ;; + esac + + case "${path_style}" in + full) + p_done="%~" + ;; + subdir) + p_done=$(print -P "%(4~|..|)%${maxlength}~") + ;; + ratio|fixed) + p_full=$(print -P %~) + if [[ ${#p_full} -le ${maxlength} ]]; then + p_done="${p_full}" + else + # I don't actually remember how this little snippet works. + # But it /does/, somehow, so I'm not touching it. + p_tchars='../' + for (( i=1 ; ; ++i )); do + p_temp="${p_tchars}$(print -P %${i}~)" + if [[ ${#p_temp} -gt ${maxlength} ]]; then + if [[ -n ${p_last} ]]; then + p_done="${p_last}" + else + p_done="${p_temp}" + fi + break + fi + p_last="${p_temp}" + done + fi + ;; + esac + + + path_prompt="${p_done}" + PS1="$base_prompt$path_prompt %# $post_prompt" + PS2="$base_prompt$path_prompt %_> $post_prompt" + PS3="$base_prompt$path_prompt ?# $post_prompt" + } + + preexec () { } + } + + prompt_soor_setup + </code> -- This mail was generated by DokuWiki at http://zshwiki.org/home/
participants (1)
-
noreply@zshwiki.org