<commit_before>require 'rubygems'
require 'bundler/setup'

require 'thor'
require 'fileutils'

require 'active_support'
require 'active_support/core_ext/string'

module Everything
  class Cli < Thor
    desc "new PIECE_NAME", "Create a new everything piece, in your current directory, with the given name, which must be in spinal-case."
    def new(piece_name)
      piece_path_to_create = piece_path(piece_name)
      Dir.mkdir(piece_path_to_create)

      content_file      = 'index.md'
      content_file_path = File.join(piece_path_to_create, content_file)
      FileUtils.touch(content_file_path)

      titleized_name = piece_name.gsub('-', ' ').titleize
      markdown_header = "# #{titleized_name}"

      File.open(content_file_path, 'w') do |f|
        f.puts markdown_header
        f.puts
        f.puts
        f.puts
      end

      metadata_file      = 'index.yaml'
      metadata_file_path = File.join(piece_path_to_create, metadata_file)
      FileUtils.touch(metadata_file_path)

      default_metadata = %{---
public: false}

      File.open(metadata_file_path, 'w') do |f|
        f.puts default_metadata
        f.puts
      end
    end

    desc "open_new PIECE_NAME", "Create a new everything piece, in your current directory, with the given name, which must be in spinal-case. And then open it in gvim."
    def open_new(piece_name)
      new(piece_name)
      open(piece_name)
    end

    desc "open PIECE_NAME", "Open the piece, in your current directory, in gvim."
    def open(piece_name)
      path = piece_path(piece_name)
      fork { `gvim -O #{path}/index.{md,yaml}` }
    end

  private

    def piece_path(piece_name)
      current_dir = Dir.pwd
      File.join(current_dir, piece_name)
    end
  end
end
<commit_msg>Map some shortcuts for the cli actions<commit_after>require 'rubygems'
require 'bundler/setup'

require 'thor'
require 'fileutils'

require 'active_support'
require 'active_support/core_ext/string'

module Everything
  class Cli < Thor
    desc "new PIECE_NAME", "Create a new everything piece, in your current directory, with the given name, which must be in spinal-case."
    def new(piece_name)
      piece_path_to_create = piece_path(piece_name)
      Dir.mkdir(piece_path_to_create)

      content_file      = 'index.md'
      content_file_path = File.join(piece_path_to_create, content_file)
      FileUtils.touch(content_file_path)

      titleized_name = piece_name.gsub('-', ' ').titleize
      markdown_header = "# #{titleized_name}"

      File.open(content_file_path, 'w') do |f|
        f.puts markdown_header
        f.puts
        f.puts
        f.puts
      end

      metadata_file      = 'index.yaml'
      metadata_file_path = File.join(piece_path_to_create, metadata_file)
      FileUtils.touch(metadata_file_path)

      default_metadata = %{---
public: false}

      File.open(metadata_file_path, 'w') do |f|
        f.puts default_metadata
        f.puts
      end
    end

    map n: :new

    desc "open_new PIECE_NAME", "Create a new everything piece, in your current directory, with the given name, which must be in spinal-case. And then open it in gvim."
    def open_new(piece_name)
      new(piece_name)
      open(piece_name)
    end
    map on: :open_new

    desc "open PIECE_NAME", "Open the piece, in your current directory, in gvim."
    def open(piece_name)
      path = piece_path(piece_name)
      fork { `gvim -O #{path}/index.{md,yaml}` }
    end
    map o: :open

  private

    def piece_path(piece_name)
      current_dir = Dir.pwd
      File.join(current_dir, piece_name)
    end
  end
end

{'fraction_non_alphanumeric': 0.0908331011423795, 'fraction_numerical': 0.0, 'mean_word_length': 2.9234972677595628, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5792516', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1171, 'n_words': 305}