Konsolewrap

Various KDE 1.-4. Improvements

Source (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
Score 50.0%
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 [email protected]

Will set the button text to 'ssh [email protected]' before executing the command. If
you prefer the button text to be just '[email protected]', 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:

16 years ago

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.

davinissim

11 years ago

Hi.

I prefer the -s option, but it doesn't seem to work for me. I'm getting this error:
konsolewrap -s ssh [email protected]
[: 15: -s: unexpected operator
exec: 17: -s: not found

maybe I'm not using this option correctly?

Thanks.

Report

cinqmars

11 years ago

Could you list here your version of konsolewrap?

Report

cinqmars

11 years ago

I think not. Your statement seems to be correct. There must be st. else.

[email protected]:~$ which konsolewrap
/usr/local/bin/konsolewrap
[email protected]:~$ 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 "[email protected]"
[email protected]:~$ konsolewrap -s ssh [email protected]
[email protected]'s password:

[email protected]:~$ konsolewrap -x ssh [email protected]
/usr/local/bin/konsolewrap: line 17: exec: -x: invalid option
exec: usage: exec [-cl] [-a name] file [redirection ...]
[email protected]:~$

Report

Burps

12 years ago

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

Report

cinqmars

11 years ago

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 "[email protected]"

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

Report

SpaceMuffin

12 years ago

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/


Report

rumcho

13 years ago

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 [email protected] From there I ssh into host2 and would like my tab to change to [email protected] is this possible?
Roumen.

Report

rumcho

14 years ago

This script is awesome!
Thanks a bunch!
Roumen.

Report

polzleitner

15 years ago

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

Report

Ekardnam

15 years ago

but i have a question: (there are no bad questions, only bad answers?)

i can't use the "su"-command!

[[email protected] hans]$ su
bash: konsolewrap: command not found

how?

but konsolewrap is great, if this error or only newbiemistake is fixed I'll use it! =)

Report

nightwriter

15 years ago

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

Report

Ekardnam

15 years ago

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

Report

nightwriter

15 years ago

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.

Report

ethx

16 years ago

Is it possible to rename session without using DCOP ?

Report

Qerub

15 years ago

Yes. Try:
print -Pn "\e]30;INSERT TEXT HERE\a\e]31;\a"

This script should probably use this approach.

Report

jazu

16 years ago

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.

Report

C

bk12

16 years ago

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

Report

thomas12777

16 years ago

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

Report

C

bk12

16 years ago

This is Bitstream Vera Sans Mono.

Report

wismerhill

16 years ago

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.

Report

C

bk12

16 years ago

Good catch!

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

Report

armstrong

16 years ago

something like a sshwrap

#!/bin/sh
dcop $KONSOLE_DCOP_SESSION renameSession "[email protected]"
ssh [email protected]
dcop $KONSOLE_DCOP_SESSION renameSession "Shell"

can change the name of the session back after exiting?

Report

C

bk12

16 years ago

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.

Report

armstrong

16 years ago

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

Report

16 years ago

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.

12345678910
product-maker Base: 4 x 5.0 Ratings
File (click to download) Version Description PackagetypeArchitecture Downloads Date Filesize DL OCS-Install MD5SUM
*Needs pling-store or ocs-url to install things
Pling
0 Affiliates
Details
license
version
updated Jul 13 2003
added Jul 11 2003
downloads 24h
0
mediaviews 24h 0
pageviews 24h 0