Start remote commands without a terminal window

You can use SSHMenu to run commands on remote servers simply by typing the command after the hostname in the 'Host Connection Details' dialog. For example to tail a log file on a web server, you might enter:

www.example.com tail -f /var/log/apache2/access.log

You can also run GUI commands using the '-X' option to enable the X-Forwarding feature of SSH. When you launch a GUI command, you might not want the terminal window that SSHMenu normally provides. This article describes how to add a checkbox to the host dialog to indicate when the terminal window is not required:

screenshot of modified dialog

As with the other SSHMenu 'hacks' described on this site, modifying the host dialog will not require any changes to the SSHMenu source code. Instead, the modified behaviour will be defined in new classes in a Ruby source file and then the SSHMenu config file will be modified to point to the new classes. For a more detail description of this process, see the article about adding telnet support to SSHMenu and for even more information, refer to the SSHMenu Hacker's Guide.

The first step is to create a file containing the new class definitions. I saved the following code in a file called '/home/grant/ruby/terminal_optional.rb':

require 'gnome-sshmenu'

module TerminalOptional

  class App <GnomeSSHMenu::App

    def build_window_command(host)
      if host.no_terminal
        return ssh_command(host) + ' ' + host.sshparams_noenv + ' &'
      else
        return super(host)
      end
    end

  end

  class HostItem <GnomeSSHMenu::HostItem

    attr_accessor :no_terminal

    def initialize(h={})
      super
      @no_terminal = true if h['no_terminal']
    end

    def to_h
      h = super
      h['no_terminal'] = true if no_terminal
      return h
    end

  end

  class HostDialog <GnomeSSHMenu::HostDialog

    def add_other_inputs
      super
      @no_terminal = Gtk::CheckButton.new( "No terminal window required", false)
      @no_terminal.active = true if @host.no_terminal
      @body.pack_start(@no_terminal, false, true, 0)
    end

    def dialog_to_host(host=nil)
      host = super(host)
      host.no_terminal = @no_terminal.active?
      return host
    end

  end

end

The next step is to modify the SSHMenu config file to point to these new classes. The config file is a YAML file called .sshmenu in your home directory. By default, the config file will contain an empty 'classes' definition that looks like this:

classes: {}

I changed that part of the file to look like this (note the empty curly braces and the blank line were both removed and four extra lines added):

classes: 
  app: TerminalOptional::App
  app.dialog.host: TerminalOptional::HostDialog
  app.model.hostitem: TerminalOptional::HostItem
  require: /home/grant/ruby/terminal_optional.rb

The final step is to restart SSHMenu. To achieve this, you could remove the applet from the panel and add it back, or you could log out and back in.

That's all there is to it.