From: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
To: zsh-workers <zsh-workers@sunsite.dk>
Subject: Re: Submitting vcs_info function
Date: Sun, 21 Sep 2008 02:39:58 -0700 [thread overview]
Message-ID: <20080921093958.GA34405@redoubt.spodhuis.org> (raw)
In-Reply-To: <20080921091111.GA26463@scru.org>
On 2008-09-21 at 09:11 +0000, Clint Adams wrote:
> On Wed, Sep 17, 2008 at 10:32:42PM +0200, Frank Terbeck wrote:
> > +If you plan to use the information from var(vcs_info) in your prompt (which
> > +is its primary use), you need to enable the tt(PROMPT_SUBST) option.
>
> I don't think that this claim is accurate.
Ditto. Although it would be nice if vcs_info made all the different
variables available in a $Z_VCS hash or somesuch, so that I didn't need
to zstyle from my prompt.
FWIW, here's a lightly modified version of the prompt I'm using now,
built up over years, originally with help from zefram@ and then later
with some attention to Bart's setup and generally munged about. I
finally updated it to use the new colour codes, since the vcs_info stuff
led to me using more elements of $psvar, deciding to add %(V..)
conditional to check if set and then seeing that CVS had already done
just that. Convenient. :)
Reports screen WINDOW, SHLVL, previous command exit status (including
signal name if sig-exit), count of backgrounded jobs, repository
information plus the usual bits. Has some automatic screen titling
stuff in the prompt too.
----------------------------8< cut here >8------------------------------
# Phil's prompt setup for zsh
#
# $HeadURL: https://svn.spodhuis.org/ksvn/spodhuis-tools/zsh/site-functions/prompt_pdp-vcs_setup $
# $Id: prompt_pdp-vcs_setup 239 2008-09-20 21:37:30Z xxx@SPODHUIS.ORG $
#
# Installs somewhere in fpath; typically one of:
# /usr/globnix/share/zsh/site-functions/prompt_pdp-vcs_setup
# ~/bin/zsh-functions/
#
# Requires: zsh 4.3.7 or newer (for %(V..) prompt conditional)
zmodload -i zsh/parameter || return 1
function prompt_pdp-vcs_help {
<<EOF
This prompt shows some information always and some when necessary.
The information depends in part upon \$TERM, as does emission of a
title-changing escape sequence (for xterms, etc).
OnDemand: '[num]' showing the SHLVL if not 1.
OnDemand: '{errcode}' or '{SIGNAME}' if previous command not successful.
Backgrounded jobs indication; '-' for none or '<+num>' showing count.
Then: usercode@machine.2ndlevel:tty[time]
OnDemand: VCS repository information
Then: (history-num)
A left-truncated section of the pwd.
The %/# prompt character and a space.
Right-hand prompt: VCS type or absent
TERM=screen: prefix '<WINDOW>' and a screen-magic escape sequence for titling.
Optional prompt setup parameters:
update -- do not reset any colour variables
EOF
}
function prompt_pdp-vcs_precmd {
local exitstatus=$?
emulate -L zsh # ksh_arrays breaks us badly
psvar=()
psvar[1]=SIG
[[ $exitstatus -ge 128 ]] && psvar[1]=SIG$signals[$exitstatus-127]
[[ $psvar[1] == SIG ]] && psvar[1]=$exitstatus
vcs_info
psvar[2]=$#jobstates; [[ $psvar[2] -eq 0 ]] && psvar[2]=''
psvar[3]=$VCS_INFO_message_1_
psvar[4]=$VCS_INFO_message_0_
return $exitstatus
}
function prompt_pdp-vcs_setup__colour {
local endc
typeset -gA prompt_pdp_vcs__hl prompt_pdp_vcs__ehl
prompt_pdp_vcs__hl=()
prompt_pdp_vcs__ehl=()
prompt_pdp_vcs__hl[name]='%F{green}'
prompt_pdp_vcs__hl[mach]='%F{yellow}'
#prompt_pdp_vcs__hl[time]='%F{yellow}'
prompt_pdp_vcs__hl[level]='%U'
prompt_pdp_vcs__ehl[level]='%u'
prompt_pdp_vcs__hl[error]='%B%F{red}'
prompt_pdp_vcs__ehl[error]='%f%b'
prompt_pdp_vcs__hl[jobcount]='%B'
prompt_pdp_vcs__ehl[jobcount]='%b'
# commandcount here
prompt_pdp_vcs__hl[path]='%F{cyan}'
prompt_pdp_vcs__hl[window]='%B%F{magenta}'
prompt_pdp_vcs__ehl[window]='%f%b'
prompt_pdp_vcs__hl[root]='%K{red}'
prompt_pdp_vcs__ehl[root]='%k'
prompt_pdp_vcs__hl[vcstype]='%F{green}'
prompt_pdp_vcs__hl[vcsbranch]='%F{magenta}'
return 1
}
function prompt_pdp-vcs_hl {
local what="$1"; shift
local text="$1"; shift
local start end
start="${prompt_pdp_vcs__hl[$what]}"
if [[ -z $start ]]; then
end=''
else
end="${prompt_pdp_vcs__ehl[$what]}"
: ${end:='%f'}
fi
print -r -- "${start}${text}${end}"
}
function prompt_pdp-vcs_setup {
local -h name root host mach line time level error jobc pathdisp vcs
local -h p1 prefix='' trunclen=40
local -h employer
local -h docolour=:
[[ $1 == update ]] && docolour=false
# this should be set by a style:
local -h hostlabelcount=2
# foo.local stet; foo.example.tld => foo; foo.bar.example.tld => foo.bar
# foo.bar.example.co.cc => foo.bar; BUT foo.example.co.cc => foo.example
# (the last accepted reluctantly as the best that can be done without
# encoding per-TLD hierarchy information)
[[ ${#${HOST//[^\.]/}} -eq 2 ]] && hostlabelcount=1
[[ -n $COLORTERM ]] && $docolour && prompt_pdp-vcs_setup__colour "$@"
case ${TERM} in
(putty|xterm*)
[[ -z $COLORTERM ]] && export COLORTERM="$TERM"
function chpwd { [[ -t 0 ]] || return; print -Pn "\e]2;%n@%${hostlabelcount}m:%~\a" }
$docolour && prompt_pdp-vcs_setup__colour
chpwd
;;
(screen|screen.*)
unfunction chpwd >/dev/null 2>&1 || true
# \x5c is backslash '\'; screen(1) §TITLES
prefix="$(prompt_pdp-vcs_hl window "<$WINDOW>")%{$(print '\ek\e\x5c')%}"
trunclen=33
;;
(cons*|linux)
[[ -z $COLORTERM ]] && export COLORTERM="$TERM"
unfunction chpwd >/dev/null 2>&1 || true
$docolour && prompt_pdp-vcs_setup__colour
;;
(*)
unfunction chpwd >/dev/null 2>&1 || true
;;
esac
zstyle ':vcs_info:*' branchformat %b:%r
zstyle ':vcs_info:*' formats %b %s
zstyle ':vcs_info:*' actionformats "%b|%a" %s
# Employer-dependent $HOST check elided from post
employer=''
root="$(prompt_pdp-vcs_hl root %n)"
name="$(prompt_pdp-vcs_hl name "%(#.${root}.%n)")"
host="$(prompt_pdp-vcs_hl mach "%${hostlabelcount}m")"
line="$(prompt_pdp-vcs_hl line '%l')"
time="$(prompt_pdp-vcs_hl time '[%T]')"
level="%2(L.$(prompt_pdp-vcs_hl level '[%L]').)"
error="%(?..$(prompt_pdp-vcs_hl error '{%v}'))"
jobc="%(2V:<$(prompt_pdp-vcs_hl jobcount '+%2v')>:-)"
cmdc="($(prompt_pdp-vcs_hl commandcount '%!'))"
pathdisp="$(prompt_pdp-vcs_hl path "%${trunclen}<..<%~%<<")"
vcs="%(3V:$(prompt_pdp-vcs_hl vcsbranch '<%4v>'):)"
PS1="$prefix$level$error$jobc$name@$host$employer:$line$time$vcs$cmdc$pathdisp%# "
PS2='%(4_:... :)%3_> '
RPS1="%(3V:$(prompt_pdp-vcs_hl vcstype '(%3v)'):)"
psvar=()
function precmd { prompt_pdp-vcs_precmd }
function preexec { }
}
prompt_pdp-vcs_setup "$@"
----------------------------8< cut here >8------------------------------
next prev parent reply other threads:[~2008-09-21 9:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20080917201859.GU2182@fsst.voodoo.lan>
[not found] ` <20080918112003.45911104@news01>
[not found] ` <20080918165212.GY2182@fsst.voodoo.lan>
[not found] ` <200809181700.m8IH0rmj019423@news01.csr.com>
[not found] ` <20080919093449.GI2182@fsst.voodoo.lan>
[not found] ` <20080919140229.3c4e9fcd@news01>
[not found] ` <20080919133411.GN2182@fsst.voodoo.lan>
2008-09-19 14:57 ` Frank Terbeck
[not found] ` <20080917203242.GV2182@fsst.voodoo.lan>
2008-09-21 9:11 ` Clint Adams
2008-09-21 9:39 ` Phil Pennock [this message]
2008-09-21 10:00 ` Phil Pennock
2008-09-21 10:23 ` Frank Terbeck
2008-09-22 17:17 ` Clint Adams
2008-09-21 19:57 ` Clint Adams
2008-09-21 20:32 ` Frank Terbeck
2008-09-22 6:42 ` Clint Adams
[not found] <20080917201859.GU2182__38438.7229955339$1221682908$gmane$org@fsst.voodoo.lan>
2008-09-17 23:05 ` Michael Prokop
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=20080921093958.GA34405@redoubt.spodhuis.org \
--to=zsh-workers+phil.pennock@spodhuis.org \
--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).