From: Andrey Borzenkov <arvidjaar@newmail.ru>
To: zsh-workers@sunsite.dk
Cc: Wael Nasreddine <mla@nasreddine.com>
Subject: Re: Fw: Phil's prompt is not working when LANG is set to UTF-8
Date: Sat, 16 Feb 2008 10:56:25 +0300 [thread overview]
Message-ID: <200802161056.29466.arvidjaar@newmail.ru> (raw)
In-Reply-To: <20080215235241.2f255730@pws-pc>
[-- Attachment #1.1: Type: text/plain, Size: 1152 bytes --]
On Saturday 16 February 2008, Peter Stephenson wrote:
> How about the following tweak to prompts to support this? The upshot is
> that you include any funny characters in %{...%G%} where the %G for
> `glitch' (which may be repeated or take a numeric argument) indicates a
> screen cell taken up by the sequence.
Yes, I was about to try the same today morning (you have to sleep on it);
but I likely would not end up with such elegant solution.
> I like this because it uses
> facilities that have been present in the shell for a long time and hence
> was trivial to implement and might work.
>
> I played with this in simple cases, but would anybody like to confirm
> this works in the cases that matter (and maybe produce an updated Phil's
> Prompt)?
I confirm that this works and updated prompt is attached. Wael, does it work
for you with this patch applied?
Now downside of course is, it works only with patched shell ...
> To put it another way: I am happy to support this fix but
> have no interest in doing anything with it myself.
>
> I think this is clean and useful enough that I will commit it anyway.
[-- Attachment #1.2: phils.new --]
[-- Type: text/plain, Size: 3939 bytes --]
# vim:ft=zsh:fenc=UTF-8:ts=4:sts=4:sw=4:expandtab:
# $Id$
function precmd {
local TERMWIDTH
(( TERMWIDTH = ${COLUMNS} - 1 ))
###
# Truncate the path if it's too long.
PR_FILLBAR=""
PR_FILLBAR_PRE=""
PR_FILLBAR_POST=""
PR_PWDLEN=""
local promptsize=${#${(%):---(%n@%m:%l)---()--}}
local pwdsize=${#${(%):-%~}}
if [[ "$promptsize + $pwdsize" -gt $TERMWIDTH ]]; then
((PR_PWDLEN=$TERMWIDTH - $promptsize))
else
PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize)))..${PR_HBAR_PURE}.)}"
PR_FILLBAR_PRE="%{"
PR_FILLBAR_POST="%${#PR_FILLBAR}G%}"
fi
###
# Get APM info.
# if which ibam &> /dev/null; then
# PR_APM_RESULT=`ibam --percentbattery 2> /dev/null`
# elif which apm &> /dev/null; then
# PR_APM_RESULT=`apm 2> /dev/null`
# fi
}
setopt extended_glob
preexec () {
if [[ "$TERM" == "screen" ]]; then
local CMD=${1[(wr)^(*=*|sudo|-*)]}
echo -n "\ek$CMD\e\\"
fi
}
setprompt () {
###
# Need this so the prompt will work.
setopt prompt_subst
###
# See if we can use colors.
autoload colors zsh/terminfo
if [[ "$terminfo[colors]" -ge 8 ]]; then
colors
fi
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
(( count = $count + 1 ))
done
PR_NO_COLOUR="%{$terminfo[sgr0]%}"
###
# See if we can use extended characters to look nicer.
typeset -A altchar
set -A altchar ${(s..)terminfo[acsc]}
PR_SET_CHARSET="%{$terminfo[enacs]%}"
PR_SHIFT_IN="%{$terminfo[smacs]%}"
PR_SHIFT_OUT="%{$terminfo[rmacs]%}"
PR_HBAR_PURE="${altchar[q]:--}"
PR_HBAR="%{${altchar[q]:--}%G%}"
PR_ULCORNER="%{${altchar[l]:--}%G%}"
PR_LLCORNER="%{${altchar[m]:--}%G%}"
PR_LRCORNER="%{${altchar[j]:--}%G%}"
PR_URCORNER="%{${altchar[k]:--}%G%}"
###
# Decide if we need to set titlebar text.
case $TERM in
xterm*)
PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
;;
screen*)
PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
;;
*)
PR_TITLEBAR=''
;;
esac
###
# Decide whether to set a screen title
if echo "${TERM}" | grep -q "^screen"; then
PR_STITLE=$'%{\ekzsh\e\\%}'
else
PR_STITLE=''
fi
###
# APM detection
# if which ibam > /dev/null; then
# PR_APM='$PR_RED${${PR_APM_RESULT[(f)1]}[(w)-2]}%%(${${PR_APM_RESULT[(f)3]}[(w)-1]})$PR_LIGHT_BLUE:'
# elif which apm > /dev/null; then
# PR_APM='$PR_RED${PR_APM_RESULT[(w)5,(w)6]/\% /%%}$PR_LIGHT_BLUE:'
# else
# PR_APM=''
# fi
###
# Finally, the prompt.
PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
$PR_CYAN$PR_SHIFT_IN$PR_ULCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
$PR_CYAN%(!.%SROOT%s.%n)$PR_YELLOW@$PR_GREEN%m$PR_YELLOW:$PR_BLUE%l\
$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_HBAR$PR_FILLBAR_PRE${(e)PR_FILLBAR}$PR_FILLBAR_POST$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
$PR_MAGENTA%$PR_PWDLEN<...<%~%<<\
$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_URCORNER$PR_SHIFT_OUT\
$PR_CYAN$PR_SHIFT_IN$PR_LLCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
%(?..$PR_LIGHT_RED%?$PR_BLUE:)\
${(e)PR_APM}$PR_YELLOW%D{%H:%M}\
$PR_LIGHT_BLUE:%(!.$PR_RED.$PR_WHITE)%#$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_NO_COLOUR '
RPROMPT=' $PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_BLUE$PR_HBAR$PR_SHIFT_OUT\
($PR_YELLOW%D{%a,%b%d}$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_LRCORNER$PR_SHIFT_OUT$PR_NO_COLOUR'
PS2='$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_BLUE$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT(\
$PR_LIGHT_GREEN%_$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT$PR_NO_COLOUR '
}
setprompt
print -rnP -- "$PROMPT" > /tmp/PROMPT
print -rnP -- "$RPROMPT" > /tmp/RPROMPT
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
next prev parent reply other threads:[~2008-02-16 7:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-15 23:52 Peter Stephenson
2008-02-16 7:56 ` Andrey Borzenkov [this message]
2008-02-16 8:50 ` Wael Nasreddine
2008-02-16 9:00 ` Bart Schaefer
2008-02-16 19:13 ` Bart Schaefer
2008-02-16 19:32 ` Bart Schaefer
2008-02-17 16:43 ` Peter Stephenson
2008-02-17 17:40 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200802161056.29466.arvidjaar@newmail.ru \
--to=arvidjaar@newmail.ru \
--cc=mla@nasreddine.com \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).