From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2127 invoked from network); 24 Feb 2005 19:32:00 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 24 Feb 2005 19:32:00 -0000 Received: (qmail 52688 invoked from network); 24 Feb 2005 19:31:52 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 24 Feb 2005 19:31:52 -0000 Received: (qmail 10538 invoked by alias); 24 Feb 2005 19:31:43 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8545 Received: (qmail 10524 invoked from network); 24 Feb 2005 19:31:42 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 24 Feb 2005 19:31:42 -0000 Received: (qmail 51681 invoked from network); 24 Feb 2005 19:31:42 -0000 Received: from ms-smtp-05.texas.rr.com (HELO ms-smtp-05-eri0.texas.rr.com) (24.93.47.44) by a.mx.sunsite.dk with SMTP; 24 Feb 2005 19:31:36 -0000 Received: from zigzag.elkins.cx (cpe-24-174-118-53.houston.res.rr.com [24.174.118.53]) by ms-smtp-05-eri0.texas.rr.com (8.12.10/8.12.7) with ESMTP id j1OJVVPa023918 for ; Thu, 24 Feb 2005 13:31:31 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by zigzag.elkins.cx (Postfix) with ESMTP id BCD9D1D62C5 for ; Thu, 24 Feb 2005 13:31:30 -0600 (CST) Received: from zigzag.elkins.cx ([127.0.0.1]) by localhost (zigzag [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 31925-07-2 for ; Thu, 24 Feb 2005 13:31:30 -0600 (CST) Received: from zigzag.elkins.cx (localhost [127.0.0.1]) by zigzag.elkins.cx (Postfix) with ESMTP id 1CE961D62C6 for ; Thu, 24 Feb 2005 13:30:54 -0600 (CST) Received: from tarpon.int.elkins.cx (tarpon.int.elkins.cx [192.168.2.107]) by zigzag.elkins.cx (Postfix) with SMTP id F2CBF1B8859 for ; Thu, 24 Feb 2005 13:30:53 -0600 (CST) Received: by tarpon.int.elkins.cx (sSMTP sendmail emulation); Thu, 24 Feb 2005 13:30:54 -0600 From: "Joel David Elkins" Date: Thu, 24 Feb 2005 13:30:54 -0600 To: zsh-users@sunsite.dk Subject: prompt Message-ID: <20050224193053.GA26686@elkins.cx> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="6c2NcOVqGQ03X4Wi" Content-Disposition: inline X-Operating-System: Linux 2.6.10-tarpon09-smp User-Agent: Mutt/1.5.6i X-DSPAM-Result: Whitelisted X-DSPAM-Confidence: 0.6789 X-DSPAM-Probability: 0.0000 X-DSPAM-Signature: 421e2b91326661741010933 X-Virus-Scanned: Symantec AntiVirus Scan Engine X-Virus-Scanned: by amavisd-new at elkins.cx X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 --6c2NcOVqGQ03X4Wi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Just for fun, I'm attaching my prompt, for those who like everything and the kitchen sink to appear every time you hit enter (like me apparently). For example, it includes optional mailbox counts (Maildir only at the moment), system uptime, last exit status, line drawing using the iso8859-1 alternate line drawing characters (optional), etc etc. I started with Bart's prompt but little is left of it. The file is extensively commented, which is good because some configuration is required by setting a few variables. Suggestions welcome; otherwise enjoy! Regards, Joel -- Joel Elkins (alternate) --6c2NcOVqGQ03X4Wi 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 "$@" --6c2NcOVqGQ03X4Wi--