11. Helper Applications

Multi Gnome Terminal comes with two supplemental programs to help extend its functionality into other areas.

11.1. mgt-helper

mgt-helper is a bash script meant to be used in conjunction with Multi Gnome Terminal to extend Multi Gnome Terminal's usefulness in a shell environment. Which is where a lot of what we do at the command line winds up -- in bash, since this is the default shell for Linux, and common on many Unices.

The script itself is a collection of subroutines that can be invoked from within Multi Gnome Terminal's Edit Commands or Keybindings features, and in some cases, used on the command line with other Multi Gnome Terminal options. These subroutines are essentially independent of each other, and should be invoked individually.

Some of the more interesting features are: the ability to have a custom bash history file defined specifically for a Tab (what you get with the UpArrow key); the use of text based applications as GNOME "Document" (URL) handlers in a split or self-contained Tab; and the ability to run complex, compound commands from Edit Commands to initialze Tabs and terminals.

There are some known limitations: mgt-helper is very much bash-centric, and most of the routines will probably not work with other shells without modification (please send patch :). The URL Handlers only work on Linux.

11.1.2. Document (URL) Handlers

This feature is provided so that text based applications may be used with GNOME "document" handling inside Multi Gnome Terminal. Presumably so that such documents can be opened in a split terminal or Tab.

This is basically a feature of GNOME that allows user defined applications for different "document" types. Typically, these are GUI apps. When the mouse is over a type of URL that Multi Gnome Terminal can identify, the URL is highlighted by an underscore. It can then be "launched" with CTRL-MiddleMouse. Which application is used, is typically configured in GNOME.

To change the default GNOME behavior, you will first have to set mgt-helper with the appropriate command line option (e.g. -u) as the handler for GNOME (see below). This can be done through the GNOME menu interface, or by directly editing $HOME/.gnome/Gnome with a text editor (carefully!).

Secondly, be aware that now, any GNOME application that tries to access this feature, will be using mgt-helper as the application of choice, even if it is some other application altogether. This means that there must be alternate handlers set up, preferably in either $HOME/.mgt-helper.rc or /etc/mgt-helper.rc, since other applications don't know about Multi Gnome Terminal and its features. In short, that just will not work at all (unless alternate applications are provided for). Defaults are provided, but probably won't work on some systems. See the script for appropriate variable names, and re-define as needed.

Tip

mgt-helper will use sane defaults for all URL handlers, but you can over-ride these by setting user or site preferences in the configuration files.

Note: This feature only works on Linux at this time.

11.1.3. Command Line Options

This is a list of available mgt-helper command line options. See examples in next section. The basic syntax is:

  mgt-helper [option] CMD_OPTION [arguments]

The following general options may be combined.

Use only one CMD_OPTION option at a time (but can be combined with general options above).

11.1.4. Examples

A few quick examples of mgt-helper usage, of no particular value other than to illustrate the kinds of things that can be done. By and large, these examples are meant to be used with Edit Commands.

Example 8. Advanced usage: Customizing URL Handlers

OK, let's assume all this makes sense, and we have URL handling set up in GNOME, and mgt-helper has been configured enough to know it works OK, including Document handlers in GNOME. Now, let's do something a little more interesting. Let's look for specific file types, and dynamically alter our Handler, and mgt-helper's behavior based on the URL's file type.

Let's say we often download source tarballs, that are gzipped tar archives. We don't need a web browser to download this. And what do we do right after downloading? We unpack it! So we make a custom handler for this situation. Put this in ~/.mgt-helper.rc, and you are there:

 
 # Check the incoming command line to see if we are handling, and if it is a tgz, etc.
 if [ "$1" = "-f" -o "$1" = "-u" ] && [ -f $PTS_FILE ] && echo $2 |grep "\.tgz$\|\.tar\.gz$\|\.Z$" >/dev/null;
  then
    
    # Make a temporary directory using the base filename. Must be exported.
    export dldir=/tmp/`basename $2 |sed 's,\(\.tar\.gz\|\.tgz\|\.Z\)$,,'`
    mkdir -p $dldir 
    
    # Get our current /dev/pts info from MGT (special file created 
    # during handling) that is necessary. $PTS_FILE is defined in mgt-helper
    # already as ~/.mgt_tty.
    pts=`cat $PTS_FILE`
    
    # Make sure to remove it now so it does not cause trouble later!!!
    rm -f $PTS_FILE
    
    # Now do the voodoo.
    exec /usr/bin/multi-gnome-terminal --nowait --add-tab --tname `basename $dldir` -x \
    "mgt-helper -x cd $dldir && wget -P . $2 && tar zvfx `basename $2` && (bash ;:) ||\
     read -p \"Failed, press ENTER to continue...\"" >$pts || exit 1
 fi
   

The first part is just shell stuff to get ready. First find if we are going to be the handler here, and that we have the file type we want, and then create a tmp directory to download into. Next, get our /dev/pts info (important!) that Multi Gnome Terminal feeds us just for this purpose so Multi Gnome Terminal will know where to open a new terminal, then remove the file to keep things clean for the next application that might come calling. This is the trigger we need, to know if the calling program is Multi Gnome Terminal or not. If not, we need to provide an alternate application (this is done elsewhere in mgt-helper).

Now our final command does this: We will be creating a new Tab that will be home to all our command line voodoo. Which is: change to our new directory, use wget to download our file, if successful then unpack it, and if all is still well, start a new shell running in our newly created Tab. If anything fails, we get notified with the original error message still displayed on screen.

Note we made a recursive call to mgt-helper -x in the command passed to Multi Gnome Terminal. It is much better to let a shell expand compound commands like we are using here and interpret metacharacters (though it certainly does not have to be mgt-helper that does this). Also, mgt-helper uses certain variables we might have wanted to take advantage of here: $MGT in case there is more than one version installed, or its not in the $PATH, and $URL_ACTION which can be used to set a preference for how the new terminal is created, e.g. a split, a new tab, or a new window.

One final note ... this only works on a fully qualified URL, e.g. http://someplace.org/somepath/some.tgz.

Similar customized handlers could conceivably be designed for other file types, or for specific sites.

11.2. mgt-pty-helper

mgt-pty-helper is a simple, one dimensional program that facilitates proper updating of the utmp (wtmp) log database. This records who is logged in, and what they are doing, and is used by other programs like who. mgt-pty-helper does this so that Multi Gnome Terminal itself does not have to be suid root, and thus is a more secure way of doing things.

For this to function properly, mgt-pty-helper should have permissions set chmod g+s, and the group owner should be the same as the group owner of the utmp logs (possibly /var/log/utmp or /var/log/wtmp). The correct group ID could be "tty", or "utmp", or something else altogether, depending on platform and packager. If you have installed from raw source, you will have to do this yourself. RPM packages should be doing this for you, though you may want to check and make sure it is working correctly.

If tracking this information is not important, then not to worry ;-) Once installed, there is no user inter-action with mgt-pty-helper.