Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'PROMPT_COMMAND is slow. Here's another way.' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
PROMPT_COMMAND is slow. Here's another way.
Authored by: dsandler on Oct 20, '03 04:00:03PM
Using PROMPT_COMMAND this way can be slow, because every time bash displays a prompt it must now launch echo in a sub-process. Fortunately, since in this case PROMPT_COMMAND is just being used to echo bytes to the terminal, you can avoid it entirely by prepending those bytes onto your PS1. bash won't interpolate ${variable}s when it shows PS1, so you can't do everything you can in a PROMPT_COMMAND, but it has backslash-escapes for everything we need here.

Here's an example, replicating the effect of the original tip:

export PS1="\[\033]0;\u@\h: \w\007\][\u@\h \W]\$ "
The \[...\] sequence tells bash that the characters between the brackets will not change the position of the cursor in the terminal; without them, text wrapping at the prompt will get very confused.

[ Reply to This | # ]
Corrected code for above comment
Authored by: dsandler on Oct 20, '03 04:05:20PM

[Whoa, that was weird -- it looked fine in the preview. I'll try "Plain Old Text" this time.]

Example:

export PS1="\[\033]0;\u@\h: \w\007\][\u@\h \W]\$ "



[ Reply to This | # ]