Archive

Posts Tagged ‘mate-terminal.wrapper’

Fixing mailto-mutt in Linux Mint Maya 2

November 18th, 2012 subogero Comments off

Antonio Radici, mutt’s Debian maintainer kindly replied and asked me to open a Debian bug for fixing the mailto-mutt vs MATE issue. I nearly did it, but decided to do some further testing before. I already had three virtual machines installed: Xubuntu, Linux Mint Maya Xfce and Linux Mint Maya KDE. It turned out that the simplistic mailto-mutt implementation worked perfectly on all.

The reason? Their native terminal emulator either passes the rest of the command line after “-e” to the command called (konsole) or, if not, they come with a wrapper that does just that (gnome-terminal.wrapper, xfce4-terminal.wrapper). The only one missing this wrapper was mate-terminal.

So I wrote another email to Antonio, calling off the new Debian bug, which restored his optimistic outlook on life, the universe and everything. And I set out to write the wrapper. My first shot was a shell script to replace “-e” with “-x”:

#!/bin/sh
while [ "$1" ]; do
  param=$1
  shift
  [ $param = '-e' ] && param='-x'
  args="$args $param"
done
exec mate-terminal $args

Seasoned Unix veterans have already noticed it. Noobs will immediately and enthusiastically learn it: This wrapper works beautifully. Until you pass a parameter that contains spaces, that is.

The shell is a cool programming language, but it has this sometimes irritating habit of messing with and interpreting your special characters, instead of leaving them alone. Fortunately the late Dennis Ritchie invented a language called C, which includes the brilliant concept of the zero-terminated C-strings. Many people hate them, others adore them. But no one can deny the fact that they don’t mess with special characters:

#include <unistd.h>
#include <string.h>
int main(int argc, char *argv[])
{
    int i;
    argv[0] = "/usr/bin/mate-terminal";
    for (i = 1; i < argc; ++i) {
        if (strncmp(argv[i], "-e", 3) == 0) {
            argv[i] = "-x";
        }
    }
    execv(argv[0], argv);
    return 1; /* if exec returns, it's an error, baby */
}

Finally, I submitted the code into a new issue on the github page of mate-terminal.