Setting window title in ssh'ed host

View: New views
15 Messages — Rating Filter:   Alert me  

Setting window title in ssh'ed host

by Bugzilla from gokdenizk@gmail.com :: Rate this Message:

| View Threaded | Show Only this Message

Hi,

This is more like a story, I am trying to  automatically set
"GNU screen window title" equal to the hostname that is connected by ssh.

I am using the following for hardstatus, which presents a list of all open windows
hardstatus lastline "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<"

Also my .screenrc connects to some machines,
screen -t hostname
stuff "ssh hostname\015
....

Sometimes I logout of the connected machine and connect to another.  I don't
want to set title each time I do this.  If there is no screen in the way, the
following bash variable shows the hostname in xterm title.
PROMPT_COMMAND='echo -ne "\033]0;${HOSTNAME}\007"'

If I use this, and change %t->%h in hardstatus string, the hostname shows in
the "currently selected window only", but not the others. As there is no
equivalent of "-w" "+w" for xterm title(which is an actual "hard" status), this
path was blocked.

Setting the following in all machines achieves what I want,
it sets screen title to hostname,
PROMPT_COMMAND='echo -n -e "\033k${HOSTNAME}\033\\"'
but when I connect to the machine out of screen, It prints the hostname
literally, so the prompt becomes like "hostname user@hostname $ " , which is
ugly and redundant.

To ensure that only ssh sessions within a GNU screen get the "title setter
prompt command", environment variables are useful, I can use the TERM variable,
but in stable debian, the default TERM=screen breaks vim editor, it goes crazy
when you press home, or pageup buttons.  Using TERM=xterm fixes this, so I
cannot check for TERM being equal to "screen".

I put "setenv INSCREEN yes" into .screenrc, and in the target shell, I set
PROMPT_COMMAND if this variable is set, but then,(surprise, surprise!) ssh
would not pass variables to target machine.  At least, does not pass unless you
use AcceptEnv in ssh server config, but I don't want to use it for security
reasons. Ok, maybe not because of security, but changing "ssh server
configuration" for only setting screen's window title seems absurd.


A solution that I imagined was to extend the "stuff" line; it does the ssh
connection, then puts the PROMPT_COMMAND to set GNU screen window title.
escaping this correctly was a chore, but I managed after some experimentation.
stuff "ssh hostname\015export PROMPT_COMMAND='echo -n -e "\\033k\${HOSTNAME}\\033\\\\\"'\015"

But of course, the connections made after these do not set the title. If only
there was a way to set GNU screen window title to the "hard status" set by the
escape sequences in PROMPT_COMMAND of bash ...


[[ rant: Why, why, why this great software gets the most generic name of "screen" ?
What's next, "computer", which is a shell that works by reading your mind,
and "earth" which gives the answer to life, the universe, and everything; and does
not only say '42' ? So that you search the web for them and find nothing :-/

Please use "GNU screen" all the time, to be search engine friendly,
like I did in this message :-S

/rant ]]

--
Gokdeniz Karadag


_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Re: Setting window title in ssh'ed host

by Trent W. Buck :: Rate this Message:

| View Threaded | Show Only this Message

On Sat, Jul 12, 2008 at 03:10:00AM +0300, Gokdeniz Karadag wrote:
> This is more like a story, I am trying to automatically set "GNU
> screen window title" equal to the hostname that is connected by ssh.

In my .profile, which exists on all my machines and is evaluated for
all interactive logins (i.e. "ssh fooserv", but not "ssh fooserv
pwd"), I have

    type uname >/dev/null 2>&1 &&
    test -n "${HOSTNAME:=`uname -n`}" &&
    case "$TERM" in
        screen*) printf %bk%s%b%b \\033 "${HOSTNAME%%.*}" \\033 \\0134;;
    esac

Note that the "type" builtin isn't portable, if you use .bash_profile
you can instead just use

    case "$TERM" in
        screen*) printf %bk%s%b%b \\033 "${HOSTNAME%%.*}" \\033 \\0134;;
    esac

I use this in preference to doing it inside screen because I couldn't
work out how to have an "alias" or "function" in screen such that

    C-a x fooserv RET

would expand to something like

    C-a :screen -t fooserv ssh fooserv

If anyone knows how to do that, I'd prefer it (since customer machines
don't have my .profile installed).

> Sometimes I logout of the connected machine and connect to another.
> I don't want to set title each time I do this.  If there is no
> screen in the way, the following bash variable shows the hostname in
> xterm title.  PROMPT_COMMAND='echo -ne "\033]0;${HOSTNAME}\007"'

Oh, have a screen window with a shell, and you run "ssh fooserv" in
the shell.  I *think* my approach still works in that case.

> If I use this, and change %t->%h in hardstatus string, the hostname
> shows in the "currently selected window only", but not the
> others. As there is no equivalent of "-w" "+w" for xterm title(which
> is an actual "hard" status), this path was blocked.

I didn't understand any of that paragraph.

> To ensure that only ssh sessions within a GNU screen get the "title
> setter prompt command", environment variables are useful, I can use
> the TERM variable, but in stable debian, the default TERM=screen
> breaks vim editor, it goes crazy when you press home, or pageup
> buttons.  Using TERM=xterm fixes this, so I cannot check for TERM
> being equal to "screen".

Then you should fix vim, not train Screen to work with the wrong
settings.  Does vim work correctly (with TERM screen) if you tell it
not to evaluate your .vimrc and such?  If so, then the problem is with
your .vimrc, not with vim itself.

> I put "setenv INSCREEN yes" into .screenrc, and in the target shell,
> I set PROMPT_COMMAND if this variable is set, but then,(surprise,
> surprise!) ssh would not pass variables to target machine.  At
> least, does not pass unless you use AcceptEnv in ssh server config,
> but I don't want to use it for security reasons.

You need to configure ssh to do so with the SendEnv directive in
~/.ssh/config.  See ssh_config(5) manpage.  Dunno about AcceptEnv, I
guess you've tried it more than I have.

> Ok, maybe not because of security, but changing "ssh server
> configuration" for only setting screen's window title seems absurd.

I agree.

> A solution that I imagined was to extend the "stuff" line; it does the ssh
> connection, then puts the PROMPT_COMMAND to set GNU screen window title.
> escaping this correctly was a chore, but I managed after some experimentation.
> stuff "ssh hostname\015export PROMPT_COMMAND='echo -n -e "\\033k\${HOSTNAME}\\033\\\\\"'\015"

Instead of using :stuff, why not just set the title when you create
the screen window, running ssh instead of the default shell?

C-a :screen -t fooserv ssh fooserv

> But of course, the connections made after these do not set the title.

In the approach I propose, each subsequent ssh would get a fresh
window, so this would work.

> [[ rant: Why, why, why this great software gets the most generic
> name of "screen" ?

I agree.


_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Re: Setting window title in ssh'ed host

by Christian Ebert :: Rate this Message:

| View Threaded | Show Only this Message

* Gokdeniz Karadag on Saturday, July 12, 2008 at 03:10:00 +0300

> Setting the following in all machines achieves what I want, it sets
> screen title to hostname,
> PROMPT_COMMAND='echo -n -e "\033k${HOSTNAME}\033\\"'
> but when I connect to the machine out of screen, It prints the hostname
> literally, so the prompt becomes like "hostname user@hostname $ " , which is
> ugly and redundant.
>
> To ensure that only ssh sessions within a GNU screen get the "title setter
> prompt command", environment variables are useful, I can use the TERM variable,
> but in stable debian, the default TERM=screen breaks vim editor, it goes crazy
> when you press home, or pageup buttons.  Using TERM=xterm fixes this, so I
> cannot check for TERM being equal to "screen".

Does checking for $STY work for your purposes?

if [ -n "$STY" ]
   <screen specific stuff>
fi

c
--
  Was heißt hier Dogma, ich bin Underdogma!
[ What the hell do you mean dogma, I am underdogma. ]

_F R E E_  _V I D E O S_  -->>  http://www.blacktrash.org/underdogma/


_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Re: Setting window title in ssh'ed host

by Gokdeniz Karadag :: Rate this Message:

| View Threaded | Show Only this Message

Hi,

First of all thanks for your answer. I have solved the question -- or the
question suddenly disappeared :)

My replies are between quotations below.

Trent W. Buck demis ki::
.......
> Note that the "type" builtin isn't portable, if you use .bash_profile
> you can instead just use
>
>     case "$TERM" in
>         screen*) printf %bk%s%b%b \\033 "${HOSTNAME%%.*}" \\033 \\0134;;
>     esac
....
>> Sometimes I logout of the connected machine and connect to another.
>> I don't want to set title each time I do this.  If there is no
>> screen in the way, the following bash variable shows the hostname in
>> xterm title.  PROMPT_COMMAND='echo -ne "\033]0;${HOSTNAME}\007"'
>
> Oh, have a screen window with a shell, and you run "ssh fooserv" in
> the shell.  I *think* my approach still works in that case.
>

Yes, your approach is the proper solution to my problem, but another problem
with "vim" made me use xterm as screen's $TERM during my previous attempts.

>> If I use this, and change %t->%h in hardstatus string, the hostname
>> shows in the "currently selected window only", but not the
>> others. As there is no equivalent of "-w" "+w" for xterm title(which
>> is an actual "hard" status), this path was blocked.
>
> I didn't understand any of that paragraph.

This is not much important but, my screen's hardstatus was like this;
hardstatus lastline "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<"
Example:  0$* machineA  1-$ machineB  2$ machineC

I was able to set the "xterm title" using "xterm hardstatus" escapes "in the
connected machine", while using TERM=xterm.
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}\007"'

I could display this "xterm hardstatus text"  in "screen hardstatus", by using
"%h" in screen's hardstatus line. But, as you can see in my example ALL
connected machine names can be seen, thanks to %-w and %+w in screen's
hardstatus string. When "xterm hardstatus" is displayed using %h, there is no
%-h and %+h to display all machines "xterm hardstatus" info on the last line.

If I couldn't made myself clear, feel free to ignore this as the problem is
solved now.


>
>> To ensure that only ssh sessions within a GNU screen get the "title
>> setter prompt command", environment variables are useful, I can use
>> the TERM variable, but in stable debian, the default TERM=screen
>> breaks vim editor, it goes crazy when you press home, or pageup
>> buttons.  Using TERM=xterm fixes this, so I cannot check for TERM
>> being equal to "screen".
>
> Then you should fix vim, not train Screen to work with the wrong
> settings.  Does vim work correctly (with TERM screen) if you tell it
> not to evaluate your .vimrc and such?  If so, then the problem is with
> your .vimrc, not with vim itself.
>

My previus tests showed that setting TERM from "screen" to "xterm" solved
problems with vim. Today, I intended to fix this issue once and for all,
strangely, vim worked without problems using TERM=screen. As a result I can
check TERM in servers and use screen specific escapes to set title.

>
>> A solution that I imagined was to extend the "stuff" line; it does the ssh
>> connection, then puts the PROMPT_COMMAND to set GNU screen window title.
>> escaping this correctly was a chore, but I managed after some experimentation.
>> stuff "ssh hostname\015export PROMPT_COMMAND='echo -n -e "\\033k\${HOSTNAME}\\033\\\\\"'\015"
>
> Instead of using :stuff, why not just set the title when you create
> the screen window, running ssh instead of the default shell?
>
> C-a :screen -t fooserv ssh fooserv
>

With stuff in screenrc, I can logout from the initially connected machine and
that screen window does not close itself, just a convenience. Also, stuff can
be extended to "cd" into relevant directory, run a non-login shell, etc.

Thanks again for the answer.

--
Gokdeniz Karadag


_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Re: Setting window title in ssh'ed host

by Gokdeniz Karadag :: Rate this Message:

| View Threaded | Show Only this Message

Christian Ebert demis ki::

> * Gokdeniz Karadag on Saturday, July 12, 2008 at 03:10:00 +0300
>> Setting the following in all machines achieves what I want, it sets
>> screen title to hostname,
>> PROMPT_COMMAND='echo -n -e "\033k${HOSTNAME}\033\\"'
>> but when I connect to the machine out of screen, It prints the hostname
>> literally, so the prompt becomes like "hostname user@hostname $ " , which is
>> ugly and redundant.
>>
>> To ensure that only ssh sessions within a GNU screen get the "title setter
>> prompt command", environment variables are useful, I can use the TERM variable,
>> but in stable debian, the default TERM=screen breaks vim editor, it goes crazy
>> when you press home, or pageup buttons.  Using TERM=xterm fixes this, so I
>> cannot check for TERM being equal to "screen".
>
> Does checking for $STY work for your purposes?
>
> if [ -n "$STY" ]
>    <screen specific stuff>
> fi
>
> c

Hi,

That works on the machine where screen is run, but my main use for screen is to
connect to many machines using ssh.

An environment var. does not get passed to the target shell, if *both* SendEnv
in the client and AcceptEnv in the server is configured.

When TERM is properly set to "screen", I can use it on the target server
without extra configuration as I wrote in my answer to Trent Buck.

Thank you for the answer.

--
Gokdeniz Karadag



_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Re: Setting window title in ssh'ed host

by Micah Cowan :: Rate this Message:

| View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gokdeniz Karadag wrote:
> Hi,
>
> This is more like a story, I am trying to  automatically set "GNU screen
> window title" equal to the hostname that is connected by ssh.

This has been a recurring need, solved in various ways.

Thomas Adam just pointed out to me the following link:
http://www.tenshu.net/screen_ssh/

which appears to solve a problem by using ssh's LocalCommand config
option (which I hadn't known about) to run a local command whenever it's
invoked.

- --
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer.
GNU Maintainer: wget, screen, teseq
http://micah.cowan.name/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJEiCR7M8hyUobTrERAofhAKCAUqhS/qrXkafnft2mjqTrkN2rUACgibCx
q05lPRNP4B0ChqcT9ULT7qw=
=In13
-----END PGP SIGNATURE-----


_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Re: Setting window title in ssh'ed host

by Robin Lee Powell :: Rate this Message:

| View Threaded | Show Only this Message

On Wed, Nov 05, 2008 at 02:39:13PM -0800, Micah Cowan wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Gokdeniz Karadag wrote:
> > Hi,
> >
> > This is more like a story, I am trying to  automatically set
> > "GNU screen window title" equal to the hostname that is
> > connected by ssh.
>
> This has been a recurring need, solved in various ways.

I've solved it by prompt hacking; here's the relevant bits from my
.screenrc at work:

# Magic to make PS1 goodness work
hardstatus off
hardstatus string "%t"
chacl :window: -rwx #?
chacl :window: +x title

#####
# With this setup, you can change the current window's title by
# sending an ANSI escape sequence; this will change the window's
# title and the title will show up in the hardstatus line (i.e. the
# title bar in PuTTY).  This sets the title to the current host
# name.  The actual prompt is the hostname followed by $ for bash or
# %# for zsh, which is magic that shows either # if you're root or %
# if you're not.
#
# zsh: PS1="$(echo -e '%{\033]83;title '$(uname -n)'\007%}%m%# ')"
#
# bash: PS1="\[\033]83;title $(uname -n)\a\]$(uname -n)\$ "
#
#####

-Robin

--
They say:  "The first AIs will be built by the military as weapons."
And I'm thinking:  "Does it even occur to you to try for something
other than the default outcome?" -- http://shorl.com/tydruhedufogre
http://www.digitalkingdom.org/~rlpowell/ *** http://www.lojban.org/


_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Re: Setting window title in ssh'ed host

by Micah Cowan :: Rate this Message:

| View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Robin Lee Powell wrote:

> On Wed, Nov 05, 2008 at 02:39:13PM -0800, Micah Cowan wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Gokdeniz Karadag wrote:
>>> Hi,
>>>
>>> This is more like a story, I am trying to  automatically set
>>> "GNU screen window title" equal to the hostname that is
>>> connected by ssh.
>> This has been a recurring need, solved in various ways.
>
> I've solved it by prompt hacking; here's the relevant bits from my
> .screenrc at work:
>
> # Magic to make PS1 goodness work
> hardstatus off
> hardstatus string "%t"
> chacl :window: -rwx #?
> chacl :window: +x title
>
> #####
> # With this setup, you can change the current window's title by
> # sending an ANSI escape sequence; this will change the window's
> # title and the title will show up in the hardstatus line (i.e. the
> # title bar in PuTTY).  This sets the title to the current host
> # name.  The actual prompt is the hostname followed by $ for bash or
> # %# for zsh, which is magic that shows either # if you're root or %
> # if you're not.
> #
> # zsh: PS1="$(echo -e '%{\033]83;title '$(uname -n)'\007%}%m%# ')"
> #
> # bash: PS1="\[\033]83;title $(uname -n)\a\]$(uname -n)\$ "
> #
> #####

I don't really see how that does what the thread's talking about;
namely, set the window title to the hostname that's connected by ssh.

Kinda cool about the :window:/OSC 83 command execution hack, though. I
was incredulous that those chacls actually did anything related to the
window title.

As previously mentioned in these threads (IIRC?), the problem with
prompt hacks is you don't always have control over the prompts in remote
shells (and even when you do, it's a bit of a pain to set up in every
host you ever visit).

- --
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer.
GNU Maintainer: wget, screen, teseq
http://micah.cowan.name/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkkSk7cACgkQ7M8hyUobTrHNwQCfT6xqxwNzPEwf7DeXfZu8paT+
LSIAn0Ft/obLm4TDFhBi2mzhHwg+SF5e
=omIc
-----END PGP SIGNATURE-----


_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Re: Setting window title in ssh'ed host

by Robin Lee Powell :: Rate this Message:

| View Threaded | Show Only this Message

On Wed, Nov 05, 2008 at 10:50:31PM -0800, Micah Cowan wrote:
> I don't really see how that does what the thread's talking about;
> namely, set the window title to the hostname that's connected by
> ssh.

You set your remote shell's PS1 to tell screen to set the title to
$(uname -n) or whatever.

> As previously mentioned in these threads (IIRC?), the problem with
> prompt hacks is you don't always have control over the prompts in
> remote shells (and even when you do, it's a bit of a pain to set
> up in every host you ever visit).

True enough.  The LocalCommand hack is kinda neat.

-Robin

--
They say:  "The first AIs will be built by the military as weapons."
And I'm thinking:  "Does it even occur to you to try for something
other than the default outcome?" -- http://shorl.com/tydruhedufogre
http://www.digitalkingdom.org/~rlpowell/ *** http://www.lojban.org/


_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Re: Setting window title in ssh'ed host

by einheitlix :: Rate this Message:

| View Threaded | Show Only this Message

Hi,

I solved the problem in bash by editing my ~/.profile file:

ssh() {
 args=$@
 echo -ne "\033k${args##* }\033\\";
 /usr/bin/ssh "$@";
}

It"s a rather simple script, whenever you call ssh, first this script is
executed, which calls the real ssh in the end, with the same arguments.
Before it does that, however, it sets the screen title to the last
argument of the ssh command. Usually, this is the hostname, at least for
the way I enter commands ;-)

Malte

Robin Lee Powell schrieb:

> On Wed, Nov 05, 2008 at 10:50:31PM -0800, Micah Cowan wrote:
>  
>> I don't really see how that does what the thread's talking about;
>> namely, set the window title to the hostname that's connected by
>> ssh.
>>    
>
> You set your remote shell's PS1 to tell screen to set the title to
> $(uname -n) or whatever.
>
>  
>> As previously mentioned in these threads (IIRC?), the problem with
>> prompt hacks is you don't always have control over the prompts in
>> remote shells (and even when you do, it's a bit of a pain to set
>> up in every host you ever visit).
>>    
>
> True enough.  The LocalCommand hack is kinda neat.
>
> -Robin
>
>  



_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Re: Setting window title in ssh'ed host

by Trent W. Buck :: Rate this Message:

| View Threaded | Show Only this Message

Malte Skoruppa <malte@...> writes:

> I solved the problem in bash by editing my ~/.profile file:
>
> ssh() {
> args=$@
> echo -ne "\033k${args##* }\033\\";
> /usr/bin/ssh "$@";

You don't need to hard-code the path to ssh if you change this line to

    command ssh "$@"

the trailing semicolons are also unnecessary because newline acts as a
command delimiter.  Have a nice day.



_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Parent Message unknown Re: Setting window title in ssh'ed host

by Bugzilla from gokdenizk@gmail.com :: Rate this Message:

| View Threaded | Show Only this Message

Hi, in your script, it would be better to revert it back to local hostname
after ssh finishes.

Both this and LocalCommand seems neat, too bad that I have solved it by
manually setting PS1 on all machines :)

------------------------------

Message: 5
Date: Thu, 06 Nov 2008 11:25:00 +0100
From: Malte Skoruppa <malte@...>
Subject: Re: Setting window title in ssh'ed host
To: screen-users@...
Message-ID: <4912C5FC.6020903@...>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi,

I solved the problem in bash by editing my ~/.profile file:

ssh() {
  args=$@
  echo -ne "\033k${args##* }\033\\";
  /usr/bin/ssh "$@";
}

It"s a rather simple script, whenever you call ssh, first this script is
executed, which calls the real ssh in the end, with the same arguments.
Before it does that, however, it sets the screen title to the last
argument of the ssh command. Usually, this is the hostname, at least for
the way I enter commands ;-)

Malte


_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Re: Setting window title in ssh'ed host

by einheitlix :: Rate this Message:

| View Threaded | Show Only this Message

Hi,

thanks for the tip with the 'command ssh' instead of /ust/bin/ssh
trick... didn't know about that.

I quickly hacked this script into my ~/.profile a while ago, so it may
not be that beautiful from a cosmetic point of view. Indeed I can leave
out the semicolons, they're just still there because this was a
one-liner to begin with ;)

I do 'revert' my screen title after the ssh command terminates. I just
don't revert it to the local hostname, but always set the title to the
current directory (at least, to the last 20 characters of $PWD) :-)

This is also in my ~/.profile
The PROMPT_COMMAND from bash is executed each time after any command was
executed. As this is really executed each and every time, it needs to be
lightning fast - that's why I coded it entirely in bash. Yes, I know I
could theoretically use sed or perl or whatever... ;-)

PROMPT_COMMAND='
if [ $TERM = "screen" ]; then
 MYPWD="${PWD/#$HOME/~}"
 [ ${#MYPWD} -gt 20 ] && MYPWD=..${MYPWD:${#MYPWD}-18}
 echo -n -e "\033k$MYPWD\033\\"
fi
'

Cheers,

Malte

Gokdeniz Karadag schrieb:

> Hi, in your script, it would be better to revert it back to local
> hostname after ssh finishes.
>
> Both this and LocalCommand seems neat, too bad that I have solved it
> by manually setting PS1 on all machines :)
>
> ------------------------------
>
> Message: 5
> Date: Thu, 06 Nov 2008 11:25:00 +0100
> From: Malte Skoruppa <malte@...>
> Subject: Re: Setting window title in ssh'ed host
> To: screen-users@...
> Message-ID: <4912C5FC.6020903@...>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Hi,
>
> I solved the problem in bash by editing my ~/.profile file:
>
> ssh() {
>  args=$@
>  echo -ne "\033k${args##* }\033\\";
>  /usr/bin/ssh "$@";
> }
>
> It"s a rather simple script, whenever you call ssh, first this script is
> executed, which calls the real ssh in the end, with the same arguments.
> Before it does that, however, it sets the screen title to the last
> argument of the ssh command. Usually, this is the hostname, at least for
> the way I enter commands ;-)
>
> Malte
>
>
> _______________________________________________
> screen-users mailing list
> screen-users@...
> http://lists.gnu.org/mailman/listinfo/screen-users
>



_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Re: Setting window title in ssh'ed host

by Pandurangan R S :: Rate this Message:

| View Threaded | Show Only this Message

I think you can as well do the following.

ssh() {
args=$@
echo -ne "\033k${args##* }\033\\";
/usr/bin/ssh "$@";
# Set window title back here!
}

Any problem with this approach?

On Fri, Nov 7, 2008 at 6:58 PM, Malte Skoruppa <malte@...> wrote:

>
> Hi,
>
> thanks for the tip with the 'command ssh' instead of /ust/bin/ssh trick... didn't know about that.
>
> I quickly hacked this script into my ~/.profile a while ago, so it may not be that beautiful from a cosmetic point of view. Indeed I can leave out the semicolons, they're just still there because this was a one-liner to begin with ;)
>
> I do 'revert' my screen title after the ssh command terminates. I just don't revert it to the local hostname, but always set the title to the current directory (at least, to the last 20 characters of $PWD) :-)
>
> This is also in my ~/.profile
> The PROMPT_COMMAND from bash is executed each time after any command was executed. As this is really executed each and every time, it needs to be lightning fast - that's why I coded it entirely in bash. Yes, I know I could theoretically use sed or perl or whatever... ;-)
>
> PROMPT_COMMAND='
> if [ $TERM = "screen" ]; then
> MYPWD="${PWD/#$HOME/~}"
> [ ${#MYPWD} -gt 20 ] && MYPWD=..${MYPWD:${#MYPWD}-18}
> echo -n -e "\033k$MYPWD\033\\"
> fi
> '
>
> Cheers,
>
> Malte
>
> Gokdeniz Karadag schrieb:
>>
>> Hi, in your script, it would be better to revert it back to local hostname after ssh finishes.
>>
>> Both this and LocalCommand seems neat, too bad that I have solved it by manually setting PS1 on all machines :)
>>
>> ------------------------------
>>
>> Message: 5
>> Date: Thu, 06 Nov 2008 11:25:00 +0100
>> From: Malte Skoruppa <malte@...>
>> Subject: Re: Setting window title in ssh'ed host
>> To: screen-users@...
>> Message-ID: <4912C5FC.6020903@...>
>> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>>
>> Hi,
>>
>> I solved the problem in bash by editing my ~/.profile file:
>>
>> ssh() {
>>  args=$@
>>  echo -ne "\033k${args##* }\033\\";
>>  /usr/bin/ssh "$@";
>> }
>>
>> It"s a rather simple script, whenever you call ssh, first this script is
>> executed, which calls the real ssh in the end, with the same arguments.
>> Before it does that, however, it sets the screen title to the last
>> argument of the ssh command. Usually, this is the hostname, at least for
>> the way I enter commands ;-)
>>
>> Malte
>>
>>
>> _______________________________________________
>> screen-users mailing list
>> screen-users@...
>> http://lists.gnu.org/mailman/listinfo/screen-users
>>
>
>
>
> _______________________________________________
> screen-users mailing list
> screen-users@...
> http://lists.gnu.org/mailman/listinfo/screen-users


_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Re: Setting window title in ssh'ed host

by einheitlix :: Rate this Message:

| View Threaded | Show Only this Message

Of course that's possible, but I want my screen title to be set to $PWD
every time (especially when I issue a 'cd' command, obviously), not only
after an ssh command :-)

Malte

Pandurangan R S schrieb:

> I think you can as well do the following.
>
> ssh() {
> args=$@
> echo -ne "\033k${args##* }\033\\";
> /usr/bin/ssh "$@";
> # Set window title back here!
> }
>
> Any problem with this approach?
>
> On Fri, Nov 7, 2008 at 6:58 PM, Malte Skoruppa <malte@...> wrote:
>  
>> Hi,
>>
>> thanks for the tip with the 'command ssh' instead of /ust/bin/ssh trick... didn't know about that.
>>
>> I quickly hacked this script into my ~/.profile a while ago, so it may not be that beautiful from a cosmetic point of view. Indeed I can leave out the semicolons, they're just still there because this was a one-liner to begin with ;)
>>
>> I do 'revert' my screen title after the ssh command terminates. I just don't revert it to the local hostname, but always set the title to the current directory (at least, to the last 20 characters of $PWD) :-)
>>
>> This is also in my ~/.profile
>> The PROMPT_COMMAND from bash is executed each time after any command was executed. As this is really executed each and every time, it needs to be lightning fast - that's why I coded it entirely in bash. Yes, I know I could theoretically use sed or perl or whatever... ;-)
>>
>> PROMPT_COMMAND='
>> if [ $TERM = "screen" ]; then
>> MYPWD="${PWD/#$HOME/~}"
>> [ ${#MYPWD} -gt 20 ] && MYPWD=..${MYPWD:${#MYPWD}-18}
>> echo -n -e "\033k$MYPWD\033\\"
>> fi
>> '
>>
>> Cheers,
>>
>> Malte
>>
>> Gokdeniz Karadag schrieb:
>>    
>>> Hi, in your script, it would be better to revert it back to local hostname after ssh finishes.
>>>
>>> Both this and LocalCommand seems neat, too bad that I have solved it by manually setting PS1 on all machines :)
>>>
>>> ------------------------------
>>>
>>> Message: 5
>>> Date: Thu, 06 Nov 2008 11:25:00 +0100
>>> From: Malte Skoruppa <malte@...>
>>> Subject: Re: Setting window title in ssh'ed host
>>> To: screen-users@...
>>> Message-ID: <4912C5FC.6020903@...>
>>> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>>>
>>> Hi,
>>>
>>> I solved the problem in bash by editing my ~/.profile file:
>>>
>>> ssh() {
>>>  args=$@
>>>  echo -ne "\033k${args##* }\033\\";
>>>  /usr/bin/ssh "$@";
>>> }
>>>
>>> It"s a rather simple script, whenever you call ssh, first this script is
>>> executed, which calls the real ssh in the end, with the same arguments.
>>> Before it does that, however, it sets the screen title to the last
>>> argument of the ssh command. Usually, this is the hostname, at least for
>>> the way I enter commands ;-)
>>>
>>> Malte
>>>
>>>
>>> _______________________________________________
>>> screen-users mailing list
>>> screen-users@...
>>> http://lists.gnu.org/mailman/listinfo/screen-users
>>>
>>>      
>>
>> _______________________________________________
>> screen-users mailing list
>> screen-users@...
>> http://lists.gnu.org/mailman/listinfo/screen-users
>>    
>
>  



_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users