0

So i'm customizing my PS1-Bash-Prompt at the moment and found the iPython way of displaying in- and output pretty neat.

Terminal Screenshot of Prompt and iPython

As you can see, i have my PS1-Prompt configured to look (almost) like the iPython-Input Prompt.

PS1="\n[\t] \e[1m\e[38;5;196m\u@\H\e[0m in \e[1m\e[38;5;196m\w\e[0m\n\e[92mIn [\e[1m\#\e[0m] \$ "

However i can't figure out how to display an Output-Prompt in Bash!

What i'm actually looking for is a way to display a message and increment a counter, whenever a command returns an output to stdout (being able to customize stderr-output would also be nice).

Can someone tell me if and how this can be achieved? Is there a good argument against my idea?

6
  • Forget it. The key difference is: when python prints something, python knows what it's printing. When you execute a command from bash, it's not bash producing the output, it's that external command producing it, and bash has no idea what that command prints. For this to work, you'd need to send the output through some filter, but only for apps that simply produce output, not for text editors and such.
    – egmont
    Commented Oct 26, 2018 at 12:43
  • On an unrelated note: You need to enclose PS1's escape sequences within \[ \] pairs, otherwise line editing falls apart badly.
    – egmont
    Commented Oct 26, 2018 at 12:44
  • Ok thank you! That's quite helpful. Are the user- / host- / time-specification also considered as escape-sequences? I must confess that i had some line-issues since i changed the prompt.
    – Tim Hilt
    Commented Oct 26, 2018 at 12:46
  • No, what you should enclose between those characters are where bash thinks that the cursor will advance, but it actually won't. Silly bash doesn't recognize \e[...m as a sequence that doesn't move the cursor. \u and friends are unrelated to this and should not be enclosed.
    – egmont
    Commented Oct 26, 2018 at 12:49
  • You could have the last process's return code in $PS1...
    – Xen2050
    Commented Oct 26, 2018 at 14:45

0

You must log in to answer this question.

Browse other questions tagged .