LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   konsole window title change in SSH session (http://www.linuxquestions.org/questions/linux-software-2/konsole-window-title-change-in-ssh-session-484981/)

maenho 09-19-2006 10:23 AM

konsole window title change in SSH session
 
Dear all,

I would like the window title and if possible also the tab title of the KDE terminal program konsole to change to the name of the remote host when I start an SSH session. Would that be possible?

thanks,

Steven

matthewg42 09-19-2006 11:33 AM

Yes it is.

I wrote a little shell script which changes a konsole tab title, and prints out the old value.

Code:

#!/bin/bash
# This script is called "konsole_tabname"

if [ -n "$KONSOLE_DCOP_SESSION" ] ; then
    dcop $KONSOLE_DCOP_SESSION sessionName
    dcop $KONSOLE_DCOP_SESSION renameSession "$1" 2> /dev/null 1>&2
fi

You could then write a little wrapper for ssh like this:

Code:

#!/bin/bash
# This script is called "kssh".  DO NOT call it ssh or it
# will call itself recursively!

old_tab_title="$(konsole_tabname "ssh session")"
ssh "$@"
konsole_tabname "$old_tab_title" > /dev/null


maenho 09-19-2006 02:50 PM

thanx, that is exactly what I needed. I made a minor change to your script so that the tab title shows the hostname. In case anybody is interested:

Code:

# This script is called "kssh".  DO NOT call it ssh or it
# will call itself recursively!

eval hostname=\$$#
old_tab_title="$(konsole_tabname "$hostname")"
ssh "$@"
konsole_tabname "$old_tab_title" > /dev/null


jamesshau 03-03-2010 11:10 AM

I got help from the posts. I'd like to contribute something hopefully also useful.

1. It's not necessary to name "kssh" differently from ssh, if you use the full path, say /usr/bin/ssh in "kssh". This saved me from the "oops, should have use kssh, not ssh" moments.

2. dcop works for me only on the machine I launched konsole.

(Got this kind of errors:
[sw18-0216t]sw18:$VIEW_ROOT>dcop --user jshau --session .DCOPserver_swvnc3.kickfire.com__50
SocketUNIXConnect: Cannot connect to non-local host swvnc3.kickfire.com
DCOPClient::attachInternal. Attach failed Could not open network socket
SocketUNIXConnect: Cannot connect to non-local host swvnc3.kickfire.com
DCOPClient::attachInternal. Attach failed Could not open network socket
ERROR: Couldn't attach to DCOP server!
)

But I'd like to be able update the tab name as I continue to ssh to
other machines, or more importantly to me, as I use svn views. I need
to do something a bit complicated as follows.

* All the following is done only for interactive shell (e.g. check the prompt variable).

o Upon shell startup, (including use svn view in my case)

if KONSOLE_DCOP_SESSION is defined and first time for this terminal,

= mkdir -p ~/rdcop/`tty`; let it be TTY_DIR
= launch a background process, which
- save its pid in a file in TTY_DIR
- periodically (e.g. 1 sec) set the session tab name with the
last line in file <TTY_DIR>/tabname.stk.
- self clean up if the tty no longer in /dev/pts.

append the desired tab name to <TTY_DIR>/tabname.stk.
also save it in an env var for this shell process.

o In "kssh", mainly need to let the login shell in the remote
machine to know which <TTY_DIR> to use. I just saved it in
a file ~/rdcop/<remote hostname>, followed by sync(1) to make
to sure the remote shell will pick it up reliably.

o I have two flavors of "popping" tabname.stk: popping to
the given tab name (saved in env var), inclusively or exclusivly.

Use the inclusive version upon logout of login shell (in .logout
for tcsh). I use the exclusive version when the popping needs
to be done by "the parent", e.g.

# cde useview is my command to use svn view;
# pop_konsole_tabname.pl is a script of mine;
# + means exclusively with tab name given in env var.
[sw18-0216t]sw18:$VIEW_ROOT>alias setview
cde useview !:1; pop_konsole_tabname.pl +


It would be nice if there's a much simpler way.

RickyRockRat 08-31-2010 02:32 PM

Got to the Settings->Edit Current Profile,
then click on the tabs tab. Change your 'Tab Title format' and 'Remote tab title format' to %w

This will use your PS1 setting on whichever machine you are on. Hope that helps....


All times are GMT -5. The time now is 06:59 AM.