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.1. Configuration

There are a number of variables that can be defined to alter mgt-helper's behavior and set user preferences. These are all listed in the script itself, though some may be commented out.

It is highly recommended that such user or site preferences be put in another file. This can be /etc/mgt-helper.rc for site-wide preferences, or $HOME/.mgt-helper.rc for individual user preferences. Both of these files are checked by mgt-helper automatically, with the latter taking precedence over other files, and the defaults as set in the script itself.

In addition, since these configuration files will be sourced by Bash, any other variables, or manipulation of the bash environment, can be added at your discretion. For instance, you could set Bash's TMOUT (time out) variable, and even base this action conditionally on other environment factors, or the contents of the command line. Or you could check the command line contents, see if a url handler is being invoked, then check the URL itself, and alter the default handler dynamically based on certain conditions. For instance, use Mozilla for your favorite multi-media sites, and w3m for less interesting HTTP sites. Or perhaps use the document extension to determine the choice of browsers, e.g. Mozilla for shockwave, or wget for web-hosted RPMs.

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.


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.

  • -D

    Turn on "verbose", debugging mode, which writes some debug type output to the screen and also to /tmp/mgt-helper.debug.

  • -r RC_FILE

    Specify this RC_FILE, which is parsed after any other config files, and will over-ride any previously defined settings.

  • -T

    Force this Command to use a full Tab.

  • -H

    Force this Command to a horizontally split Tab.

  • -V

    Force this Command to a vertically split Tab.

  • -W

    Force this Command to a "New Window".

  • -WT

    Force this Command to a "New Window" with appropriate start-up Tabs for the current Class.


    Use this Multi Gnome Terminal ACTION for output of the Command. Example: --add-tab, or --add-tab --tclass myclass. Don't get carried away with this, as all actions will not work. Notably, -x, which is used by CMD_OPTIONS listed below. And, may not be appropriate for all CMD_OPTIONS. Be sure to quote if there is any whitespace.

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

  • -h, --history EXTENSION

    Specify a user defined, custom bash history file for this terminal/Tab, where EXTENSION is a user-defined, unique string. This probably only works with bash right now. Use with Edit Commands.

  • -u, --url-handler, --http-handler

    Set mgt-helper as the GNOME URL Handler for HTTP (WWW) URLs. Also can be used for HTTPS URLS. See full example syntax below. You will have to either define this in the GNOME menus as the "Document" handler. Or, hand edit your $HOME/.gnome/Gnome file and set accordingly. The idea here is to open a new Tab (or split terminal), with a text client running. There is no default HTTP handler set; mgt-helper will look for w3m, links, and lynx and use whatever it finds first. Though you can set a preference for this (and other handlers too).

  • -f, --ftp-handler

    Set mgt-helper as the GNOME URL Handler for FTP URLs, similar to above. Default handler is whatever is used for HTTP above.

  • -m, --mailto-handler

    Set mgt-helper as the GNOME URL Handler for mailto style URLs (i.e. email addresses), similar to above. Default handler is mutt.

  • -F, --file-handler

    Set mgt-helper as the URL Handler for files, similar to above. Depending on what mgt-helper thinks of the file, it will either provide some information itself, or spawn a file manager (default is Midnight Commander).

  • -x, --execute

    Use this option to run complex, compound commands from within Multi Gnome Terminal, e.g. as an Edit Commands command. For example, a command like ps | less does not work from Edit Commands. But by wrapping this in mgt-helper (or another script), it does work, since now the shell is handling the parsing of the command string (which happens to be shell constructs).

  • -U, --user-guide

    Open this User Guide in a Tab (or split terminal). Use with Edit Commands, or from the command line.

  • -s, --ssh [ssh args] HOST [command]

    Use mgt-helper as a ssh wrapper. This is probably only useful where the sshd daemon may be running as another user, and thus breaks our GNOME URL Handling tricks. Use with Edit Commands, if needed (ie URL Handlers don't work).

  • -S, --su

    Use mgt-helper as a su wrapper. Su will also break the Multi Gnome Terminal URL Handling extensions. Use this instead of the Multi Gnome Terminal Root menu selection, or with Edit Commands.

  • -g, --google

    Search Google from Edit Commands.

  • -lg, --lin-google

    Same as above but searches on google.com/linux only.

  • -l, --lookup [WORD]

    Look up a word in an on-line dictionary. This will use the dict command if availalbe, otherwise the Merriam Webster on-line dictionary is used. Provided as a convenience feature only. If WORD is omitted, then user is prompted for word to look up.

  • -d, --debug COMMAND [args]

    This is a simple troubleshooting aid to capture error output from shell commands (not Multi Gnome Terminal internals) that might vanish quickly otherwise. For instance, you have a "command" to open a Tab, but there is some error and the Tab closes too quickly to see what happened. For use with Edit Commands.

  • --show-all

    This dumps all bash variables from the mgt-helper environment to STDOUT, and also writes the same data to /tmp/mgt-helper.debug. For simple troubleshooting purposes.

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 1. Create a custom bash history file

  mgt-helper -h my_tab

This will create, and subsequently use, a bash history file named .bash_history-my_tab, whenever this Tab is opened. So what you get with the UpArrow will only be command history that is used in this Tab. It also uses the mgt-helper variable SHELL_CMD to start the shell. Use with Edit Commands.

Example 2. Read my mail on another system, in such a way that URL Handling works like we want

  mgt-helper -s -t some_host.org   mutt

This essentially translates out to: ssh -t some_host.org mutt, and is only useful to make sure that URL Handling extensions are sure to work. Use with Edit Commands.

Example 3. Create a shell/Tab that times out in 15 minutes

  mgt-helper -x export TMOUT=900; bash --login

Bash's TMOUT feature only works for interactive shells, and while the user is sitting at the bash prompt. Use with Edit Commands.

Example 4. Show who is logged in and what they are up to

  mgt-helper -x w |  sed 's/   //' |  /usr/bin/less -Ps"`hostname -s`\: who is that"

We trimmed a little gratuitous whitespace with sed here too, just so it fits better. Use with Edit Commands.

Example 5. Show file listing with current directory

  mgt-helper -x ls  -laF  | /usr/bin/less -P "All files for\: `pwd` `date`"

Use with Edit Commands.

Example 6. Create a "New Mail" Tab for mutt

  mgt-helper  -x while : ; do mutt -H /dev/null ; clear ; done

This will create a Tab just for composing new mail in mutt. (It is not useful for replying, just starting a new mail from scratch.)

Example 7. Setting GNOME Document Handlers

If you want to hand edit your ~/.gnome/Gnome file to set up URL Handling for use in Multi Gnome Terminal:

    [URL Handlers]
    file-show=mgt-helper -F "%s"
    mailto-show=mgt-helper -m "%s" 
    http-show=mgt-helper -u "%s"
    https-show=mgt-helper -u "%s"
    ftp-show=mgt-helper -f "%s"

We are just showing the relevant ones here. The handlers that Multi Gnome Terminal will use are defined in the script as:

    HTTP_HANDLER (undefined, script will look for w3m, links, or lynx)
    FTP_HANDLER (undefined, and uses same as above by default)
    FILE_HANDLER=mc (though some files are handled by mgt-helper itself)

And you must set alternate handlers for non-Multi Gnome Terminal applications (if you use them elsewhere):


Again, it is best to set these in $HOME/.mgt-helper.rc.

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;
    # 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

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.