Sha256: 94cf87605f1076adf1b33fea719f032fc34ec4ec097852406368ddaec662ecfe

Contents?: true

Size: 685 Bytes

Versions: 2

Compression:

Stored size: 685 Bytes

Contents

require 'fileutils'

class Nib::History::Config
  PATH = '/tmp/nib/config'.freeze

  attr_reader :type, :history_command, :host_path

  def initialize(type, history_command)
    @type = type
    @history_command = history_command
    @host_path = "#{ENV['HOME']}/.#{type}"

    FileUtils.mkdir_p PATH
  end

  def container_path
    config_file.path
  end

  private

  def config
    if File.exist?(host_path)
      File.read(host_path)
    else
      Nib.load_default_config(:shell, type)
    end
  end

  def config_file
    @config_file ||= File.open("#{PATH}/#{type}", 'w+') do |file|
      file.write(config)
      file.write("#{history_command}\n")
      file
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nib-2.1.1 lib/nib/history/config.rb
nib-2.1.0 lib/nib/history/config.rb