module GreenHat::Settings

Helper for all things user environment / settings / history

Public Class Methods

assume_json?() click to toggle source
# File lib/greenhat/settings.rb, line 18
def self.assume_json?
  settings.assume_json
end
cmd_add(line) click to toggle source
# File lib/greenhat/settings.rb, line 88
def self.cmd_add(line)
  File.write(cmd_file, line, File.size(cmd_file), mode: 'a')
end
cmd_file() click to toggle source
# File lib/greenhat/settings.rb, line 76
def self.cmd_file
  "#{dir}/cmd_history"
end
cmd_history() click to toggle source

Command History

# File lib/greenhat/settings.rb, line 72
def self.cmd_history
  "#{dir}/cmd_history"
end
cmd_history_clean() click to toggle source
# File lib/greenhat/settings.rb, line 80
def self.cmd_history_clean
  File.read(cmd_file).split("\n")
end
cmd_history_clear() click to toggle source
# File lib/greenhat/settings.rb, line 84
def self.cmd_history_clear
  File.write(cmd_file, "\n")
end
color?() click to toggle source

Allow for future disabling of color output

# File lib/greenhat/settings.rb, line 23
def self.color?
  settings.color
end
default_log_flags(flags, skip_flags) click to toggle source

Set any Log Arguments that weren't set otherwise | Conditional assign applied on bool rubocop:disable Style/GuardClause

# File lib/greenhat/settings.rb, line 42
def self.default_log_flags(flags, skip_flags)
  flags[:round] = settings.round if !(skip_flags.include?(:round) || flags.key?(:round)) && settings.round

  flags[:page] = settings.page if !(skip_flags.include?(:page) || flags.key?(:page)) && settings.page

  flags[:truncate] = settings.truncate unless skip_flags.include?(:truncate) || flags.key?(:truncate)

  # Fuzzy File Match
  unless skip_flags.include?(:fuzzy_file_match) || flags.key?(:fuzzy_file_match)
    flags[:fuzzy_file_match] = settings.fuzzy_file_match
  end
end
dir() click to toggle source
# File lib/greenhat/settings.rb, line 66
def self.dir
  "#{ENV['HOME']}/.greenhat"
end
history_file() click to toggle source

File Load History

# File lib/greenhat/settings.rb, line 95
def self.history_file
  "#{dir}/file_history"
end
settings() click to toggle source
# File lib/greenhat/settings.rb, line 5
def self.settings
  @settings ||= {
    history: [],
    assume_json: true,
    fuzzy_file_match: true,

    # round: [2],
    # page: [:true] Automatic,
    truncate: TTY::Screen.width * 4,
    color: true
  }
end
settings_file() click to toggle source
# File lib/greenhat/settings.rb, line 36
def self.settings_file
  "#{dir}/settings.json"
end
settings_load() click to toggle source

Load User Settings and drop them into settings

# File lib/greenhat/settings.rb, line 28
def self.settings_load
  return true unless File.exist?(settings_file)

  Oj.load(File.read(settings_file)).each do |key, value|
    settings[key] = value
  end
end
start() click to toggle source

rubocop:enable Style/GuardClause

# File lib/greenhat/settings.rb, line 56
def self.start
  Dir.mkdir dir unless Dir.exist? dir

  # Load User Settings
  settings_load

  # CMD History Loading / Tracking
  File.write(cmd_file, "\n") unless File.exist? cmd_file
end