Class | SSHMenu::History |
In: |
lib/sshmenu.rb
(Git)
|
Parent: | Object |
SSHMenu::History manages the history of hostnames entered in the quick- connect entry box.
Constructor, expects a single argument: the config object
# File lib/sshmenu.rb, line 1747 def initialize(config) @hist_file = config.home_dir + '.sshmenu_history' @timestamp = nil load_history end
Adds a line to the start of the history list and then saves the list to the history file
# File lib/sshmenu.rb, line 1773 def add_line(line) @history = [ line, @history.find_all { |l| l != line } ].flatten fh = File.new(@hist_file, 'w') @history.each { |l| fh.puts(l) } fh.close @timestamp = File.mtime(@hist_file) end
Iterator which yields a list of history strings which match the supplied text string
# File lib/sshmenu.rb, line 1784 def each_match(text, prefix_only = false) pattern = Regexp.quote(text) @history.each do |line| yield(line) if line =~ /^#{pattern}/i # match at start end if not prefix_only @history.each do |line| next if line =~ /^#{pattern}/i yield(line) if line =~ /#{pattern}/i # match, but not at start end end end
Reloads the history file if it has been modified
# File lib/sshmenu.rb, line 1765 def freshen return unless File.exists?(@hist_file) load_history if File.mtime(@hist_file) != @timestamp end