News for hackers. Stuff that matters.
Re:Your Bash Prompt Needs This by freshbreath on Friday April 27, 2012 @11:55AM (#3899626)
What if a program prints text without a newline at the end, then exits? It's possible and it would be confusing to not see that last line.

    cout >> "Hello world"; // with no endl.
Prepending the prompt with a new line might be a better idea than over-writing the current line.
Re:Your Bash Prompt Needs This by arjunnarayan on Friday April 27, 2012 @12:04PM (#3899680)
Yes. I have a two line bash prompt: the first line with a whole bunch of info like the exit status of the last command, the number of background jobs, the hostname, current username (very useful when you have 5 different ssh sessions to different machines), and the current working directory. In real world usage I have experienced almost no loss of utility from only having 50% of my command history on screen. In fact, given how many commands are just ls,whoami,jobs,pwd, that info gets condensed into one line.
Re:Your Bash Prompt Needs This by pavel_lishin on Friday April 27, 2012 @01:33PM (#3900165)
Mine's very similar, and includes the current date and time; it also wraps onto the next line and starts with a # (mostly because I'm an idiot, and have burned myself by copying-and-pasting an entire-line-plus-newline and ran a command instead of just copying it in order to edit it.)

    [\[\033[1;32m\]\D{%Y-%m-%d %H:%M:%S}\[\033[0m\]] \[\033[1;32m\]\u\[\033[0m\]\[\033[1;32m\]@\h\[\033[0m\]:\[\033[1;36m\]\w\[\033[0m\]\n#
It's actually dynamically generated by my .bashrc so that different servers have different colors; at a glance, I can generally tell whether I'm on one of my machines, or on a work build server, or an amazon ec2 instance.
Re:Your Bash Prompt Needs This by TimothyFitz on Friday April 27, 2012 @12:25PM (#3899803)
Cool! Do you mind posting your PS1 so other people can try out your config?
Re:Your Bash Prompt Needs This by arjunnarayan on Friday April 27, 2012 @01:54PM (#3900264)
Here's the PS1:

  PS1="\[\e[32;1m\]\[\e[37;1m\]\`if [ \$? = 0 ]; then echo \[\e[33m\] :\)\[\e[0m\]; else echo \[\e[31m\] X\(\[\e[0m\]; fi\`\[\e[32;1m\] \[\e[32;1m\](\[\e[37;1m\]\h:\u\[\e[32;1m\])-(\[\e[37;1m\]\j\[\e[32;1m\])-(\[\e[37;1m\]\w\[\e[32;1m\])\n\[\e[0m\]"
Here's how it appears:

   :) (seas456:narayana)-(0)-(~/personal)
  [this line is where your cursor blinks; notice no symbol at the start of this line]
You can't see the colors here. The smiley face turns into a bright red frowny face if the exit code of the last job is nonzero.
Re:Your Bash Prompt Needs This by jamii on Friday April 27, 2012 @02:36PM (#3900493)
It looks like the your markup got mangled a little. Would you mind posting a gist?
Re:Your Bash Prompt Needs This by india on Friday April 27, 2012 @12:24PM (#3899795)
Could you share your prompt?
Re:Your Bash Prompt Needs This by AngryParsley on Friday April 27, 2012 @12:01PM (#3899668)
Zsh handles this case pretty well. If there's no newline when a process exits, it prints a color-inverted % and a newline.
Re:Your Bash Prompt Needs This by air-lemming on Friday April 27, 2012 @12:42PM (#3899878)
My prompt puts a newline if the cursor is not in the first column, but getting the cursor position complicates things.

https://github.com/dylanahsmith/dotfiles/blob/master/.config...

Re:Your Bash Prompt Needs This by keithwinstein on Friday April 27, 2012 @07:26PM (#3901485)
zsh's approach is clever and doesn't require bidirectional communication. They always print their inverted "%" and then they print as many spaces as you have columns in the terminal (minus one). If the last process ended with a CRLF, they will now be in the last column of the same line; otherwise they will have wrapped around to a new line (assuming the terminal is in auto wrap mode, which is the default). Then they print a carriage return and the prompt as normal.

This does break if the terminal has auto wrap turned off (echo -e "\033[?7l"), but otherwise it's very clever.

Re:Your Bash Prompt Needs This by air-lemming on Sunday April 29, 2012 @03:25AM (#3905394)
That solution sounds even more hacky. Just like I expected resizing my iterm2 window causes glitches because it's text reflowing. I love that feature, but I realize this isn't a problem for all terminals.
Re:Your Bash Prompt Needs This by adavies42 on Friday April 27, 2012 @02:21PM (#3900384)
looks interesting, but it doesn't seem to be compatible with either my setup in general (bash 3.2.25 inside screen inside PuTTY) or my current prompt, which comes out of a shell function and embeds the number of files in pwd, username@hostname:pwd, and previous status, with coloring applied to various parts.

specifically your function just sort of sits there doing nothing when i try it....

Re:Your Bash Prompt Needs This by statico on Friday April 27, 2012 @12:58PM (#3899983)
Agreed. This is the reason I tried this tip many years ago and removed it.