Class: SshMenu::Actions

Inherits:
Object
  • Object
show all
Defined in:
lib/sshmenu/actions.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Actions

Returns a new instance of Actions.



6
7
8
9
10
# File 'lib/sshmenu/actions.rb', line 6

def initialize(config)
  @general = config.general
  @connections = config.connections
  @config_file = config.config_file
end

Class Method Details

.ask_edit_with_default_editorObject



33
34
35
36
37
38
39
40
# File 'lib/sshmenu/actions.rb', line 33

def self.ask_edit_with_default_editor
  editor = Config.default_editor
  config = Config.default_config_file
  print "Edit #{config} using default editor '#{editor}' [y/N]? "
  if STDIN.getc =~ /\A[Yy]\z/
    exec("#{editor} #{config}")
  end
end

Instance Method Details

#connect(index) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sshmenu/actions.rb', line 17

def connect(index)
  unless index.between?(0, @connections.length-1)
    raise ArgumentError, 'invalid index'
  end

  conn = @connections[index]

  opts = " #{@general['ssh_opts']}  #{conn['ssh_opts']}"
  cmd = "#{@general['ssh_exec']}"
  cmd << opts
  cmd << " #{conn['user_host']}"

  puts "Connecting to #{conn['user_host']}"
  exec(cmd)
end

#editObject



12
13
14
15
# File 'lib/sshmenu/actions.rb', line 12

def edit
  puts "Edit config file #{@config_file}"
  exec("#{@general['editor']} #{@config_file}")
end