Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

domm (4030)

domm
  (email not shown publicly)
http://domm.plix.at/

Just in case you like to know, I'm currently full-time father of 2 kids, half-time Perl hacker, sort-of DJ, bicyclist, no longer dreadlocked and 33 years old

I'm also head of Vienna.pm [pm.org], maintainer of the CPANTS [perl.org] project, member of the TPF Grants Commitee [perlfoundation.org] and the YAPC Europe Foundation [yapceurope.org].

I've got stuff on CPAN [cpan.org], held various talks [domm.plix.at] and organised YAPC::Europe 2007 in Vienna [yapceurope.org].

Journal of domm (4030)

Friday August 04, 2006
10:45 AM

set current working directory as a screen name

[ #30527 ]

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!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • 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.
  • 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