From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13451 invoked from network); 21 Sep 2008 09:40:21 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=AWL,BAYES_00,URIBL_GREY, WHOIS_MONIKER_PRIV autolearn=no version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 21 Sep 2008 09:40:21 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 95452 invoked from network); 21 Sep 2008 09:40:16 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 21 Sep 2008 09:40:16 -0000 Received: (qmail 23478 invoked by alias); 21 Sep 2008 09:40:10 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25698 Received: (qmail 23462 invoked from network); 21 Sep 2008 09:40:10 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 21 Sep 2008 09:40:10 -0000 Received: from mx.spodhuis.org (redoubt.spodhuis.org [193.202.115.177]) by bifrost.dotsrc.org (Postfix) with ESMTPS id 32E06802720D for ; Sun, 21 Sep 2008 11:40:00 +0200 (CEST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=d200807; d=spodhuis.org; h=Received:Date:From:To:Subject:Message-ID:Mail-Followup-To:References:MIME-Version:Content-Type:Content-Disposition:Content-Transfer-Encoding:In-Reply-To; b=P0UrjMKFLtl5zAm4Em56tVqJp9SrzEDgJpFb1kdfB4Ea2nNTstbRgCH1BWgtoUrg9V6VNgfPH6cZqHeorYYLdQg8rBaRW8R2w77GGnsTfHaaPNjqEuLbL5oii5WEi4yUm+dGMJbyxE/yo1/2I30K9qs3t9ycXD2hS5YaEEsGGyk=; Received: by smtp.spodhuis.org with local id 1KhLQ6-0008zY-GO; Sun, 21 Sep 2008 09:39:58 +0000 Date: Sun, 21 Sep 2008 02:39:58 -0700 From: Phil Pennock To: zsh-workers Subject: Re: Submitting vcs_info function Message-ID: <20080921093958.GA34405@redoubt.spodhuis.org> Mail-Followup-To: zsh-workers References: <20080917201859.GU2182@fsst.voodoo.lan> <20080917203242.GV2182@fsst.voodoo.lan> <20080921091111.GA26463@scru.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20080921091111.GA26463@scru.org> X-Virus-Scanned: ClamAV 0.92.1/8296/Sun Sep 21 05:04:54 2008 on bifrost X-Virus-Status: Clean 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 { <' 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 '' 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------------------------------