Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a debug trap that runs every time I enter a command in bash that sets the window title to indicate what command is running. I'm leaving out all the configuration details and boil it down to:

export PS1="\[\e]0;$GENERATED_WINDOW_TITLE\a\]$GENERATED_PROMPT"

This works incredibly well, with only one snag: if the bash shell is running in an environment that does not support this feature, the GENERATED_WINDOW_TITLE is printed on the screen with each prompt. This happens any time I'm running bash from a non-X terminal.

How can bash tell if this escape sequence is supported?

share|improve this question
    
I'm looking at "tput has_status_line" as a possible starting point, but all my terminals claim that this is not a known terminfo capability - despite documenting it as a boolean in terminfo. –  Sniggerfardimungus Feb 26 '13 at 23:37
    
I've updated the blog post on this topic, in case you're interested in the fun color prompt and status line stuff I was doing with this: foodini.org/permalink.cgi?link=20080816 –  Sniggerfardimungus Feb 27 '13 at 20:28
add comment

1 Answer

up vote 3 down vote accepted

I don't think there's a terminfo capability for that. In practice, testing the value of TERM should be good enough. That's what I do in my .bashrc and .zshrc, and I don't recall it being a problem.

case $TERM in
  (|color(|?))(([Ekx]|dt|(ai|n)x)term|rxvt|screen*)*)
    PS1=$'\e\]0;$GENERATED_WINDOW_TITLE\a'"$PS1"
esac
share|improve this answer
    
Heh heh. I just plugged in an "if [ $TERM == "xterm" ];" but holy cow! How did you pull that list of possibilities together? –  Sniggerfardimungus Feb 26 '13 at 23:44
    
@Sniggerfardimungus Right now, grep -C5 title ~/.zshrc. When I wrote it (last updated 2007)… I didn't leave a comment, so by observation I guess. –  Gilles Feb 26 '13 at 23:50
    
Thanks for the hack. I've had trouble getting it to parse, though, and went with a simpler version that I'll build up over time as I find a need for more terminals. –  Sniggerfardimungus Feb 27 '13 at 20:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.