Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Coolest prompt?



On 2004-06-15 17:18:40 +0200, Julius Plenz wrote:
> To see this Prompt in action, look at this example:
> 
> e/www/plenz,0% cd www/
> w/plenz/www,0% cd plenz.com/
> w/plenz.com,0% cd /tmp
>        /tmp,0% sleep 10&
> [1] 16056
>        /tmp,1% cd
> [1]  + 16056 done       sleep 10
> e/www/plenz,0%
> 
> So, you see, there is a fixed path-length and the number of
> background jobs. I really like this prompt, its simple but gives
> enough information.

You could avoid to write ",0" when there are no background jobs.

Here's my prompt code:

setopt PROMPT_SUBST
setopt PROMPT_PERCENT

zmodload -i zsh/parameter

precmd()
{
  local njobs
  if [[ $domain == local.ay && "$(pmu_battery)" == "Battery" ]] then
    psvar[1]="[$(pmu_percent)%]"
  else
    psvar[1]=""
  fi
  njobs=$#jobstates;
  case $njobs in
    0) psvar[2]=();;
    1) psvar[2]="1 job";;
    *) psvar[2]="$njobs jobs";;
  esac
  [[ -n $TTY && $TERM == (xterm*|dtterm|rxvt|screen*) ]] &&
    {
      print -nP "\e]1;%m:%.\x07"
      print -nP "\e]2;%(2v. %2v |.)${WINTITLE:+ $WINTITLE |} %n@%m - %~ | %y"
      [[ $TERM == screen* ]] && print -n .
      print -n "\x07"
    } > $TTY
}

TRAPCLD() { [[ -o interactive && -n $TTY ]] && precmd }

putprompt()
{
  local preprompt postprompt prefail postfail

  if [[ -n $COLORTERM ]] then
    local bgcol=`tput setab 0`
    preprompt="%{`tput bold`$bgcol%(2v.`tput setaf 2`.`tput setaf 3`)%}"
    postprompt="%{`tput sgr0`%}"
    prefail="%{`tput setab 1`%}"
    postfail="%{$bgcol%}"
  fi

  PS1="%m:%20<...<%~%<<%(?..${prefail}[%?]${postfail})%1v%(#.#.>) "
  RPS1="<%*"

  PS1="$preprompt$PS1$postprompt"
  RPS1="$preprompt$RPS1$postprompt"
  PS2="$preprompt$PS2$postprompt"
  PS3="$preprompt$PS3$postprompt"
  PS4="$preprompt$PS4$postprompt"
}

putprompt

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.org/>
100% validated (X)HTML - Acorn / RISC OS / ARM, free software, YP17,
Championnat International des Jeux Mathématiques et Logiques, etc.
Work: CR INRIA - computer arithmetic / SPACES project at LORIA



Messages sorted by: Reverse Date, Date, Thread, Author