Class: Utils::ConfigFile::SshTunnel

Inherits:
BlockConfig show all
Defined in:
lib/utils/config_file.rb

Defined Under Namespace

Classes: CopyPaste

Instance Method Summary collapse

Methods inherited from BlockConfig

config, inherited, #to_ruby

Constructor Details

#initializeSshTunnel

The initialize method sets up the instance by calling the superclass constructor and assigning the terminal multiplexer configuration.

Parameters:

  • terminal_multiplexer (Object)

    the terminal multiplexer to be assigned



477
478
479
480
# File 'lib/utils/config_file.rb', line 477

def initialize
  super
  self.terminal_multiplexer = terminal_multiplexer
end

Instance Method Details

#copy_paste(enable = false) {|block| ... } ⇒ CopyPaste?

The copy_paste method manages the copy-paste functionality by returning an existing instance or creating a new one.

This method checks if a copy-paste instance already exists and returns it if available. If no instance exists, it creates a new one based on whether a block is provided or the enable flag is set to true.

instance, or nil if not enabled

Parameters:

  • enable (TrueClass, FalseClass) (defaults to: false)

    flag to enable copy-paste functionality

Yields:

  • (block)

    optional block to initialize the copy-paste instance

Returns:

  • (CopyPaste, nil)

    the existing or newly created copy-paste



603
604
605
606
607
608
609
610
611
612
613
# File 'lib/utils/config_file.rb', line 603

def copy_paste(enable = false, &block)
  if @copy_paste
    @copy_paste
  else
    if block
      @copy_paste = CopyPaste.new(&block)
    elsif enable
      @copy_paste = CopyPaste.new {}
    end
  end
end

#multiplexer_attach(session) ⇒ String

The multiplexer_attach method generates a command string for attaching to a session using either screen or tmux multiplexer.

Parameters:

  • session (String)

    the name or identifier of the session to attach to

Returns:

  • (String)

    a formatted command string ready for execution



534
535
536
537
538
539
540
541
# File 'lib/utils/config_file.rb', line 534

def multiplexer_attach(session)
  case @multiplexer
  when 'screen'
    'screen -DUR "%s"' % session
  when 'tmux'
    'tmux -u attach -d -t "%s"' % session
  end
end

#multiplexer_listString?

The multiplexer_list method returns the appropriate command string for listing sessions based on the current multiplexer type.

Returns:

  • (String, nil)

    the command string to list sessions for the configured multiplexer (‘screen -ls’ or ‘tmux ls’), or nil if no multiplexer is set



503
504
505
506
507
508
509
510
# File 'lib/utils/config_file.rb', line 503

def multiplexer_list
  case @multiplexer
  when 'screen'
    'screen -ls'
  when 'tmux'
    'tmux ls'
  end
end

#multiplexer_new(session) ⇒ String?

The multiplexer_new method generates a command string for creating a new session in the specified terminal multiplexer.

Parameters:

  • session (String)

    the name of the session to be created

Returns:

  • (String, nil)

    a command string for creating a new session in screen or tmux, or nil if the multiplexer type is not supported



519
520
521
522
523
524
525
526
# File 'lib/utils/config_file.rb', line 519

def multiplexer_new(session)
  case @multiplexer
  when 'screen'
    'false'
  when 'tmux'
    'tmux -u new -s "%s"' % session
  end
end

#terminal_multiplexer=(terminal_multiplexer) ⇒ Object

The terminal_multiplexer= method sets the terminal multiplexer type for the editor.

This method assigns the specified terminal multiplexer to the editor configuration, validating that it is either ‘screen’ or ‘tmux’. It converts the input to a string and ensures it matches one of the supported multiplexer types.

be configured

Parameters:

  • terminal_multiplexer (Symbol)

    the terminal multiplexer type to



492
493
494
495
496
# File 'lib/utils/config_file.rb', line 492

def terminal_multiplexer=(terminal_multiplexer)
  @multiplexer = terminal_multiplexer.to_s
  @multiplexer =~ /\A(screen|tmux)\z/ or
    fail "invalid terminal_multiplexer #{terminal_multiplexer.inspect} was configured"
end