Source i (link to git-repo or to original if based on someone elses unmodified work):

Add the source-code for this project on opencode.net

0
Become a Fan
5.0

Available as/for:
Description:
# Overview

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.

2003.07.11 - v1.0
- Initial release.


Ratings & Comments

24 Comments

davinissim

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.

cinqmars

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:~$

cinqmars

Could you list here your version of konsolewrap?

Burps

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

cinqmars

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$,~,`"'

SpaceMuffin

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/

rumcho

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.

rumcho

This script is awesome! Thanks a bunch! Roumen.

polzleitner

Hi. I used it and was hooked immediately. Wonderful!

Ekardnam

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! =)

nightwriter

cp the executable konsolewrap to /usr/bin That way it is in your path.

Ekardnam

YES! thank you, now i can use this useful improvement! =)

nightwriter

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.

ethx

Is it possible to rename session without using DCOP ?

Qerub

Yes. Try: print -Pn "\e]30;INSERT TEXT HERE\a\e]31;\a" This script should probably use this approach.

jazu

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.

bk12

Good catch! I'm going to integrate this to a new version.

thomas12777

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

bk12

This is Bitstream Vera Sans Mono.

wismerhill

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.

bk12

Good catch! I did not test it with mc. I will have a look at your hack.

armstrong

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?

bk12

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.

armstrong

simple and effectiv... dcop is cool... Anyway, thanks a lot for 12 nice lines making my work a bit easier!

Pling
0 Affiliates
Details
license
version
updated
added
downloads 24h 0
mediaviews 24h 0
pageviews 24h 0

More Various KDE 1.-4. Improvements from bk12:

Colibri
bk12
last update date: 12 years ago

Score 8.4

Other Various KDE 1.-4. Improvements:

Slicker Debian Package for Woody
cirrusgr
last update date: 22 years ago

Score 5.0

Konqueror/kdesktop suggestion
PovMan
last update date: 22 years ago

Score 5.0

Biiig buttons
dbojan
last update date: 20 years ago

Score 5.0

Yet Another KControl
Frans
last update date: 21 years ago

Score 5.0

Next window and next/previos window
dbojan
last update date: 20 years ago

Score 5.0

Fantasie Toolbar
katoe
last update date: 20 years ago

Score 5.0