bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PATCH: Add \? to get PIPESTATUS information in the prompt


From: Paul Jarc
Subject: Re: PATCH: Add \? to get PIPESTATUS information in the prompt
Date: Tue, 04 Sep 2001 21:46:21 -0400
User-agent: Gnus/5.090004 (Oort Gnus v0.04) Emacs/20.7

"Wesley J Landaker" <address@hidden> wrote:
> I use bash all the time, but there is one thing that always bugged me 
> that tcsh had that bash didn't: the ability to get the return code from 
> the last process (or pipeline) embedded easily in the prompt.
> 
> This is possible to do, sure, with PROMPT_COMMAND and so forth, but 
> it's rather annoying, because running PROMPT_COMMAND actually modifies 
> PIPESTATUS, and so forth.

You can save $? befare doing anything else, and restore it at the end.
I use this:
function ps1 {
  local s="${?#0}" pwd="$PWD"
  [ "$hash" = '' ] && pwd="${pwd/#$HOME/~}"
  echo -n "$hash${s:+$s:}${HOSTNAME%%.*}:${pwd%/}/ "
  return "${s:-0}"
}
PS1='$(ps1)'
hash=
case "$(id)" in (uid=0\(*) hash='#';; esac


paul



reply via email to

[Prev in Thread] Current Thread [Next in Thread]