[Top][All Lists]

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

Re: shouldn't prompt printing be smarter?

From: Bob Proulx
Subject: Re: shouldn't prompt printing be smarter?
Date: Sun, 1 Apr 2007 12:06:20 -0600
User-agent: Mutt/1.5.9i

Francesco Montorsi wrote:
> PROMPT_COMMAND='echo -ne "\033]0;${PWD/$HOME/~}\007"'

That looks okay to me.  It sets the working directory as the xterm
window title.

> PS1='${debian_chroot:+($debian_chroot)}\[\033[01;address@hidden:\[\033[01;34m\]\w\[\033[00m\]\$
> '
> what is it btw?

That is a pretty standard Debian setting that looks to see if you are
running inside of a chroot.  Normally inside of a chroot on Debian
systems the file /etc/debian_chroot has been set (I wish it were a
more generic name) to the name of the chroot.  That is used to set the
debian_chroot variable.  The variable setting is used in the prompt
itself.  You have the color prompt setting uncommented which is pretty
gnarly.  The non-color one is easier to understand.

  PS1='${debian_chroot:+($debian_chroot)address@hidden:\w\$ '

It simply places the value of the variable if it is set in the prompt
inside parenthesis.  If it is not set then it reduces simply to the
basic 'address@hidden:\w\$ '.

> ok, but this problem does not only happen with "cat". It happens with 
> _any_ program which does not print a newline:

I only expect to see the prompt once.  Example:

  $ printf "hello "
  hello $ 

The prompt, once, after the previous output is normal.

> address@hidden:~$ ./test
> address@hidden:~$ thout final address@hidden:~$

I don't know why you are getting two prompts.

There are two separate issues.  One is that you think that the shell
should be able to dynamically determine the cursor location and add a
newline if it is not already in the first column.  I disagree.  The
shell should not do that.  If you want the shell to always add an
extra newline then you can always add one to your PS1 setting.  Some
people do that and like that configuration.

Second is that you think there should only be one prompt printed in
that case.  I agree.  But I cannot recreate your behavior here and I
cannot think of how that would come about.  I am afraid you will have
to try to debug it further on your end.  Unless someone else on the
mailing list pops up with a better idea.  Try reducing your
environment to the minimum by unsetting PROMPT_COMMAND and setting PS1
to '\$ ' and similar.  The values you showed looked okay to me though.

> same weird behaviour I see when using cat with non-newline-ended files.

Right.  That is the way it is supposed to work.

After the command has output whatever the command outputs then the
shell emits the prompt.  If the PROMPT_COMMAND is set then before
emitting the prompt the value of the $PROMPT_COMMNAND is output.  If
the previous command did not terminate with newline then the prompt
will be output not at the left of the line but immediately after the
previous output.

> Interestly, if the main() just returns 0 and does not printf() anything, 
> then the prompt is correctly printed...

Correct.  There was no output at all in that case.  You can simulate
that case with true, false or any other empty command.

  $ true


reply via email to

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