Konsolewrap is a set of .bashrc commands and a script shell which will automatically changes the name of Konsole buttons according to your current host and path.
To get the current path in your buttons you just need the PROMPT_COMMAND part from the bashrc.sample file. The 'konsolewrap' script is responsible for updating the button text whenever you get out by using ssh, ftp, or even su. It works this way:
konsolewrap ssh login@host
Will set the button text to 'ssh login@host' before executing the command. If you prefer the button text to be just 'login@host', use the -s option. To avoid typing konsolewrap everytime it's needed, it's better to define some aliases like this in your .bashrc:
alias ssh='konsolewrap ssh'
# Installation
Copy konsolewrap somewhere in your path. Edit your .bashrc to add the content of the bashrc.sample file.Last changelog:
2003.07.13 - v1.1 - Fixed error when cd'ing into a dir with spaces. - Fixed the "su -c 'make install'" bug.
Hi.
I prefer the -s option, but it doesn't seem to work for me. I'm getting this error:
konsolewrap -s ssh user@hostname
[: 15: -s: unexpected operator
exec: 17: -s: not found
maybe I'm not using this option correctly?
Thanks.
I love this script, but I'm only interested in having the remote-computer name in the tab, I don't want the "pwd" on yhe localhost :
How can I modify the script so that it only write the "hostname" info ?
Thanks
I know I'm late but ...
... here you can try folowing modification:
cat konsolewrap
#!/bin/sh
#This script is GPL, see http://www.gnu.org
if [ $1 == "-s" ]
then
shift 1
cmd=$1
shift 1
while [[ `echo $1 | grep -c -- -` -eq 1 ]];
do
cmd="$cmd $1"
shift 1
done
else
cmd=""
fi
dcop $KONSOLE_DCOP_SESSION renameSession "$*"
exec $cmd "$@"
... and then replace following entry in your ~/.bashrc:
PROMPT_COMMAND='dcop $KONSOLE_DCOP_SESSION renameSession "`echo $PWD | sed s,^$HOME,~,`"'
with this one:
PROMPT_COMMAND='dcop $KONSOLE_DCOP_SESSION renameSession "`echo ${USER}@${HOSTNAME}:${PWD} | sed s,$HOME$,~,`"'
This is fantastic. I changed the sed string to show up to max of three directories (to keep tabs from getting too long.)
PROMPT_COMMAND='dcop $KONSOLE_DCOP_SESSION renameSession `echo $PWD | sed "s,^$HOME,~$USER,; s,\(/[^/]*\)/.\+\(/.\+/.\+\)$,\1/..\2,"`'
This results in tab names that look like:
~user/dir1/../dir3
or /root/../stuff/
Is it possible to change the tab name when I ssh from one host to another. For example when I ssh into host1 my tab changes to myuser@host1. From there I ssh into host2 and would like my tab to change to myotheruser@host2. is this possible?
Roumen.
but i have a question: (there are no bad questions, only bad answers?)
i can't use the "su"-command!
[hans@localhost hans]$ su
bash: konsolewrap: command not found
how?
but konsolewrap is great, if this error or only newbiemistake is fixed I'll use it! =)
I added the following to bashrc
if [ "$KONSOLE_DCOP_SESSION" ]
then
alias ssh='konsolewrap -s ssh -C'
alias lftp='konsolewrap -s lftp'
alias sftp='konsolewrap -s sftp'
alias su='konsolewrap su -m'
alias ftp='konsolewrap ftp'
alias scp='konsolewrap scp -C'
PROMPT_COMMAND='dcop $KONSOLE_DCOP_SESSION renameSession "`echo $PWD | sed s,^$HOME,~,`"'
fi
Now i can list ftp sessions as well and scp and ssh use compression.
PS Everyone here agrees .... this improvement is fantastic.... thanks.
Thanks for the great improvement, here is a small fix for the error "arguments do not match" when one is in a directory where the directory name contains a space e.g. "/home/user/my stuff/"
Replace:
`echo $PWD | sed s,^$HOME,~,`
in the PROMPT_COMMAND line in .bashrc with:
"`echo $PWD | sed s,^$HOME,~,`"
In another words, just put quotes around the original execution.
Hi. I know this is a poor question, but which font do you use for your Konsole?
(At least my standard Font is with Serifs and I yet haven't found a useful monospace font to use with the Konsole.
Thanks
Thomas
This doesn't work with a midnight commander session. It is renamed to ~ but when I change directory it stay at ~.
I did such a thing for myself bu putting in my ~/.bashrc
if [ -z $MIDNIGHT_COMMANDER ]; then
PROMPT_COMMAND=$PROMPT_COMMAND';dcop $KONSOLE_DCOP_SESSION renameSession $PWD'
export PROMPT_COMMAND
fi
and encountered the mc problem.
So I put up a workaround by putting in ~/.mc/bashrc (a script which is executed when bash is started from mc)
export MIDNIGHT_COMMANDER=1
and in my ~/.bashrc
if [ -z $MIDNIGHT_COMMANDER ]; then
if [ ! -z $KONSOLE_DCOP_SESSION ]; then
PROMPT_COMMAND=$PROMPT_COMMAND';dcop $KONSOLE_DCOP_SESSION renameSession $PWD'
export PROMPT_COMMAND
fi
fi
This way nothing is done when it is an mc.
Quite a dirty hack, but it works.
something like a sshwrap
#!/bin/sh
dcop $KONSOLE_DCOP_SESSION renameSession "$@"
ssh $@
dcop $KONSOLE_DCOP_SESSION renameSession "Shell"
can change the name of the session back after exiting?
It's not necessary if you use the PROMPT_COMMAND variable. At least on my machine the button text will come back to my current path when I leave my ssh session.
Ratings & Comments
24 Comments
Hi. I prefer the -s option, but it doesn't seem to work for me. I'm getting this error: konsolewrap -s ssh user@hostname [: 15: -s: unexpected operator exec: 17: -s: not found maybe I'm not using this option correctly? Thanks.
I think not. Your statement seems to be correct. There must be st. else. zahrubsm@DeepThoughtAtWork:~$ which konsolewrap /usr/local/bin/konsolewrap zahrubsm@DeepThoughtAtWork:~$ cat /usr/local/bin/konsolewrap #!/bin/sh #This script is GPL, see http://www.gnu.org if [ $1 == "-s" ] then shift 1 cmd=$1 shift 1 while [[ "`echo $1 | grep -c -- -`" = "1" ]]; do cmd="$cmd $1" shift 1 done else cmd="" fi dcop $KONSOLE_DCOP_SESSION renameSession "$*" exec $cmd "$@" zahrubsm@DeepThoughtAtWork:~$ konsolewrap -s ssh r4@ca1d001 r4@ca1d001's password: zahrubsm@DeepThoughtAtWork:~$ konsolewrap -x ssh r4@ca1d001 /usr/local/bin/konsolewrap: line 17: exec: -x: invalid option exec: usage: exec [-cl] [-a name] file [redirection ...] zahrubsm@DeepThoughtAtWork:~$
Could you list here your version of konsolewrap?
I love this script, but I'm only interested in having the remote-computer name in the tab, I don't want the "pwd" on yhe localhost : How can I modify the script so that it only write the "hostname" info ? Thanks
I know I'm late but ... ... here you can try folowing modification: cat konsolewrap #!/bin/sh #This script is GPL, see http://www.gnu.org if [ $1 == "-s" ] then shift 1 cmd=$1 shift 1 while [[ `echo $1 | grep -c -- -` -eq 1 ]]; do cmd="$cmd $1" shift 1 done else cmd="" fi dcop $KONSOLE_DCOP_SESSION renameSession "$*" exec $cmd "$@" ... and then replace following entry in your ~/.bashrc: PROMPT_COMMAND='dcop $KONSOLE_DCOP_SESSION renameSession "`echo $PWD | sed s,^$HOME,~,`"' with this one: PROMPT_COMMAND='dcop $KONSOLE_DCOP_SESSION renameSession "`echo ${USER}@${HOSTNAME}:${PWD} | sed s,$HOME$,~,`"'
This is fantastic. I changed the sed string to show up to max of three directories (to keep tabs from getting too long.) PROMPT_COMMAND='dcop $KONSOLE_DCOP_SESSION renameSession `echo $PWD | sed "s,^$HOME,~$USER,; s,\(/[^/]*\)/.\+\(/.\+/.\+\)$,\1/..\2,"`' This results in tab names that look like: ~user/dir1/../dir3 or /root/../stuff/
Is it possible to change the tab name when I ssh from one host to another. For example when I ssh into host1 my tab changes to myuser@host1. From there I ssh into host2 and would like my tab to change to myotheruser@host2. is this possible? Roumen.
This script is awesome! Thanks a bunch! Roumen.
Hi. I used it and was hooked immediately. Wonderful!
but i have a question: (there are no bad questions, only bad answers?) i can't use the "su"-command! [hans@localhost hans]$ su bash: konsolewrap: command not found how? but konsolewrap is great, if this error or only newbiemistake is fixed I'll use it! =)
cp the executable konsolewrap to /usr/bin That way it is in your path.
YES! thank you, now i can use this useful improvement! =)
I added the following to bashrc if [ "$KONSOLE_DCOP_SESSION" ] then alias ssh='konsolewrap -s ssh -C' alias lftp='konsolewrap -s lftp' alias sftp='konsolewrap -s sftp' alias su='konsolewrap su -m' alias ftp='konsolewrap ftp' alias scp='konsolewrap scp -C' PROMPT_COMMAND='dcop $KONSOLE_DCOP_SESSION renameSession "`echo $PWD | sed s,^$HOME,~,`"' fi Now i can list ftp sessions as well and scp and ssh use compression. PS Everyone here agrees .... this improvement is fantastic.... thanks.
Is it possible to rename session without using DCOP ?
Yes. Try: print -Pn "\e]30;INSERT TEXT HERE\a\e]31;\a" This script should probably use this approach.
Thanks for the great improvement, here is a small fix for the error "arguments do not match" when one is in a directory where the directory name contains a space e.g. "/home/user/my stuff/" Replace: `echo $PWD | sed s,^$HOME,~,` in the PROMPT_COMMAND line in .bashrc with: "`echo $PWD | sed s,^$HOME,~,`" In another words, just put quotes around the original execution.
Good catch! I'm going to integrate this to a new version.
Hi. I know this is a poor question, but which font do you use for your Konsole? (At least my standard Font is with Serifs and I yet haven't found a useful monospace font to use with the Konsole. Thanks Thomas
This is Bitstream Vera Sans Mono.
This doesn't work with a midnight commander session. It is renamed to ~ but when I change directory it stay at ~. I did such a thing for myself bu putting in my ~/.bashrc if [ -z $MIDNIGHT_COMMANDER ]; then PROMPT_COMMAND=$PROMPT_COMMAND';dcop $KONSOLE_DCOP_SESSION renameSession $PWD' export PROMPT_COMMAND fi and encountered the mc problem. So I put up a workaround by putting in ~/.mc/bashrc (a script which is executed when bash is started from mc) export MIDNIGHT_COMMANDER=1 and in my ~/.bashrc if [ -z $MIDNIGHT_COMMANDER ]; then if [ ! -z $KONSOLE_DCOP_SESSION ]; then PROMPT_COMMAND=$PROMPT_COMMAND';dcop $KONSOLE_DCOP_SESSION renameSession $PWD' export PROMPT_COMMAND fi fi This way nothing is done when it is an mc. Quite a dirty hack, but it works.
Good catch! I did not test it with mc. I will have a look at your hack.
something like a sshwrap #!/bin/sh dcop $KONSOLE_DCOP_SESSION renameSession "$@" ssh $@ dcop $KONSOLE_DCOP_SESSION renameSession "Shell" can change the name of the session back after exiting?
It's not necessary if you use the PROMPT_COMMAND variable. At least on my machine the button text will come back to my current path when I leave my ssh session.
simple and effectiv... dcop is cool... Anyway, thanks a lot for 12 nice lines making my work a bit easier!