Log in

No account? Create an account
entries friends calendar profile Scribbles in the Dark Previous Previous Next Next
"This bash shell is now fully operational!" - Please Visit http://glyph.twistedmatrix.com/ - This Blog Is Closed. — LiveJournal
Sorry about the ads, I can't turn them off.
"This bash shell is now fully operational!"
14 comments or Leave a comment
jes5199 From: jes5199 Date: December 8th, 2006 11:07 pm (UTC) (Link)
This is extremely cool. Thanks. (Now I have my GNU SCREEN title and my XTERM title set together using readable commands, rather than using screen's terribly conceived auto-titles)
glyf From: glyf Date: December 9th, 2006 02:26 am (UTC) (Link)
Glad you enjoyed it. Spread the word! I have been looking for a way to do this in bash for years, and others looking for a similar hack will likely have a hard time finding it from google... (how did you run across it, anyway?)
jes5199 From: jes5199 Date: December 9th, 2006 02:31 am (UTC) (Link)
I googled for preexec() bash
because I had seen the zsh preexec example in the Screen infodocs, and I didn't see any good reason why that hadn't been ported to bash. I was about to install the patch when I found your post.
rawy From: rawy Date: March 18th, 2007 05:12 pm (UTC) (Link)
Cool news cool ideas! and cool you also
From: williamsmj Date: March 20th, 2007 01:43 am (UTC) (Link)
Can you say a bit more about how you get this to interact with screen correctly. So far, in my ~/.bashrc (right at the end) I have:
. ~/.bash_preexec.sh

set_xterm_title () {
    local title="$1"
    case "$TERM" in
        echo -ne "\e]0;$title\007"
        echo -ne "\033k$title\033\134"

precmd () {
    set_xterm_title "${USER}@${HOSTNAME} `dirs -0` $PROMPTCHAR"

preexec () {
    set_xterm_title "$1 {`dirs -0`} (${USER}@${HOSTNAME})"

In my ~/.screenrc I have:

caption always "%{= kw}%-w%{= BW}%n %t%{-}%+w %-= %1` %y.%m.%d %C:%s%a"

lifted from Mark Pilgirm (which is where I found this page, by the way).

Unsurprisingly, this works in an xterm. In screen, the screen title is set correctly, to "top {~} (user@host)" or whatever, but my bash prompt is screwed up. It reads "bembo:~$ ~$", but the cursor is positioned under the second ~, and overwrites is and the final $ as you type. Presumably the problem is with 'echo -ne "\033k$title\033\134"' in my .bashrc, but I can't see it. I'd be very grateful for a quick fix, or a better method!
From: williamsmj Date: March 20th, 2007 01:52 am (UTC) (Link)
bembo is my host, by the way, not the random product of subtly interacting escape codes.
From: williamsmj Date: March 20th, 2007 05:24 pm (UTC) (Link)
For Google's benefit, the fix is to change

echo -ne "\033k$title\033\134"


echo -ne "\033k$title\033\\"
14 comments or Leave a comment