Quest for terminal application nirvana

| 1 Comment | No TrackBacks

The real power of using Linux/Unix is in the command-line interface. As a result, terminal applications are the bread and butter of the Linux/Unix power user. That is, if they use a graphical user interface. If they're some kind of wacky console-only freak, that's another story.

Anyway... where was I? Oh yeah, terminal applications. I've never been completely satisfied with any of the standard offerings. Over the years I've used xterm, aterm, eterm, gnome-terminal, konsole, and some others I can't remember the names of. KDE's konsole and gnome-terminal are both pretty and all, but seem to be lacking in a few areas of terminal emulation. It seems programs like mutt do a good job of breaking terminal emulation if there's a weakness to be exploited.

Plus, konsole and gnome-terminal just take too frickin' long to start up. In my mind, terminal applications are doing something very simple and therefore should be lightweight and should launch instantaneously when needed.

One thing I do like about KDE's and GNOME's terminal apps is the support for tabs. If you're willing to push your mouse around a bit, you can even change the names/titles of each tabbed terminal session to something more meaningful than the default "Shell No. 99" or GNOME's standard: "Terminal."

Both of these terminal apps also have hot keys like CTRL+SHIFT+N (KDE) or CTRL+SHIFT+T (GNOME) to create new tabs. That's handy, but not as handy as it could be.

What would be ideal, in my little world, is a way to create new, customized tabs in a terminal application via the command line.

Next, I find I usually want to dedicate each terminal session I create to a specific task like:

  • Running a yum -y update
  • Opening an SSH connection to a remote host
  • Viewing a local file with less
  • Miscellaneous/general filesystem interaction

Creating a new tab is only the first of a few steps I must take to create a new session, distinguish it from others that may be open, and, if applicable, run a command in the terminal.

When running multiple terminal sessions in a graphical environment without any kind of significantly distinguishing characteristics associated with each terminal session, it's easy to get confused. I know I'm not the only person who types something like sudo poweroff into a terminal session only to realize afterward the system being shut down isn't the one you meant to shut down. In worse cases, it's a system you don't have physical access to.

fterm

I'm always open to new solutions, but for now, I have a shell script that I've maintained for several years called fterm (FozzTerm) that I run anytime I need a new terminal window. In its most basic form, fterm is just a fast way for me to launch a new terminal session with the geometry and foreground/background colors I prefer.

Since most of my terminal interaction involves SSH connections to remote systems, fterm also makes doing this more convenient. If I add a parameter after the fterm command, the script assumes I want to open an SSH connection to the host named by the parameter. A new terminal session will be launch and ssh will be run in that session.

Additionally, fterm inserts the hostname into the titlebar of the terminal session window which makes it so much easier to identify a specific session or remind myself which host I'm working with.

This works great when I want to log into the remote host using the same username I'm using when I execute the fterm script, but it's not uncommon for me to need to log into a remote system using a different username.

So, I originally modified the fterm script to prompt for a username, indicating that if the user merely pressed the ENTER key, the current username would be used.

% fterm foo.bar.com
[fozz] jdoe

This made things easier, but eventually I realized it could be better. My improvement was creating a cache of usernames associated with hostnames which could be looked at anytime you called fterm with a hostname as parameter. So, the next time you opened an fterm session to foo.bar.com:

% fterm foo.bar.com
[jdoe]

Lately, the actual terminal application run by my fterm script is xterm, but I have configured it to use other application as well.

In the interest of providing others with code they can use or inspiring them to come up with a tool that improves their own productivity, I'm including the code for fterm below. I'd also be interested in, perhaps, better solutions people have created or found.

The real power of using Linux/Unix is in the command-line interface. As a result, terminal applications are the bread and butter of the Linux/Unix power user. That is, if they use a graphical user interface. If they’re some kind of wacky console-only freak, that’s another story.

Anyway... where was I? Oh yeah, terminal applications. I’ve never been completely satisfied with any of the standard offerings. Over the years I’ve used xterm, aterm, eterm, gnome-terminal, konsole, and some others I can’t remember the names of. KDE’s konsole and gnome-terminal are both pretty and all, but seem to be lacking in a few areas of terminal emulation. It seems programs like mutt do a good job of breaking terminal emulation if there’s a weakness to be exploited.

Plus, konsole and gnome-terminal just take too frickin’ long to start up. In my mind, terminal applications are doing something very simple and therefore should be lightweight and should launch instantaneously when needed.

One thing I do like about KDE’s and GNOME’s terminal apps is the support for tabs. If you’re willing to push your mouse around a bit, you can even change the names/titles of each tabbed terminal session to something more meaningful than the default “Shell No. 99” or GNOME’s standard: “Terminal.”

Both of these terminal apps also have hot keys like CTRL+SHIFT+N (KDE) or CTRL+SHIFT+T (GNOME) to create new tabs. That’s handy, but not as handy as it could be.

What would be ideal, in my little world, is a way to create new, customized tabs in a terminal application via the command line.

Next, I find I usually want to dedicate each terminal session I create to a specific task like:

  • Running a yum -y update
  • Opening an SSH connection to a remote host
  • Viewing a local file with less
  • Miscellaneous/general filesystem interaction

Creating a new tab is only the first of a few steps I must take to create a new session, distinguish it from others that may be open, and, if applicable, run a command in the terminal.

When running multiple terminal sessions in a graphical environment without any kind of significantly distinguishing characteristics associated with each terminal session, it’s easy to get confused. I know I’m not the only person who types something like sudo poweroff into a terminal session only to realize afterward the system being shut down isn’t the one you meant to shut down. In worse cases, it’s a system you don’t have physical access to.

fterm

I’m always open to new solutions, but for now, I have a shell script that I’ve maintained for several years called fterm (FozzTerm) that I run anytime I need a new terminal window. In its most basic form, fterm is just a fast way for me to launch a new terminal session with the geometry and foreground/background colors I prefer.

Since most of my terminal interaction involves SSH connections to remote systems, fterm also makes doing this more convenient. If I add a parameter after the fterm command, the script assumes I want to open an SSH connection to the host named by the parameter. A new terminal session will be launch and ssh will be run in that session.

Additionally, fterm inserts the hostname into the titlebar of the terminal session window which makes it so much easier to identify a specific session or remind myself which host I’m working with.

This works great when I want to log into the remote host using the same username I’m using when I execute the fterm script, but it’s not uncommon for me to need to log into a remote system using a different username.

So, I originally modified the fterm script to prompt for a username, indicating that if the user merely pressed the ENTER key, the current username would be used.

% fterm foo.bar.com
[fozz] jdoe

This made things easier, but eventually I realized it could be better. My improvement was creating a cache of usernames associated with hostnames which could be looked at anytime you called fterm with a hostname as parameter. So, the next time you opened an fterm session to foo.bar.com:

% fterm foo.bar.com
[jdoe]

Lately, the actual terminal application run by my fterm script is xterm, but I have configured it to use other application as well.

In the interest of providing others with code they can use or inspiring them to come up with a tool that improves their own productivity, I’m including the code for fterm below. I’d also be interested in, perhaps, better solutions people have created or found.

#!/bin/sh

# fterm - A convenient way of launching a custom terminal window
# and also for connecting via SSH to remote hosts

# Set up some defaults
USERNAMECACHEFILE=$HOME/.fterm_cache
USER=`whoami`
TERMAPP=xterm
TERMNAME="FozzTerm"

# If parameters... launch with SSH
if [ "$1" != "" ]
then

# Look for cached username for host in the cache file
if [ -f "$USERNAMECACHEFILE" ]
then
CACHEDUSER=`grep "^$1:" $USERNAMECACHEFILE | cut -f2 -d:`
if [ "$CACHEDUSER" ]
then
FOUNDUSER=1
USER=$CACHEDUSER
fi
else
touch $USERNAMECACHEFILE
fi

# prompt for username change/confirmation
echo -n "[$USER] "
read USERNAME
if [ "$USERNAME" = "" ]
then
USERNAME=$USER
fi

# Configure the title
if [ "$2" != "" ]
then
TITLE=$2
else
TITLE="$TERMNAME: $1 ($USERNAME)"
fi


# Launch the appropriate app
case $TERMAPP in
aterm)
aterm -sl 2000 -geometry 80x40 -bg black -fg green -tr \
-tint rgbi:1.2/1.2/1.2 -tinttype true -n "$TITLE" \
-title "$1" -e ssh -l $USERNAME $1 $2 $3 $4&
;;
xterm)
xterm -geometry 90x50 -bg black -fg green -T "$TITLE" \
-e ssh -Y -l $USERNAME $1 &
;;
konsole)
konsole -vt_sz 80x50 -T "$TITLE" \
--schema $HOME/.kde/share/apps/konsole/TransparentGreenonBlack.schema \
-e ssh -l $USERNAME $1 &
;;
esac

# Modify cache, if necessary
if grep -q "^$1:" $USERNAMECACHEFILE
then
sed -i "/^$1:/c$1:$USERNAME" $USERNAMECACHEFILE
else
echo "$1:$USERNAME" >> $USERNAMECACHEFILE
fi

else
# We have no parameter - launch simple terminal
case $TERMAPP in
xterm)
xterm -geometry 90x50 -bg black -fg green -T "$TERMNAME" &
;;

aterm)
aterm -sl 2000 -geometry 80x40 -bg black -fg green -tr \
-tint rgbi:1.2/1.2/1.2 -tinttype true -n "$TERMNAME" -title "$TERMNAME" &
;;
konsole)
konsole -vt_sz 80x50 -T "$TERMNAME" \
--schema /usr/share/apps/konsole/GreenOnBlack.schema &
;;
esac
fi

No TrackBacks

TrackBack URL: http://fozzolog.fozzilinymoo.org/mt-tb.cgi/1082

1 Comment

1BTW: In Konsole, you can press ++ to change the name on the tab, without ever taking your hands off the keyboard. I do it all the time.
------
--------

Leave a comment

About this Entry

This page contains a single entry by Doran L. Barton published on November 30, 2006 9:43 PM.

FC6 on the laptop (HP zv5000z) was the previous entry in this blog.

catalystinstaller.sh - Automated Catalyst package installation for FC6 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.