Tuesday, December 10, 2013

Effective Terminal Windows

This one's for all the terminal junkies out there.

I have a tendency to open about 10-20 terminal windows at a time, and it gets hard to track which terminal is in use for which ongoing project. The defaults for my distro are to put a ridiculously long and useless title on the terminal, and the prompt shows the entire working directory. Titles get really long when the directory structure is nested more than 8 or so levels. I did a little searching and found the right set of configuration commands for bash to make my terminal titles and prompts more useful for me. Now my title shows the current working directory name, and the prompt shows at most 6 levels (the current directory and its 5 ancestors).

Add the following after the definition of PS1 in .bashrc to get my configuration:

# If this is an xterm set the title to the current directory name
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\W\a\]$PS1"
    ;;
*)
    ;;
esac

# cut off really deep prompts
PROMPT_DIRTRIM=6

2 comments:

  1. One day after almost drowning in terminal windows, I've re-discovered GNU screen with its window naming feature (Ctrl-A to name, Ctrl-a ' to switch to desired window, Ctrl-a " to get a list of windows). Now, there's only one terminal window in the desktop session.

    ReplyDelete
    Replies
    1. I mentioned screen before (http://gedare-csphd.blogspot.com/2013/02/screen.html), but I did not know about the window naming, very nice. I haven't used it a lot other than on servers. Sometimes I like my sprawl of 4-10 terminal windows!

      Delete