From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17846 invoked from network); 26 Jul 2005 16:30:35 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 26 Jul 2005 16:30:35 -0000 Received: (qmail 94032 invoked from network); 26 Jul 2005 16:30:28 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 26 Jul 2005 16:30:28 -0000 Received: (qmail 5125 invoked by alias); 26 Jul 2005 16:30:17 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9188 Received: (qmail 5115 invoked from network); 26 Jul 2005 16:30:17 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 26 Jul 2005 16:30:17 -0000 Received: (qmail 92605 invoked from network); 26 Jul 2005 16:30:17 -0000 Received: from ms-smtp-01.texas.rr.com (HELO ms-smtp-01-eri0.texas.rr.com) (24.93.47.40) by a.mx.sunsite.dk with SMTP; 26 Jul 2005 16:30:08 -0000 Received: from zigzag.elkins.cx (cpe-67-10-248-171.houston.res.rr.com [67.10.248.171]) by ms-smtp-01-eri0.texas.rr.com (8.12.10/8.12.7) with ESMTP id j6QGU3H9007530 for ; Tue, 26 Jul 2005 11:30:03 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by zigzag.elkins.cx (Postfix) with ESMTP id 1614BA24F9 for ; Tue, 26 Jul 2005 11:30:03 -0500 (CDT) Received: from zigzag.elkins.cx ([127.0.0.1]) by localhost (zigzag [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 14169-11-2 for ; Tue, 26 Jul 2005 11:30:02 -0500 (CDT) Received: from zigzag.elkins.cx (localhost [127.0.0.1]) by zigzag.elkins.cx (Postfix) with ESMTP id 05877A2507 for ; Tue, 26 Jul 2005 11:28:59 -0500 (CDT) Received: by zigzag.elkins.cx (Postfix, from userid 1000) id B110DA24F7; Tue, 26 Jul 2005 11:28:59 -0500 (CDT) Date: Tue, 26 Jul 2005 11:28:59 -0500 From: Joel David Elkins To: zsh-users@sunsite.dk Subject: Re: [zsh] Re: psvar expansion with %v Message-ID: <20050726162859.GA17231@elkins.cx> References: <20050723084210.GA7913@DervishD> <20050726073322.GA1945@DervishD> <1050726140109.ZM29371@candle.brasslantern.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="H1spWtNR+x+ondvy" Content-Disposition: inline In-Reply-To: <1050726140109.ZM29371@candle.brasslantern.com> X-Operating-System: Linux 2.6.11.10-zigzag03 User-Agent: Mutt/1.5.8i X-DSPAM-Result: Whitelisted X-DSPAM-Confidence: 0.9997 X-DSPAM-Probability: 0.0000 X-DSPAM-Signature: 42e66509175811403316385 X-Virus-Scanned: Symantec AntiVirus Scan Engine X-Virus-Scanned: amavisd-new at elkins.cx X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham version=3.0.4 --H1spWtNR+x+ondvy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline As Bart noted, you can't use %v as you want to, but you can get the same effect using "set promptsubst" and PS1="\$psvar[1]". This was my solution to a similar problem for my prompt. I attached it in hopes of giving you more ideas, Raul. Regards, Joel On Tue, Jul 26, 2005 at 02:01:09PM +0000, Bart Schaefer wrote: > On Jul 26, 9:33am, DervishD wrote: > } > } > How can I use psvar and %v to get a readable PS1 *but* use escape > } > sequences at the same time? I'm using zsh 4.2.5 (i686-pc-linux-gnu) > } > } I still haven't solved this, and I've carried a lot of tests. Is > } any way of using '%{%}' constructs, or escape sequences, using psvar? > > No, there isn't. The results of percent-expandos are not re-expanded, > so whatever gets inserted by %v appears literally in the final prompt. > Furthermore, anything inserted by any percent-expando (be it your user > name, or the host name, or the contents of psvar) is deliberately put > through a conversion to printable form so that you can't accidentally > mess up ZLE by moving the cursor or emitting something whose displayed > length cannot be accurately counted. > > Consider the bad things that could otherwise result if you created a > directory with strange characters in its name when your prompt has %/ > in it, or had such a directory in your path when using %N. -- Joel Elkins (alternate) --H1spWtNR+x+ondvy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=prompt_jde_setup # vim:ft=zsh fdm=marker # $Id: prompt_jde_setup,v 1.15 2004/10/27 03:03:59 jde Exp $ # "jde" prompt theme -- a multiline theme of great tweaking zmodload -i zsh/parameter || return 1 ################################################################################ ### HELP {{{ ################################################################################ prompt_jde_help () { setopt localoptions nocshnullcmd noshnullcmd [[ $ZSH_VERSION < 3.1.6-dev-20 ]] && print 'Requires 3.1.6-dev-19 plus zsh-workers/10168.'$'\n' <<-\EOF This prompt provides a lot of information attractively. Observe: user@host login tty new mail counts uptime loadavg 5,10,15 $PWD v v v v v v v v v v --| jde@zigzag : pts/468 : IN:3 m:22 p:58 |--| 25d03:13 : 0.10 0.07 0.01 |---| ~ |-- --| ?0 : !1004 : % |- -| 23:41 : 04-08-20 |-- ^ ^ ^ ^ | history # time date last exitcode This prompt is tested on Linux and OpenBSD; on the latter, it is required to have kernfs mounted on /kern for some features to work properly, although there are simple (slower) workarounds if you edit the script. EOF [[ $(read -Ek 1 "?${(%):-%S[press return]%s}") == [Qq] ]] && print -nP '\r%E' && return <<-\EOF The prompt is fully colorized, but as of now you have to edit the script to change the colors. (I.e., it is not themable.) Additionally, the scheme uses the alternate charset available with vt100-type terminals (including nearly every xterm flavor) to draw lines and angles. With some combinations of terminals and programs, this may cause problems; the feature can be turned off with: prompt jde -a or prompt jde noaltchar In this case, standard ascii characters will be used instead. (The example above is the ascii mode.) You can re-enable line drawing with: prompt jde altchar EOF [[ $(read -Ek 1 "?${(%):-%S[press return]%s}") == [Qq] ]] && print -nP '\r%E' && return <<-\EOF The mail count feature will read the mailboxes identified in the zsh $PROMPT_JDE_MAILBOXES array parameter, which should have the form: (TAG:/path/to/mailbox BOX2:/alt/box) The script will read the mailboxes identified therein, and use the "tag" as the key displayed next to the count of new mail. As of now, the script only deals with maildir-style mailboxes. It will silently ignore any non-maildir identified in $PROMPT_JDE_MAILBOXES, including directories containing other mailboxes (which are supported by the zsh implementation of mail checking). When new mail arrives in any of the tracked mailboxes, the prompt will change color briefly (one line). If you do not want this feature, start the prompt with prompt jde -m or prompt jde nomailcount With this invocation, the prompt theme will work normally, but will omit the mail count widget. To reenable this feature, use: prompt jde mailcount EOF [[ $(read -Ek 1 "?${(%):-%S[press return]%s}") == [Qq] ]] && print -nP '\r%E' && return <<-\EOF When the screen is resized to the point where the "widgets" get sqeezed, the script will attempt to shrink things appropriately. First, the center widget on the first line (containing uptime and load average info) will disappear. If yet more room is needed, the $PWD element will be truncated on the left-hand side. The top center (uptime) widget, if visible, will always try to remain centered. EOF } #############################################################################}}} ### UPTIME {{{ ################################################################################ prompt_jde_uptime () { setopt localoptions noksharrays local -i upSeconds secs mins hours days case "${OSTYPE:l}" in linux*|cygwin*) # optimization. -d. means delimiter is the decimal. Clever? read -d. upSeconds 0 )); then echo -n "${days}d" fi printf '%.2d:%.2d' $hours $mins } #############################################################################}}} ### MAILCOUNTS {{{ ################################################################################ # Count new mail in mailboxes. The resulting counts are put into assoc arrays # PROMPT_JDE_MAILCOUNTS and PROMPT_JDE_MAILCOUNTS_OLD (holding former results. # TODO: support mbox mailboxes. # TODO: What do do with directory-of-mailboxes? Just ignore I guess. # TODO: Is there some smarter way of determining the keys? It is very basic now. prompt_jde_mailcounts () { [[ $PROMPT_JDE_MAILCOUNT == no ]] && return setopt localoptions nullglob local -h line maildir files count key typeset -gA PROMPT_JDE_MAILCOUNTS PROMPT_JDE_MAILCOUNTS_OLD PROMPT_JDE_MAILCOUNTS_OLD=() #${${(s::)${${(s:?:)x}[1]:t}}[1]} for line in $PROMPT_JDE_MAILBOXES; do maildir=${${(s.:.)line}[2]} key=${${(s.:.)line}[1]} [[ -d $maildir/new ]] || continue files=($maildir/new/*) count=${#files} PROMPT_JDE_MAILCOUNTS_OLD[$key]=$PROMPT_JDE_MAILCOUNTS[$key] PROMPT_JDE_MAILCOUNTS[$key]=$count done } #############################################################################}}} ### LOADAVG {{{ ################################################################################ prompt_jde_loadavg () { setopt localoptions noksharrays local -h loadavg case "${OSTYPE:l}" in linux*|cygwin*) local -h one five fifteen rest # read /proc/loadavg as a speedup over $(uptime|sed...) read one five fifteen rest >) with the length equal to # the 2nd line of PS1 (the part between $grbeg and # $grend). Then we pad the string with plenty of spaces. "%\${#:-$ps1line2}> >" # The following prints the number of words in %_ "$invtext \${(w)#\${(%):-%_}}" # The following prints the last word of %_ #"$normtext \${\${(%):-%_}[(w)-1]}" "$normtext %1_" # DUH!! # Here is the big space pad needed to ensure we get to # the right side of PS1's 2nd line. Should I be more # precise, e.g. using ${(l...)}? Nah. " " "%<<" # end the truncation "$pr_shift_in" "$grend" "$pr_shift_out" "$rs" $' ' ) PS2="${(j::)ps2}" } #############################################################################}}} ### WINCH {{{ ################################################################################ #TODO: this is not getting called prompt_jde_winch () { setopt localoptions noksharrays # Delete ourself from TRAPWINCH if not using our precmd insert. [[ $functions[precmd] = *prompt_jde_precmd* ]] && prompt_jde_ps1 || functions[TRAPWINCH]="${functions[TRAPWINCH]//prompt_jde_winch}" } #############################################################################}}} ### SETUP {{{ ################################################################################ prompt_jde_setup () { # zsh options we require: prompt_* prompt_opts=( cr subst percent ) setopt localoptions noksharrays typeset -g PROMPT_JDE_ALTCHAR PROMPT_JDE_MAILCOUNT : ${PROMPT_JDE_ALTCHAR:=yes} : ${PROMPT_JDE_MAILCOUNT:=yes} # A few extra niceties ... repeat 1 case "$1:l" in (off|disable) functions[precmd]="${functions[precmd]//prompt_jde_precmd}" functions[preexec]="${functions[preexec]//prompt_jde_preexec}" functions[TRAPWINCH]="${functions[TRAPWINCH]//prompt_jde_winch}" [[ $prompt_theme[1] = jde ]] && PS1=${${(f)PS1}[-1]} return 1 ;; (on|enable) shift [[ $prompt_theme[1] = jde ]] && break ;& (-a|noaltchar) PROMPT_JDE_ALTCHAR=no ;; (altchar) PROMPT_JDE_ALTCHAR=yes ;; (-m|nomailcount) PROMPT_JDE_MAILCOUNT=no ;; (mailcount) PROMPT_JDE_MAILCOUNT=yes ;; (*) # nothing ;; esac [[ -z $PROMPT_JDE_MAILBOXES ]] && PROMPT_JDE_MAILCOUNT=no prompt_jde_ps1 # Paste our special commands into precmd and TRAPWINCH functions[precmd]="${functions[precmd]//prompt_*_precmd} prompt_jde_precmd" functions[preexec]="${functions[preexec]//prompt_*_preexec \"\$1\"} prompt_jde_preexec \"\$1\"" functions[TRAPWINCH]="${functions[TRAPWINCH]//prompt_jde_winch} prompt_jde_winch" return 0 } # }}} [[ -o kshautoload ]] || prompt_jde_setup "$@" --H1spWtNR+x+ondvy--