#!/usr/bin/env ruby # frozen_string_literal: true # encoding=utf-8 def append_to_bash_history(line) # Get the bash history file from the HISTFILE environment variable or default to ~/.bash_history histfile = ENV['HISTFILE'] || File.expand_path("~/.bash_history") if File.exist?(histfile) # Open the file in append mode and write the line File.open(histfile, 'a') do |file| file.puts line end puts "Appended to bash history: #{line}" else puts "Bash history file does not exist." end end return if $PROGRAM_NAME != __FILE__ # Example usage: append_to_bash_history('echo "Hello from Ruby!"') # require 'minitest/autorun' # require_relative 'colorize' # class TestMarkdownTableFormatter < Minitest::Test # def setup # @lines = [ # '| Header 1 | Header 2 | Header 3 |', # '|----------|:--------:|---------:|', # '| Row 1 Col 1 | Row 1 Col 2 | Row 1 Col 3 |', # '| Row 2 Col 1 | Row 2 Col 2 | Row 2 Col 3 |' # ] # @column_count = 3 # end # def test_format_table # result = MarkdownTableFormatter.format_table( # column_count: @column_count, lines: @lines # ) # expected = [ # '| Header 1 | Header 2 | Header 3 |', # '| ----------- | ----------- | ----------- |', # '| Row 1 Col 1 | Row 1 Col 2 | Row 1 Col 3 |', # '| Row 2 Col 1 | Row 2 Col 2 | Row 2 Col 3 |' # ] # assert_equal expected, result # end # def test_format_table_with_decoration # decorate = { header_row: :upcase, row: %i[downcase upcase] } # result = MarkdownTableFormatter.format_table( # column_count: @column_count, # decorate: decorate, # lines: @lines # ) # expected = [ # '| HEADER 1 | HEADER 2 | HEADER 3 |', # '| ----------- | ----------- | ----------- |', # '| ROW 1 COL 1 | ROW 1 COL 2 | ROW 1 COL 3 |', # '| row 2 col 1 | row 2 col 2 | row 2 col 3 |' # ] # assert_equal expected, result # end # def test_format_table_with_empty_lines # lines_with_empty = [ # '| Header 1 | Header 2 | Header 3 |', # '|----------|:--------:|---------:|', # '| Row 1 Col 1 | Row 1 Col 2 | Row 1 Col 3 |', # '', # '| Row 2 Col 1 | Row 2 Col 2 | Row 2 Col 3 |' # ] # result = MarkdownTableFormatter.format_table( # lines: lines_with_empty, # column_count: @column_count # ) # expected = [ # '| Header 1 | Header 2 | Header 3 |', # '| ----------- | ----------- | ----------- |', # '| Row 1 Col 1 | Row 1 Col 2 | Row 1 Col 3 |', # '', # '| Row 2 Col 1 | Row 2 Col 2 | Row 2 Col 3 |' # ] # assert_equal expected, result # end # def test_alignment_detection # lines_with_alignment = [ # '| Header 1 | Header 2 | Header 3 |', # '|:-------- |:--------:| --------:|' # ] # result = MarkdownTableFormatter.format_table( # lines: lines_with_alignment, # column_count: @column_count # ) # expected = [ # '| Header 1 | Header 2 | Header 3 |', # '| --------- | ---------- | --------- |' # ] # assert_equal expected, result[0..1] # only checking the header and separator # end # end # class TestFormatTable < Minitest::Test # def test_basic_formatting # lines = [ # '| Species| Genus| Family', # '|-|-|-', # '| Pongo tapanuliensis| Pongo| Hominidae', # '| | Histiophryne| Antennariidae' # ] # column_count = 3 # expected = [ # '| Species | Genus | Family |', # '| ------------------- | ------------ | ------------- |', # '| Pongo tapanuliensis | Pongo | Hominidae |', # '| | Histiophryne | Antennariidae |' # ] # assert_equal expected, MarkdownTableFormatter.format_table( # lines: lines, # column_count: column_count # ) # end # def test_missing_column_count # lines = [ # '| A| B| C', # '| 1| 2', # '| X' # ] # column_count = 3 # expected = [ # '| A | B | C |', # '| 1 | 2 | |', # '| X | | |' # ] # assert_equal expected, MarkdownTableFormatter.format_table( # lines: lines, # column_count: column_count # ) # end # # def test_extra_column_count # # lines = [ # # "| A| B| C| D", # # "| 1| 2| 3| 4| 5" # # ] # # column_count = 3 # # expected = [ # # "| A | B | C ", # # "| 1 | 2 | 3 " # # ] # # assert_equal expected, MarkdownTableFormatter.format_table(lines, column_count) # # end # def test_empty_input # assert_equal [], MarkdownTableFormatter.format_table( # lines: [], # column_count: 3 # ) # end # def test_single_column # lines = [ # '| A', # '| Longer text', # '| Short' # ] # column_count = 1 # expected = [ # '| A |', # '| Longer text |', # '| Short |' # ] # assert_equal expected, MarkdownTableFormatter.format_table( # lines: lines, # column_count: column_count # ) # end # def test_no_pipe_at_end # lines = [ # '| A| B| C', # '| 1| 2| 3' # ] # column_count = 3 # expected = [ # '| A | B | C |', # '| 1 | 2 | 3 |' # ] # assert_equal expected, MarkdownTableFormatter.format_table( # lines: lines, # column_count: column_count # ) # end # end # class TestFormatTable2 < Minitest::Test # def test_basic_formatting # lines = [ # '| Name | Age | City |', # '| John | 30 | New York |', # '| Jane | 25 | Los Angeles |' # ] # expected_output = [ # '| Name | Age | City |', # '| John | 30 | New York |', # '| Jane | 25 | Los Angeles |' # ] # assert_equal expected_output, MarkdownTableFormatter.format_table( # lines: lines, # column_count: 3 # ) # end # def test_incomplete_column_count # lines = [ # '| Name | Age |', # '| John | 30 | New York |', # '| Jane | 25 | Los Angeles |' # ] # expected_output = [ # '| Name | Age | |', # '| John | 30 | New York |', # '| Jane | 25 | Los Angeles |' # ] # assert_equal expected_output, MarkdownTableFormatter.format_table( # lines: lines, # column_count: 3 # ) # end # def test_extra_column_count # lines = [ # '| Name | Age | City | Country |', # '| John | 30 | New York | USA |', # '| Jane | 25 | Los Angeles | USA |' # ] # expected_output = [ # '| Name | Age | City | Country |', # '| John | 30 | New York | USA |', # '| Jane | 25 | Los Angeles | USA |' # ] # assert_equal expected_output, MarkdownTableFormatter.format_table( # lines: lines, # column_count: 4 # ) # end # def test_varied_column_lengths # lines = [ # '| Name | Age |', # '| Johnathan | 30 | New York |', # '| Jane | 25 | LA |' # ] # expected_output = [ # '| Name | Age | |', # '| Johnathan | 30 | New York |', # '| Jane | 25 | LA |' # ] # assert_equal expected_output, MarkdownTableFormatter.format_table( # lines: lines, # column_count: 3 # ) # end # def test_single_line # lines = ['| Name | Age | City |'] # expected_output = ['| Name | Age | City |'] # assert_equal expected_output, MarkdownTableFormatter.format_table( # lines: lines, # column_count: 3 # ) # end # def test_empty_lines # lines = [] # expected_output = [] # assert_equal expected_output, MarkdownTableFormatter.format_table( # lines: lines, # column_count: 3 # ) # end # def test_complete_rows # lines = [ # '| Name | Age |', # '| John | 30 |' # ] # expected_output = [ # '| Name | Age |', # '| John | 30 |' # ] # assert_equal expected_output, MarkdownTableFormatter.format_table( # lines: lines, # column_count: 3 # ) # end # end