<commit_before>module Trith; module Shell
  ##
  # Supporting code for the `3sh` shell's input line history.
  module History
    FILE = File.join(ENV['TRITH_HOME'] || '~', '.trith', '3sh.log').freeze unless const_defined?(:FILE)
    MODE = 0640

    ##
    # Loads the shell history from the `~/.trith/3sh.log` file.
    #
    # @return [void]
    def self.load!
      unless (lines = File.readlines(File.expand_path(FILE)) rescue []).empty?
        Readline::HISTORY.push(*lines.map { |line| line.chomp.strip })
        @load_count = Readline::HISTORY.size
      end
    end

    ##
    # Dumps the shell history to the `~/.trith/3sh.log` file.
    #
    # @return [void]
    def self.dump!
      File.open(File.expand_path(FILE), 'a', MODE) do |file|
        lines = Readline::HISTORY.to_a
        lines.slice!(0, @load_count) if @load_count
        file.puts(lines)
      end
    end

    ##
    # Returns `true` if the shell history is empty.
    #
    # @return [Boolean]
    def self.empty?
      Readline::HISTORY.empty?
    end

    ##
    # Returns the number of lines in the shell history.
    #
    # @return [Integer]
    def self.size
      Readline::HISTORY.size
    end
<commit_msg>Ensured that the ~/.trith directory is automatically created when first needed.<commit_after>module Trith; module Shell
  ##
  # Supporting code for the `3sh` shell's input line history.
  module History
    FILE = File.join(ENV['TRITH_HOME'] || '~', '.trith', '3sh.log').freeze unless const_defined?(:FILE)
    MODE = 0640

    ##
    # Loads the shell history from the `~/.trith/3sh.log` file.
    #
    # @return [void]
    def self.load!
      unless (lines = File.readlines(File.expand_path(FILE)) rescue []).empty?
        Readline::HISTORY.push(*lines.map { |line| line.chomp.strip })
        @load_count = Readline::HISTORY.size
      end
    end

    ##
    # Dumps the shell history to the `~/.trith/3sh.log` file.
    #
    # @return [void]
    def self.dump!
      begin
        require 'fileutils' unless defined?(FileUtils)
        FileUtils.mkdir_p(File.expand_path(File.dirname(FILE)), :mode => 0750)
        File.open(File.expand_path(FILE), 'a+', MODE) do |file|
          lines = Readline::HISTORY.to_a
          lines.slice!(0, @load_count) if @load_count
          file.puts(lines)
        end
      rescue Errno::ENOENT # ignore 'No such file or directory' errors
      rescue Errno::EACCES # ignore 'Permission denied' errors
      end
    end

    ##
    # Returns `true` if the shell history is empty.
    #
    # @return [Boolean]
    def self.empty?
      Readline::HISTORY.empty?
    end

    ##
    # Returns the number of lines in the shell history.
    #
    # @return [Integer]
    def self.size
      Readline::HISTORY.size
    end

{'fraction_non_alphanumeric': 0.12848353239232718, 'fraction_numerical': 0.007962359753890699, 'mean_word_length': 2.4378109452736316, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5365044', 'n_tokens_mistral': 937, 'n_tokens_neox': 915, 'n_words': 238}