zsh-users
 help / color / mirror / code / Atom feed
* prompt
@ 2005-02-24 19:30 Joel David Elkins
  2005-02-27 16:47 ` prompt William H. Magill
  0 siblings, 1 reply; 8+ messages in thread
From: Joel David Elkins @ 2005-02-24 19:30 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 638 bytes --]

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 <jde@elkins.cx>
(alternate) <jdelkins@gmail.com>

[-- Attachment #2: prompt_jde_setup --]
[-- Type: text/plain, Size: 23503 bytes --]

# 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 </proc/uptime
		;;
	    openbsd*)
		# OpenBSD has /kern/boottime, which has as a drawback that
		# it is the system time at boot, which is not (?) updated for
		# subsequent system time changes.[1] It is therefore potentially
		# inaccurate to do the following calculation, but who cares.
		# Note using the print shell builtin to get the current
		# system time in seconds since epoch. It's all about speed.
		# [1] "man boottime" suggests differently, but there
		# is a discrepancy between what uptime reports and
		# this method, which I haven't figured out.
		((upSeconds = $(print -P "%D{%s}") - $(</kern/boottime)))
		# slower alternative would be to parse $(uptime)
		;;
	    darwin*)
		# Darwin has the same info as OpenBSD available as a
		# sysctl parameter. In fact, this method would work as
		# well (perhaps a tad slower) on OpenBSD, if the
		# OpenBSD sysadmin prefers not to leave /kern mounted.
		((upSeconds = $(print -P "%D{%s}") - $(sysctl -n kern.boottime)))
		;;
	esac

	((secs = upSeconds % 60))
	((mins = upSeconds / 60 % 60))
	((hours = upSeconds / 3600 % 24))
	((days = upSeconds / 86400))
	if (( days > 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 </proc/loadavg
		loadavg="$one $five $fifteen"
		;;
	    openbsd*)
		# TODO: openbsd has /kern/loadavg, but what the hell do the #s mean?
		loadavg=$(uptime | sed -e 's/.*load averages: \([.[:digit:]]*\), \([.[:digit:]]*\), \([.[:digit:]]\)/\1 \2 \3/')
		;;
	    darwin*)
		# Darwin leaves the commas out, ala BSD <= 4.1
		loadavg=$(uptime | sed -e 's/.*load averages: \([.[:digit:]]*\) \([.[:digit:]]*\) \([.[:digit:]]\)/\1 \2 \3/')
		;;
	esac
	print $loadavg
}

#############################################################################}}}
### TITLEBAR {{{
################################################################################
prompt_jde_titlebar() {
	[[ -t 1 ]] || return

	# commands like x='\n' cause \n to be expanded here because print
	# by default interprets all of the ascii escape codes, which can
	# screw up the titlebar... bad. So:
	# 1. use print -R to output the actual string
	# 2. make visible any unprintable characters using ${(V)1}
	# TODO: other fail cases? I don't really care what the titlebar
	# says, I just want to make damn sure it's safe.
	local -h line=${(V)1}

	case $TERM in
	    *xterm*|rxvt)
		# don't want prompt expansion or escape codes on the
		# "commandline" string, so split into several prints
		print -Pn "\e]2;%(!.*ROOT*.%n)@%m:"
		print -rn -- "${line}"
		print -n  "\a"
		;;
	    screen)
		# TODO: I don't use screen much, so I don't know if this works
		print -Pn "\e]0;"
		print -rn -- "${line}"
		print -n  "\a"
		;;
	esac
}

prompt_jde_preexec() {
	# update the titlebar with the name of the command before executed...
	# TODO: for example, vim; ^Z; fg will show the title bar as fg
	prompt_jde_titlebar $1
}

#############################################################################}}}
### PRECMD {{{
################################################################################
# This func, precmd, does the grunt work of finding data to put into the prompt
# string (just the top line), with some formatting logic (mostly setting widths
# of horizontal fills). Even though there is a dependency on $COLUMNS, there are
# few assumptions made about the eventual display of the information calculated
# herein.
#  1. The general layout is assumed -- three sections with horizontal fills
#  2. The three sections should be prototyped, without formatting codes, in the
#     variables psvar[1] (left), psvar[2] (middle), and psvar[3] (right). These
#     must be set up before this function is called. (The are set by the ps1
#     function below.)
#  3. $COLUMNS is read to calculate the size of the fill sections between the
#     sections.
# The output of this function is stored in the $psvar array:
#  $psvar[4]:  the max allowable width of the center section (always either the
#     full desired width or 1 character, depending on whether there is enough room
#     or not, a binary outcome.)
#  $psvar[5]:  the max allowable width of the right section, which is the maximum
#     possible space given that the left section is always shown in full.
#  $psvar[6]:  the width of the fill between the left and middle sections
#  $psvar[7]:  the width of the fill between the middle and right sections
#  $psvar[8]:  a string representing the system uptime
#  $psvar[9]:  a string representing the system load average
#  $psvar[10]: the unformatted mail count string
#  $psvar[11]: the formatted mail count string. By formatted, I mean that if a
#     mailbox count changes from the prior invocation to this one, then special
#     codes will bracket the appropriate string to so indicate. The tags are
#     #ON# and #OFF#.
prompt_jde_precmd () {
	setopt localoptions noxtrace noksharrays

	# Mail counting
	typeset -gA PROMPT_JDE_MAILCOUNTS         # assoc holding (maildir count) pairs
	typeset -gA PROMPT_JDE_MAILCOUNTS_OLD     # the former setting (to asses new arrivals)
	local -ha mail_unformatted mail_formatted # arrays holding strings for display
	prompt_jde_mailcounts
	local -h mckey="z"
	for mckey in ${(k)PROMPT_JDE_MAILCOUNTS}; do
		# mail_unformatted holds the key:count strings without
		# formatting.
		# mail_formatted has the same thing, but if new mail count has
		# changed, then the strings are bracketed with #ON#...#OFF# tags
		# to indicate to the gui layer that a highlight is warranted. (I
		# keep gui code out of precmd.)
		mail_unformatted+=("$mckey:$PROMPT_JDE_MAILCOUNTS[$mckey]")
		if (( PROMPT_JDE_MAILCOUNTS[$mckey] != PROMPT_JDE_MAILCOUNTS_OLD[$mckey] )); then
			mail_formatted+=("#ON#$mckey:$PROMPT_JDE_MAILCOUNTS[$mckey]#OFF#")
		else
			mail_formatted+=("$mckey:$PROMPT_JDE_MAILCOUNTS[$mckey]")
		fi
	done

	# The following are dynamic. Need to set them first, as they are
	# embedded in the $psvar[1..3] variables, for which we need to calculate
	# widths here in a sec...
	psvar[8]=$(prompt_jde_uptime)
	psvar[9]=$(prompt_jde_loadavg)
	psvar[10]=${(j: :)mail_unformatted}
	psvar[11]=${(j: :)mail_formatted}

	# now, the hard work of calculating the fill widths
	local -i width1=${#${(%)psvar[1]}}
	local -i width2=${#${(%)psvar[2]}}
	local -i width3=${#${(%)psvar[3]}}
	local -i fillsize_l fillsize_r

	# 1. Calculate the width of the left fill assuming all widgets have full width
	# 2. If not enough room, then disappear the middle widget
	# 3. Calculate the right fill width in light of steps 1 & 2, but assuming the
	#    right fill (pwd) is at full width
	# 4. If not enough room for this fill, then give it as much room as possible
	# 5. Recalculate both fills one last time.

	# the 3 constant allows room for the left and right corners, plus one blank
	# on the right. This last is needed because RPROMPT leaves one blank to the
	# right...
	((fillsize_l = (COLUMNS - 3 - width1 - width2 - width3) / 2))
	if (( fillsize_l < 0 )); then
		width2=1
		((fillsize_l = (COLUMNS - 3 - width1 - width2 - width3) / 2))
	fi
	((fillsize_r = COLUMNS - 3 - width1 - width2 - width3 - fillsize_l))
	if ((fillsize_r < 0)); then
		((width3 = width3 + (fillsize_r * 2) ))
	fi
	((fillsize_l = (COLUMNS - 3 - width1 - width2 - width3) / 2))
	((fillsize_r = COLUMNS - 3 - width1 - width2 - width3 - fillsize_l))

	psvar[4]=$width2
	psvar[5]=$width3
	psvar[6]=$fillsize_l
	psvar[7]=$fillsize_r

	# Update the titlebar before prompt display. Cooler this way than putting the
	# control codes in PS1, I think.
	prompt_jde_titlebar $(print -P "%~")
}

#############################################################################}}}
### PS1 {{{
################################################################################
# This function contains what I call "GUI" code -- it defines the layout and
# colors of the prompt. The heart of the script is here, although there is a
# fairly tight (yet clean) link with precmd.  This func is not called every time
# a new line is entered; that's precmd's job. Rather, it sets up the prompt
# variables PS1 and PS2 so that the prompt will update itself using parameter
# expansion and prompt expansion. To understand the intricacies of this
# function, it will be necessary to follow the zsh manual zshmisc (prompt
# expansion) and zshexpn (parameter expansion).
prompt_jde_ps1 () {
	setopt localoptions noxtrace noksharrays promptsubst

	local -Ah altchar     # assoc holding alternate character codes
	set -A altchar ${(s..)terminfo[acsc]}

	local -h pr_set_charset pr_shift_in pr_shift_out pr_dot pr_hbar \
		pr_vbar pr_lvbar pr_rvbar pr_lrvbar pr_ulcorner pr_llcorner \
		pr_lrcorner pr_urcorner

	if [[ "$PROMPT_JDE_ALTCHAR" == no ]]; then
		pr_set_charset=""
		pr_shift_in=""
		pr_shift_out=""
		pr_dot=":"
		pr_hbar="-"
		pr_vbar="|"
		pr_lvbar="|"
		pr_rvbar="|"
		pr_lrvbar="|"
		pr_ulcorner="-"
		pr_llcorner="-"
		pr_lrcorner="-"
		pr_urcorner="-"
	else
		pr_set_charset="%{$terminfo[enacs]%}"
		pr_shift_in="%{$terminfo[smacs]%}"
		pr_shift_out="%{$terminfo[rmacs]%}"
		pr_dot=${altchar[~]:-:}
		pr_hbar=${altchar[q]:--}
		pr_vbar=${altchar[x]:-|}
		pr_lvbar=${altchar[u]:-|}
		pr_rvbar=${altchar[t]:-|}
		pr_lrvbar=${altchar[n]:-|}
		pr_ulcorner=${altchar[l]:--}
		pr_llcorner=${altchar[m]:--}
		pr_lrcorner=${altchar[j]:--}
		pr_urcorner=${altchar[k]:--}
	fi

	#########################
	# CONFIGURE COLORS HERE #
	#########################
	local -h         rs="%{$reset_color%}"
	local -h        bkg="%{$bg[black]%}"
	local -h   normtext="%{$bg[black]$fg_bold[green]%}"
	local -h     hitext="%{$bg[black]$fg_no_bold[white]%}"
	local -h    invtext="%{$bg[black]$fg_bold[cyan]%}"
	local -h  alerttext="%{$bg[red]$fg_bold[yellow]%}"
	local -h figuretext="%{$bg[black]$fg_bold[yellow]%}"
	local -h   linetext="%{$bg[black]$fg_no_bold[yellow]%}"
	#########################
	#    END COLOR CONFIG   #
	#########################

	local -h        sep="${figuretext}${pr_shift_in}${pr_dot}${pr_shift_out}"
	local -h       user="%(#.$alerttext.$normtext)%(!.%U.)%n%(!.%u$bkg.)"
	local -h         at="${normtext}@"
	local -h       host="${hitext}%m"
	local -h        tty="${normtext}%l"
	local -h    mailcnt
	if [[ $PROMPT_JDE_MAILCOUNT == yes ]]; then
		mailcnt="$sep ${normtext}\${\${psvar[11]//\\#ON\\#/\"$alerttext\"}//\\#OFF\\#/\"$normtext\"} "
	else
		mailcnt=""
	fi
	local -h     uptime="${normtext}%8v"
	local -h    loadavg="${normtext}%9v"
	local -h       date="${normtext}%D"
	local -h       time="${normtext}%T"
	local -h      grbeg="${figuretext}${pr_hbar}${pr_lvbar}"
	local -h      grend="${figuretext}${pr_rvbar}${pr_hbar}"
	local -h   exitcode="${normtext}?%(?.${invtext}.${alerttext})%?$bkg"
	local -h     histnr="${normtext}!${invtext}%!"
	local -h         pr="${normtext}%#"
	local -h         wd="${normtext}%U%~%u${normtext}"

	# the following hold non-colorized versions of the first line prompt elements
	# for use by precmd in determining string widths. NOTE: precmd expects
	# these to be set!
	if [[ $PROMPT_JDE_MAILCOUNT == yes ]];then
		psvar[1]="-[ %n@%m : %l : %10v ]-" # left widget
	else
		psvar[1]="-[ %n@%m : %l ]-"        # left widget
	fi
	psvar[2]="-[ %8v : %9v ]-"                 # middle widget
	psvar[3]="-[ %~ ]-"                        # right widget

	local -ah ps1 ps2 rps1

	ps1=("$pr_set_charset$pr_shift_in"
	     "$figuretext$pr_ulcorner"
	     # The first widget is very simple
	     "$grbeg$pr_shift_out $user$at$host $sep $tty $mailcnt$pr_shift_in$grend"
	     # Next comes the first fill. $psvar[6] contains the width of the fill...
	     # use ${(l.$psvar[6]..$pr_hbar.)} to create the fill string
	     # Note, whenever we use parameter interpolation, we have to backwhack the \$
	     "$linetext\${(l.\${psvar[6]}..${pr_hbar}.)}" # fill left
	     # The following two lines implement the middle widget. Some notes:
	     #  1. The uptime text is in $psvar[8], and the loadavg text is in $psvar[9]
	     #  2. $psvar[4]  will equal either 1 (if not enough room) or the required
	     #     length for the middle widget
	     #  3. We truncate (using %<< construct) the widget to $psvar[4]
	     #  4. %%8v<blah< doesn't work! (And even %[%8vblah] doesn't!) So we have to
	     #     resort to parameter interpolation... ah well.
	     #  5. The truncation string is $pr_hbar, meaning if there isn't room, then
	     #     we draw a single - instead
	     #  6. The widget itself is pretty normal, except we replace the "d" in the
	     #     uptime string with a different color using ${x/y/z}. Why do I torture
	     #     myself?
	     #     a. Tricky bit #1: the replacement string includes control codes and
	     #        therefore } characters! So we have to quote it with \"
	     #     b. Tricky bit #2: $ interpolation is done BEFORE % interpolation in
	     #        prompts, therefore we cant use %8v, we have to use \$psvar[8]
	     "%\$psvar[4]<$pr_hbar<"
	     "$grbeg$pr_shift_out $normtext\${psvar[8]/d/\"${hitext}d${normtext}\"} $sep $normtext%9v $pr_shift_in$grend"
	     "%<<"  # end the truncation
	     # Next comes the second fill. $psvar[7] contains its width...
	     "$linetext\${(l.\${psvar[7]}..${pr_hbar}.)}" # fill right
	     "$grbeg"
	     "$pr_shift_out"
	     # The $PWD widget (but only the part inside the groupings) is truncated
	     # to the length dictated by $psvar[5] (note $psvar[5] width is reduced by 6
	     # to allow for the group ends, which are always visible)
	     " %\$[psvar[5] - 6]<...<$wd%<< "
	     "$pr_shift_in"
	     "$grend"
	     "$figuretext$pr_urcorner"
	     "$pr_shift_out"
	     "$rs"
	     "$prompt_newline"
	     # Second line. Nothing very interesting here
	     "$pr_shift_in"
	     "$figuretext$pr_llcorner"
	     "$grbeg"
	     "$pr_shift_out"
	     " $exitcode $sep $histnr $sep $pr "
	     "$pr_shift_in"
	     "$grend"
	     "$pr_shift_out"
	     "$rs"
	     $' ' )
	PS1="${(j::)ps1}"

	rps1=("$pr_set_charset$pr_shift_in"
	      "$grbeg"
	      "$pr_shift_out"
	      " $time $sep $date "
	      "$pr_shift_in"
	      "$grend"
	      "$figuretext$pr_lrcorner"
	      "$pr_shift_out"
	      "$rs" )
	RPS1="${(j::)rps1}"

	# The following string, when interpolated at runtime (note,
	# not here, of course) with PARAMETER expansion
	# (note, not prompt expansion), should produce a string of
	# exactly the same width as line 2 of PS1, the part between
	# the $grbeg and $grend -- i.e., the content.
	# It must also avoid containing right curlies '}' after
	# interpolation. Finally, it should avoid any control
	# codes since those may be counted with ${#} (which is how
	# it's used in PS2) which we don't want.
	local -h ps1line2=' ?${(%):-%?} : !${(%):-%!} : # '

	ps2=("$pr_set_charset$pr_shift_in"
	     "$bkg $grbeg"
	     "$pr_shift_out"
	     # The following allows us to align the ps2 right side
	     # with the ps1 right side -- a cool visual effect.
	     #
	     # The downside is if %_ (which contains "for dquote..."
	     # type information -- the parser stack) can get
	     # truncated. To overcome this limitation, we show only
	     # the rightmost element of %_, along with the parser
	     # stack depth. More below...
	     #
	     # First, to align things, the strategy is to set up a
	     # right side truncation (%> >) 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 "$@"

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: prompt
  2005-02-24 19:30 prompt Joel David Elkins
@ 2005-02-27 16:47 ` William H. Magill
  0 siblings, 0 replies; 8+ messages in thread
From: William H. Magill @ 2005-02-27 16:47 UTC (permalink / raw)
  To: Joel David Elkins; +Cc: zsh-users

On 24 Feb, 2005, at 14:30, Joel David Elkins wrote:
> 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!

Wonderful stuff!

(And I used to think I was a masochist!!!)

Since I run on multiple platforms, it's exactly the kind of thing I 
wind up doing!
(And why I like 21 inch monitors at 1280x1024...)

My mind is still boggled from reading that code. It's going to take 
while to absorb it all.

T.T.F.N.
William H. Magill
# Beige G3 [Rev A motherboard - 300 MHz 768 Meg] OS X 10.2.8
# Flat-panel iMac (2.1) [800MHz - Super Drive - 768 Meg] OS X 10.3.7
# PWS433a [Alpha 21164 Rev 7.2 (EV56)- 64 Meg] Tru64 5.1a
# XP1000  [Alpha 21264-3 (EV6) - 256 meg] FreeBSD 5.3
# XP1000  [Alpha 21264-A (EV 6.7) - 384 meg] FreeBSD 5.3
magill@mcgillsociety.org
magill@acm.org
magill@mac.com
whmagill@gmail.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: PROMPT
  1999-06-17 15:20     ` PROMPT Peter Stephenson
@ 1999-06-17 16:42       ` Bart Schaefer
  0 siblings, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 1999-06-17 16:42 UTC (permalink / raw)
  To: zsh-users

On Jun 17,  5:32pm, Oliver Grimm wrote:
} Subject: Re: PROMPT
}
}         precmd ()
}         {
}             if test "$UID" = 0; then
}                 PS1="%m:`pwd -r` # "
}             else
}                 PS1="%n@%m:`pwd -r` > "
}             fi
}         }
} 
} this defines a function that is called every time anything is executed
} by the shell, and so also make a change of PROMPT impossible.
} 
} I wonder if this was intended by the designer of the profile ?

I doubt that the side-effect of preventing the user from customizing his
prompt was intentional.

On Jun 17,  5:20pm, Peter Stephenson wrote:
} Subject: Re: PROMPT
}
} I can hardly believe it.
} 
} setopt chaselinks
} PS1='%n@%m:%/'

For completeness:

PS1='%(#..%n@)%m:%/%(#.#.>) '

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: PROMPT
  1999-06-16 15:42 ` PROMPT Bart Schaefer
@ 1999-06-17 15:32   ` Oliver Grimm
  1999-06-17 15:20     ` PROMPT Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: Oliver Grimm @ 1999-06-17 15:32 UTC (permalink / raw)
  To: zsh-users



Sorry, I meant to write that PROMPT=Hallo does not work - forget the
equal sign in my first mail.

I am not using RedHat, but Suse Linux 6.1. But I figured out the problem
now:

The /etc/zshrc file sources /etc/profile, which contains the following:

if test -z "$EMACS" ; then
    if   [ -n "$ZSH_VERSION" ]; then
        precmd ()
        {
            if test "$UID" = 0; then
                PS1="%m:`pwd -r` # "
            else
                PS1="%n@%m:`pwd -r` > "
            fi
        }
    fi
fi

Uncommenting the second PS1=... lines solved the problem. I assume that
this defines a function that is called every time anything is executed
by the shell, and so also make a change of PROMPT impossible.

I wonder if this was intended by the designer of the profile ?

Cheers, Oliver.

> } I do have a strange problem with the PROMPT variable, persisting since
> } some time. After upgrading to Linux 6.1, the command
> } 'PROMPT  Hallo' does not change the prompt anymore.
> } 
> } Now, the version of zsh is 3.0 (dated 26 June 1996), but it seems
> } that it's not the fault of zsh, since on a different machine with the
> } same version of zsh (but not under Linux but Solaris Unix), this
> } does work properly.
> 
> Did you recompile zsh after installing the new OS, or are you still
> running the old binary?  I've had a number of strange problems when
> running older Linux binaries on my upgraded OS, including things like
> some of the libc string functions not working correctly -- neither the
> "par" paragraph-formatting package nor the old zmail beta that I'd been
> using as my mailer could parse text properly any more, and the slightly
> newer version of zmail that I'm using now is unable to get the correct
> timezone (you may note that my Date: headers say +0000, though they do
> contain the GMT it would be if I were instantly teleported to England).
> 
> If `Linux 6.1' really does mean RedHat, you should install the zsh-3.0.5
> RPM (and then carefully consider deleting the /etc/z* files) and let us
> know if the problem persists.
> 
> -- 
> Bart Schaefer                                 Brass Lantern Enterprises
> http://www.well.com/user/barts              http://www.brasslantern.com
> 

=====================================================================
Oliver Grimm			   EMail: grimm@particle.phys.ethz.ch
ETH ZÜrich			   Telephone: ++41 - (0)1 - 633 65 01
Labor fÜr Hochenergiephysik	   Facsimile: ++41 - (0)1 - 633 11 04
CH-8093 ZÜrich


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: PROMPT
  1999-06-17 15:32   ` PROMPT Oliver Grimm
@ 1999-06-17 15:20     ` Peter Stephenson
  1999-06-17 16:42       ` PROMPT Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 1999-06-17 15:20 UTC (permalink / raw)
  To: zsh-users, Oliver Grimm

Oliver Grimm wrote:
> The /etc/zshrc file sources /etc/profile, which contains the following:
> 
> if test -z "$EMACS" ; then
>     if   [ -n "$ZSH_VERSION" ]; then
>         precmd ()
>         {
>             if test "$UID" = 0; then
>                 PS1="%m:`pwd -r` # "
>             else
>                 PS1="%n@%m:`pwd -r` > "
>             fi
>         }
>     fi
> fi
> 
> I wonder if this was intended by the designer of the profile ?

I can hardly believe it. The correct way of doing this, by the way, is

setopt promptsubst
PS1='%n@%m:`pwd -r`'

or if you insist on having the physical directory (the -r argument to pwd),
it might be better to have

setopt chaselinks
PS1='%n@%m:%/'

but using precmd() just to get the raw directory into the prompt is serious
overkill.

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: PROMPT
  1999-06-16  9:27 PROMPT Oliver Grimm
  1999-06-16 14:33 ` PROMPT Larry P. Schrof
@ 1999-06-16 15:42 ` Bart Schaefer
  1999-06-17 15:32   ` PROMPT Oliver Grimm
  1 sibling, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 1999-06-16 15:42 UTC (permalink / raw)
  To: Oliver Grimm; +Cc: zsh-users

On Jun 16, 11:27am, Oliver Grimm wrote:
} Subject: PROMPT
}
} I do have a strange problem with the PROMPT variable, persisting since
} some time. After upgrading to Linux 6.1, the command
} 'PROMPT  Hallo' does not change the prompt anymore.
} 
} Now, the version of zsh is 3.0 (dated 26 June 1996), but it seems
} that it's not the fault of zsh, since on a different machine with the
} same version of zsh (but not under Linux but Solaris Unix), this
} does work properly.

Did you recompile zsh after installing the new OS, or are you still
running the old binary?  I've had a number of strange problems when
running older Linux binaries on my upgraded OS, including things like
some of the libc string functions not working correctly -- neither the
"par" paragraph-formatting package nor the old zmail beta that I'd been
using as my mailer could parse text properly any more, and the slightly
newer version of zmail that I'm using now is unable to get the correct
timezone (you may note that my Date: headers say +0000, though they do
contain the GMT it would be if I were instantly teleported to England).

If `Linux 6.1' really does mean RedHat, you should install the zsh-3.0.5
RPM (and then carefully consider deleting the /etc/z* files) and let us
know if the problem persists.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: PROMPT
  1999-06-16  9:27 PROMPT Oliver Grimm
@ 1999-06-16 14:33 ` Larry P. Schrof
  1999-06-16 15:42 ` PROMPT Bart Schaefer
  1 sibling, 0 replies; 8+ messages in thread
From: Larry P. Schrof @ 1999-06-16 14:33 UTC (permalink / raw)
  To: Oliver Grimm; +Cc: zsh-users

Couple of things.

On Wed, Jun 16, 1999 at 11:27:42AM +0200, Oliver Grimm wrote:
> I do have a strange problem with the PROMPT variable, persisting since
> some time. After upgrading to Linux 6.1, the command

I'm assuming you mean "Redhat 6.1". There are plenty of other brands
of Linux with their own version numbers. :)

> 'PROMPT  Hallo' does not change the prompt anymore.

PROMPT is a shell parameter, so you want to set it in the supported,
standard way. (Regardless of what other syntactical methods work or
don't work). In zsh, the way I do this is

PROMPT=<SOME_STRING>

> 
> Now, the version of zsh is 3.0 (dated 26 June 1996), but it seems
> that it's not the fault of zsh, since on a different machine with the
> same version of zsh (but not under Linux but Solaris Unix), this
> does work properly.
> 
> Does someone has an idea what causes this problem ? Me and our
> system operator haven't found a clue so far.
> 
> Regards, Oliver Grimm.
>  
> =====================================================================
> Oliver Grimm			   EMail: grimm@particle.phys.ethz.ch
> ETH ZÜrich			   Telephone: ++41 - (0)1 - 633 65 01
> Labor fÜr Hochenergiephysik	   Facsimile: ++41 - (0)1 - 633 11 04
> CH-8093 ZÜrich
> 
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* PROMPT
@ 1999-06-16  9:27 Oliver Grimm
  1999-06-16 14:33 ` PROMPT Larry P. Schrof
  1999-06-16 15:42 ` PROMPT Bart Schaefer
  0 siblings, 2 replies; 8+ messages in thread
From: Oliver Grimm @ 1999-06-16  9:27 UTC (permalink / raw)
  To: zsh-users


I do have a strange problem with the PROMPT variable, persisting since
some time. After upgrading to Linux 6.1, the command
'PROMPT  Hallo' does not change the prompt anymore.

Now, the version of zsh is 3.0 (dated 26 June 1996), but it seems
that it's not the fault of zsh, since on a different machine with the
same version of zsh (but not under Linux but Solaris Unix), this
does work properly.

Does someone has an idea what causes this problem ? Me and our
system operator haven't found a clue so far.

Regards, Oliver Grimm.
 
=====================================================================
Oliver Grimm			   EMail: grimm@particle.phys.ethz.ch
ETH ZÜrich			   Telephone: ++41 - (0)1 - 633 65 01
Labor fÜr Hochenergiephysik	   Facsimile: ++41 - (0)1 - 633 11 04
CH-8093 ZÜrich




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-02-27 16:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-24 19:30 prompt Joel David Elkins
2005-02-27 16:47 ` prompt William H. Magill
  -- strict thread matches above, loose matches on Subject: below --
1999-06-16  9:27 PROMPT Oliver Grimm
1999-06-16 14:33 ` PROMPT Larry P. Schrof
1999-06-16 15:42 ` PROMPT Bart Schaefer
1999-06-17 15:32   ` PROMPT Oliver Grimm
1999-06-17 15:20     ` PROMPT Peter Stephenson
1999-06-17 16:42       ` PROMPT Bart Schaefer

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).