Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nice!

I'd love to see support for the terminal window title here, too. Add an additional container for the titlebar contents, and prefix \[\e]0;$titlebar_contents\a\] to the prompt when TERM is xterm, rxvt, or screen*.

Also, colors should be draggable into the prompt, since they can change between different parts of the prompt.

"Last command error when not successful" is nice as well; just add this to your prompt (includes color and whitespace):

    $(e="$?";[ "$e" -ne 0 ] && echo -n "\[\e[01;31m\]($e) ")
On my system, I also have some extra logic to only show the username and hostname if either $SSH_CONNECTION is set or the username is not my usual username (usually because it's either root, some user I've sudoed to, or an unusual username because I'm on a system with mandated username conventions). Thus, on my personal system, my initial prompt is "~$ ", taking up very little room. Unfortunately "not my usual username" isn't portable to different users (though you could check for the presence of SUDO_USER), but checking SSH_CONNECTION is.


I have this bit of magic in mine to map return codes to some semblance of a string version of them:

    LED=$(perl -le "\$!+=${LE};print \$!" 2>/dev/null || echo "unknown error")
It's not perfect but I haven't found a more reliable way to map exit status' to something like the right meaning.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: