Any variable can have a .get method so it would be hard so single out PS1
and ignore the exit value for that.  The way that Mark McCullough did it is
the way to do it.  I do the same for the bash emulation when I emulate
their PS1 expansion.



On Sun, Dec 28, 2014 at 2:45 PM, Mark McCullough <mark.mc...@gmail.com>
wrote:

> Have you tried making the first part of PS1.get retrieve $? and put it in
> a holder var.  Then the last part of PS1.get returns that value.
>
> Quick mock-up
> function PS1.get {
>     typeset retval=$?
>     echo "Last command returned $retval"
>     return $retval
> }
>
> I do something similar all the type in my standard PS1.get which modifies
> PS1 based on $?
>
> I did some testing and it certainly seems to work per what you'd like to
> do.
>
> > On 2014 Dec 28, at 11:15 , Terrence J. Doyle <
> terrence.j.doyle+...@gmail.com> wrote:
> >
> >
> >    No, this is not another bug report.
> >
> >    I've been experimenting with the discipline function PS1.get. It has
> > the advantage that it can place more dynamic information in the prompt
> > than the variable. For instance, it's possible to get the current load
> > average in the prompt with PS1.get.
> >
> >    The main drawback is that $? then gets set from the return value of
> > PS1.get. So, if PS1.get is defined, $? must be viewed/obtained before
> > the prompt reappears. It would be nice if $? could be saved just after
> > the current command executes but before PS1.get executes, then restored
> > after PS1.get finishes.
> >
> >    Here's a demonstration of putting the load average into the prompt
> > with PS1.get:
> >
> > $ function PS1.get
> >> {     typeset IFS=,
> >>      typeset -a uptime=($(uptime))
> >>
> >>      .sh.value="${uptime[${#uptime[@]} - 1]} $ "
> >>      }
> > load averages: 0.97 1.32 0.98 $ false
> > load averages: 1.12 1.34 0.99 $ echo $?
> > 0
> > load averages: 1.03 1.31 0.99 $ false; echo $?
> > 1
> > load averages: 0.87 1.27 0.98 $ unset -f PS1.get
> > PS1='$ '
> > $
> >
> >
> >                    Terrence Doyle
> > _______________________________________________
> > ast-users mailing list
> > ast-users@lists.research.att.com
> > http://lists.research.att.com/mailman/listinfo/ast-users
>
>
> ----
> "The speed of communications is wondrous to behold. It is also true that
> speed can multiply the distribution of information that we know to be
> untrue." Edward R Murrow (1964)
>
> Mark McCullough
> mark.mc...@gmail.com
>
>
>
>
> _______________________________________________
> ast-users mailing list
> ast-users@lists.research.att.com
> http://lists.research.att.com/mailman/listinfo/ast-users
>
_______________________________________________
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to