/ domm

I hack Perl for fun and
profit.

Follow me on twitter!
Atom Icom ... on Atom!
<<<<<<<<<<
06.09.2006: Post-YAPC::Europe CPANTS news
04.09.2006: YAPC::Europe Day 3 (and journey back home)
01.09.2006: YAPC::Europe Day 2
31.08.2006: YAPC::Europe Day 1 (and a bit of day 2)
31.08.2006: YAPC::Europe Day 1 (and a bit of day 2)
30.08.2006: YAPC::Europe Day 0 & 1
28.08.2006: [yapceu2006] CPANTS hackathon
04.08.2006: set current working directory as a screen name

I use screen quite a lot. In fact, I can't imagine NOT using it, not only because it allows me stay in IRC while not beeing connected, but mainly because I do not like cluttered desktops. Instead of n open xterm, I have one with a screen session handling n'windows'.

The only problem is that having a screen session with, say, 8 'windows' open, gets complex. I can remember the 'CTRL-] 1' maps to my main terminal, CTRL-] 2' to IRC, and a few more. But more often than not I tab through my open screens trying to find the one in the right directory.

To solve this problem, add this in your .bashrc (or whatever you happen to be using):

    case $TERM in

    xterm*)

        PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'

        ;;

    screen*)

        PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}:${PWD}\007\033k$PWD\033\\"'

        ;;

    *)

        ;;

    esac

This sets the title of your xterm to the current working directory. But if you're running screen, it also sets the name of this screen 'window' to pwd. Which is great, because now you can hit CTRL-] " and get a list of all 'windows' and in which directory they are.

A bit like this:

0 root                                                                       $

1 /home/domm/3united/threeunited.coin.messaging.sms                          $

2 /home/domm/3united/threeunited.coin.messaging.sms/t/sms_http               $

3 /home/domm/3united/threeunited.coin.connectivity/http/de.nextid            $

.

.

.

Now it's easy to find the right screen. Yay!

Original: http://use.perl.org/~domm/journal/30527

Legacy comments

nik: Include the command too (orignal post)

I don't know the bash equivalent (I'm sure it has one) but the tcsh man page has a good example (when describing the cwdcmd and postcmd variables) of doing the same thing, but also including the name/arg list of the most recently executed command.



So your xterm/screen title might be:



~/src/> vi foo.c



which I've found invaluable when hunting between different windows.

Dom2: zsh too (orignal post)

In zsh, I stick this in my chpwd() function. Works great!

chpwd () {

    [[ -t 1 ]] || return

    case $TERM in

    xterm*)

        print -Pn "\e]0;%m:%~\a" ;;

    screen)

        print -Pn "\e_%m:%~\e\\"

        print -Pn "\ek%m:%~\e\\" ;;

    esac

}

# Initialize.

cd $PWD

Hmmm, wish I'd commented on why I have two lines in there for screen... I can't remember now. The [[ -t 1 ]] bit is to ensure that stdo

Comments (via disqus)

02.08.2006: howto setup an ssh tunnel
21.07.2006: lumbago; cpants; holidays
>>>>>>>>>>