Skip to content

Commit

Permalink
add ls command
Browse files Browse the repository at this point in the history
  • Loading branch information
dorianmariecom committed Sep 7, 2024
1 parent a4a3d1b commit fba07e6
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions lib/dorian/bin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ def run
arguments.delete("eval")
@command = :eval
command_eval
when :ls
arguments.delete("ls")
@command = :ls
command_ls
else
arguments.delete("read")
@command = :read
Expand Down Expand Up @@ -282,6 +286,22 @@ def command_dir
puts "." if self?
end

def command_ls
puts(
Git
.open(".")
.ls_files
.map(&:first)
.map { |path| path.split("/").first }
.reject { |path| path.start_with?(".") }
.select { |path| match_filetypes?(path) }
.sort
.uniq
)

puts "." if self?
end

def command_submodules
puts(
File
Expand Down Expand Up @@ -914,6 +934,79 @@ def encoder
Tiktoken.encoding_for_model("gpt-4o")
end

def match_filetypes?(path)
return true unless arguments.any?
return true unless arguments.intersect?(["rb", "ruby"])

ruby_extensions = %w[
.rb
.arb
.axlsx
.builder
.fcgi
.gemfile
.gemspec
.god
.jb
.jbuilder
.mspec
.opal
.pluginspec
.podspec
.rabl
.rake
.rbuild
.rbw
.rbx
.ru
.ruby
.schema
.spec
.thor
.watchr
]

ruby_filenames = %w[
.irbrc
.pryrc
.simplecov
Appraisals
Berksfile
Brewfile
Buildfile
Capfile
Cheffile
Dangerfile
Deliverfile
Fastfile
Gemfile
Guardfile
Jarfile
Mavenfile
Podfile
Puppetfile
Rakefile
rakefile
Schemafile
Snapfile
Steepfile
Thorfile
Vagabondfile
Vagrantfile
buildfile
]

return false if Dir.exist?(path)
return true if ruby_filenames.include?(path)
return true if ruby_extensions.include?(File.extname(path))
return false unless File.exist?(path)

first_line =
File.open(path, &:gets).to_s.encode("UTF-8", invalid: :replace)

/\A#!.*ruby\z/.match?(first_line)
end

def evaluates(
ruby: @ruby,
it: nil,
Expand Down

0 comments on commit fba07e6

Please sign in to comment.