Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Escape Sequences to set Terminal Title Broken in OpenSUSE 13.1?

  1. #1

    Default Escape Sequences to set Terminal Title Broken in OpenSUSE 13.1?

    Using bash in OpenSuSE 13.1, I set the following environment variable in .bashrc and rerun bash:

    export PROMPT_COMMAND='echo -ne "\033]0;${USER}@@${HOSTNAME}: ${PWD}\007"'

    but the xterm title doesn't reflect my custom text. (I've used two @'s to ensure I'm seeing my change). This also happens with konsole if go to Settings > Edit Current Profile > Tabs and set "Table title format" to %w (window title set by shell). According to many searches, the above sequence should work just fine.

    If I unset that environment variable and directly echo the same string, no change - it still doesn't work. Thus it doesn't seem to be related to bash configuration (dot files).

    Anyone have any ideas what's wrong? Is this crucial feature broken in KDE 4.11.5?

  2. #2

    Default Re: Escape Sequences to set Terminal Title Broken in OpenSUSE 13.1?

    Quote Originally Posted by CountBakula View Post
    Using bash in OpenSuSE 13.1, I set the following environment variable in .bashrc and rerun bash:

    export PROMPT_COMMAND='echo -ne "\033]0;${USER}@@${HOSTNAME}: ${PWD}\007"'

    but the xterm title doesn't reflect my custom text. (I've used two @'s to ensure I'm seeing my change). This also happens with konsole if go to Settings > Edit Current Profile > Tabs and set "Table title format" to %w (window title set by shell). According to many searches, the above sequence should work just fine.

    If I unset that environment variable and directly echo the same string, no change - it still doesn't work. Thus it doesn't seem to be related to bash configuration (dot files).

    Anyone have any ideas what's wrong? Is this crucial feature broken in KDE 4.11.5?
    Hi,

    Im not sure what are you trying to do with that prompt command. There are characters/strings in there that is special to the shell so it will not work, you need to escape it. Still i don't understand what you want to achieve with this. Maybe you want PS1 instead?
    "Unfortunately time is always against us" -- [Morpheus]

    .:https://github.com/Jetchisel:.

  3. #3

    Default Re: Escape Sequences to set Terminal Title Broken in OpenSUSE 13.1?

    Quote Originally Posted by CountBakula View Post
    Using bash in OpenSuSE 13.1, I set the following environment variable in .bashrc and rerun bash:

    export PROMPT_COMMAND='echo -ne "\033]0;${USER}@@${HOSTNAME}: ${PWD}\007"'

    but the xterm title doesn't reflect my custom text.
    First, this sets the prompt (actually it causes the shell to run a command before printing the prompt), not the window title.

    Second, escape sequences work fine, but yours are wrong and make no sense.
    Try this e.g. to see that it works in principle:
    Code:
    export PROMPT_COMMAND='echo -ne "\033[3;12r\033[3H${USER}@@${HOSTNAME}: ${PWD}> "'
    Btw, you don't need to rerun bash after setting the variable...

    And you can set the prompt by setting the variable PS1, no need to run echo...
    Code:
    PS1="\033[3;12r\033[3H${USER}@@${HOSTNAME}: ${PWD}> "
    See e.g. here for more escape sequences: http://misc.flogisoft.com/bash/tip_c...and_formatting
    Last edited by wolfi323; 26-Feb-2015 at 14:12.

  4. #4

    Default Re: Escape Sequences to set Terminal Title Broken in OpenSUSE 13.1?

    Nope, PS1 is specifically for generating the command prompt. I don't care about the command prompt here; the reason I'm setting PROMPT_COMMAND is to get the side effect of echoing the special characters needed to set the terminal title.

    According to these pages, what I'm doing should work:
    http://tldp.org/HOWTO/Xterm-Title-4.html
    http://superuser.com/questions/79972...rent-directory

  5. #5

    Default Re: Escape Sequences to set Terminal Title Broken in OpenSUSE 13.1?

    Quote Originally Posted by wolfi323 View Post
    First, this sets the prompt (actually it causes the shell to run a command before printing the prompt), not the window title.
    Not according to the web pages I read (linked above). PROMPT_COMMAND is just something run before the prompt is generated, and doesn't itself set the prompt. By echoing special character sequences, I can change the xterm title, or should be able to, according to those pages.

    Quote Originally Posted by wolfi323 View Post
    Second, escape sequences work fine, but yours are wrong and make no sense.
    Wrong. See the two links I posted in the response to the other user. They should work. They are specific sequences to change the title.

    Quote Originally Posted by wolfi323 View Post
    Try this e.g. to see that it works in principle:
    Code:
    export PROMPT_COMMAND='echo -ne "\033[3;12r\033[3H${USER}@@${HOSTNAME}: ${PWD}> "'
    Btw, you don't need to rerun bash after setting the variable...
    When I echo that, it moves my cursor to a higher position in the terminal window, but doesn't affect the title.

    Quote Originally Posted by wolfi323 View Post
    And you can set the prompt by setting the variable PS1, no need to run echo...
    Code:
    PS1="\033[3;12r\033[3H${USER}@@${HOSTNAME}: ${PWD}> "
    If I execute this in my bash shell, each command starts being written on top of the previous one (it no longer scrolls) and thus becomes corrupted and unusable. I had to kill off the xterm after doing this and start another one.

  6. #6

    Default Re: Escape Sequences to set Terminal Title Broken in OpenSUSE 13.1?

    Quote Originally Posted by CountBakula View Post
    Nope, PS1 is specifically for generating the command prompt. I don't care about the command prompt here; the reason I'm setting PROMPT_COMMAND is to get the side effect of echoing the special characters needed to set the terminal title.
    I thought you wanted to change the prompt, and that you should better do by setting PS1, not running echo via COMMAND_PROMPT.

    Ah, ok.
    And it does work, at least if you rename /etc/bash.bashrc, something in there seems to override the window title.
    Last edited by wolfi323; 26-Feb-2015 at 14:45.

  7. #7

    Default Re: Escape Sequences to set Terminal Title Broken in OpenSUSE 13.1?

    Quote Originally Posted by CountBakula View Post
    Not according to the web pages I read (linked above). PROMPT_COMMAND is just something run before the prompt is generated, and doesn't itself set the prompt.
    Exactly. That's what I wrote.

    When I echo that, it moves my cursor to a higher position in the terminal window, but doesn't affect the title.
    I never said that this should change the title. It was an example that escape sequences work in general.

    If I execute this in my bash shell, each command starts being written on top of the previous one (it no longer scrolls) and thus becomes corrupted and unusable. I had to kill off the xterm after doing this and start another one.
    You could have just set PS1 to something else. No need to kill xterm...
    Last edited by wolfi323; 26-Feb-2015 at 14:41.

  8. #8

    Default Re: Escape Sequences to set Terminal Title Broken in OpenSUSE 13.1?

    PS: Type this into your xterm (or add it to .bashrc or similar) and you should be able to change the window title afterwards:
    Code:
    ppwd () { exit; }
    This overrides the function that sets the window title.

    Or you could set the window title directly with something like this (instead of setting PROMPT_COMMAND):
    Code:
    ppwd () { echo -ne "\033]0;${USER}@@${HOSTNAME}: ${PWD}\007"; }
    Apparently ppwd() gets called before the prompt is printed, but after PROMPT_COMMAND. The default function (defined in /etc/bash.bashrc) sets the window title to the standard one ("user@host: dir"), which overrides the title you set via PROMPT_COMMAND.
    Last edited by wolfi323; 26-Feb-2015 at 15:10.

  9. #9
    Join Date
    Aug 2010
    Location
    Chicago suburbs
    Posts
    12,356
    Blog Entries
    3

    Default Re: Escape Sequences to set Terminal Title Broken in OpenSUSE 13.1?

    Quote Originally Posted by CountBakula View Post
    Anyone have any ideas what's wrong? Is this crucial feature broken in KDE 4.11.5?
    Personally, I consider that a misfeature. Fortunately, I use "csh" rather than "bash", so I don't have to put up with it.

    In any case, I opened an xterm with the title that I wanted (using "-title"). Then I ran "bash" in that xterm. And, sure enough, that misfeature did its annoying thing and changed the title.

    This is with opensuse 13.2. I haven't checked 13.1, though I'm pretty sure it does the same.

    What this shows is that bash is still able to emit an escape sequence that tells "xterm" to change its title. So I don't think a feature (or misfeature) is broken.

    To be a bit pedantic, neither "xterm" nor "bash" is part of KDE. So it would not be a KDE feature.
    openSUSE Leap 15.1; KDE Plasma 5;

  10. #10

    Default Re: Escape Sequences to set Terminal Title Broken in OpenSUSE 13.1?

    Quote Originally Posted by nrickert View Post
    Personally, I consider that a misfeature. Fortunately, I use "csh" rather than "bash", so I don't have to put up with it.

    In any case, I opened an xterm with the title that I wanted (using "-title"). Then I ran "bash" in that xterm. And, sure enough, that misfeature did its annoying thing and changed the title.

    This is with opensuse 13.2. I haven't checked 13.1, though I'm pretty sure it does the same.
    If you undefine ppwd() in ~/.bashrc or /etc/bash.bashrc.local, the -title parameter works fine as well.

    Actually this is no misfeature of bash, but just the standard openSUSE setup (as mentioned, ppwd() is defined in /etc/bash.bashrc to change the window title every time the shell prints a prompt).

    Oh, and actually ppwd() is called by the prompt. See "echo $PS1"...
    So setting PS1 to something else will prevent the window title from being changed as well, and will make your escape sequences for changing the title work.
    Last edited by wolfi323; 26-Feb-2015 at 15:33.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •