1

here is my ps1

does someone know documents about this?

export PS1='\[\e]0;YYY@\h:\w\a\]\[\e]2;XXX\W\a\e[32;40m\]\[\e[36;40m\]$?\[\e[31;40m\]\D{%d}\[\e[35;40m\]\D{%H%M}\[\e[36;40m\]\W\[\e[32;40m\]>\[\e[0m\]'

enter image description here

2
  • 1
    I suggest to consult the Bash Prompt HOWTO, that should cover all the bells and whistles.
    – markgraf
    Commented Jun 22 at 12:46
  • @markgraf, but does it cover the difference between \e]0; and \e]2;? Where? If it does, you might consider posting an answer describing the difference along with references to the documentation.
    – ilkkachu
    Commented Jun 24 at 20:56

1 Answer 1

5

For reference, the \e] prefix is often called "OSC" in documentation (while \e[ is "CSI").

  • \e]0; (OSC 0) begins a sequence that sets both the terminal's window title and icon title – the latter for desktop environments that allow a separate title for minimized or iconified windows, such as MS Windows 3.11.

  • \e]2; (OSC 2) sets only the window title (and \e]1; OSC 1 would set just the icon title).

  • Not to be confused with \e[0m (CSI 0 m, aka SGR 0) which resets all text formatting.

Both OSCs can end with either \e\\ (ST) or \a (BEL), the latter is nonstandard but also common. So \e]0;YYY@\h:\w\a is the whole sequence.

To see the difference between the two on your system, you can try e.g. commands like this:

printf '\e]0;Both titles\a'; sleep 5
printf '\e]1;Icon title\a'; sleep 5
printf '\e]2;Window title\a'; sleep 5

(The sleep commands are there so you can see the changes one by one if you copypaste the whole deal in one go.)

The outermost \[ ... \] in the prompt are specific to Bash; they're not part of the sequence itself, but tell the shell's Readline library that the sequences are zero-width and don't move the cursor when printed, so that it would correctly know how wide the prompt is and how line-wrapping should behave when editing long multi-line commands.

2
  • What is the point of this && sleep 1h here? Commented Jun 21 at 12:23
  • @KamilMaciorowski: So that the results of the example command remain visible for a while before OP returns to their shell prompt (which otherwise would immediately override the title with its regular "user@host:cwd"). Commented Jun 21 at 12:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .