Using Terminator instead of Gnome-Terminal

This article was contributed by Nicolas Roman. The article copyright is retained by the contributor.

Terminator allows multiple terminals in one window. Using SSHMenu with Terminator instead of Gnome-Terminal allows a user to split their terminal window and to see multiple terminals at a single glance (i.e. without swapping between tabs). You can see some screenshots here. Even though they show an older version, you'll get a good idea of how handy it is.

This work (including the page you are reading at the moment) has been widely inspired by reading The Adding Telnet Support to SSHMenu article. Many thanks to the author!

To allow transparent usage of Terminator, some work must be done:

  • sub-class GnomeSSHMenu::App to use Terminator
  • tell SSHMenu to use our class instead of the default one

Sub-class GnomeSSHMenu::App to use Terminator

Put the following in a file name sshmenu-terminator.rb:

#!/usr/bin/ruby

require 'gnome-sshmenu'

module SSHMenuTerminator

  class App <GnomeSSHMenu::App

    def build_window_command(host)
      command = 'terminator'
      if host.env_settings and host.env_settings.length > 0
        command = host.env_settings + command
      end
      if host.profile and host.profile.length > 0
        command += ' --profile ' + shell_quote(host.profile)
      end
      ssh_cmnd = "#{ssh_command(host)} #{host.sshparams_noenv}"
      command += ' -e ' + shell_quote("sh -c #{shell_quote(ssh_cmnd)}")
      return command + ' &';
    end

  end

end

This file defines a new class that will be used instead of the SSHMenu one when the application is running. It just replaces the gnome-terminal command with terminator and changes some options because Gnome-Terminal has some options that are not supported by Terminator.

Tell SSHMenu to use our class

This is done by modifying the SSHMenu config file: ~/.sshmenu. Find the 'classes' definition which looks like this by default:

classes: {}

Replace it with the following lines :

classes:
  app: SSHMenuTerminator::App
  app.dialog.prefs: SSHMenu::PrefsDialog
  require: /home/nicolasr/bin/sshmenu-terminator.rb

Of course, the full path to your sshmenu-terminator.rb must be used instead of mine ;-).

Line by line explanation :

require: /home/nicolasr/bin/sshmenu-terminator.rb
This tells SSHMenu to include our file at launch time. Again, be sure of your path here!
app: SSHMenuTerminator::App
This line tells SSHMenu to use the class SSHMenuTerminator instead of the default class.
app.dialog.prefs: SSHMenu::PrefsDialog
This last line tells SSHMenu to use the non-gnome preferences dialog. I do this to avoid the display of the "open all in tabs" option, which is supported by Gnome-Terminal but not by Terminator.

You can now relaunch sshmenu-gnome, or remove the applet from your panel and reload it for these changes to be used.

Enjoy!

Late Disclaimer: This was the first time I met ruby, so maybe my code and/or my explanations are not as good as yours might have been. I apologise for that and I would like to hear feedback on the SSHMenu users mailing list.

Shameless Self Promotion: I recently registered a bazaar branch on the Terminator Launchpad that adds support for cloning terminals. Instead of just splitting the current terminal, it also re-launches the command, if any was given when the first window was opened.

When used together with SSHMenu, it means that when you split your window, you get reconnected to your current host. And that's, IMHO, a true killer feature.