[ZshWiki] page changed: config:prompt
A page in your DokuWiki was added or changed. Here are the details: Date : 2008/04/05 20:23 Browser : @BROWSER@ IP-Address : @IPADDRESS@ Hostname : @HOSTNAME@ Old Revision: http://zshwiki.org/home/config/prompt?rev=1207346622 New Revision: http://zshwiki.org/home/config/prompt Edit Summary: Fixed some bugs in the 'soor' prompt User : creidiki @@ -56,15 +56,19 @@ % prompt bart </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> + # -*- mode: sh; -*- + # soor prompt theme + prompt_soor_help () { cat <<'EOF' This prompt is configurable via styles: @@ -101,9 +105,9 @@ precmd () { local p_full - local p_tchars p_temp p_done p_last + local p_tchars p_temp p_done p_last i local maxlength ratio local prompt_color local user_color local root_color @@ -140,9 +144,9 @@ case "${path_style}" in ratio) zstyle -s :prompt:soor ratio ratio ratio=${ratio:-6} - maxlength=$(($COLUMNS/$ratio)) + maxlength=$(( ${COLUMNS} / ${ratio} )) ;; fixed) zstyle -s :prompt:soor length maxlength maxlength=${maxlength:-20} @@ -154,39 +158,31 @@ esac case "${path_style}" in full) - p_done="%~" + path_prompt=$(print -P %~) ;; subdir) - p_done=$(print -P "%(4~|..|)%${maxlength}~") + path_prompt=$(print -P "%($(( ${maxlength} + 1 ))~|..|)%${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. + path_prompt=$(print -P %~) + if (( ${#path_prompt} > ${maxlength} )); then p_tchars='../' + p_done=${path_prompt} 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 + p_temp=$(print -P %${i}~) + if (( ( ${#p_temp} + ${#p_tchars} ) < ${maxlength} )); then + p_done=${p_temp} + else break fi - p_last="${p_temp}" done + path_prompt=${p_tchars}${p_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" } -- This mail was generated by DokuWiki at http://zshwiki.org/home/
participants (1)
-
noreply@zshwiki.org