Skip to content

Commit 4d080ee

Browse files
committed
Add colorize command
1 parent 762c38c commit 4d080ee

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ ruby -run -e touch -- [OPTION] FILE
3333
ruby -run -e wait_writable -- [OPTION] FILE
3434
ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION]
3535
ruby -run -e httpd -- [OPTION] [DocumentRoot]
36+
ruby -run -e colorize -- FILE
3637
ruby -run -e help [COMMAND]
3738
```
3839

lib/un.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# ruby -run -e wait_writable -- [OPTION] FILE
2424
# ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION]
2525
# ruby -run -e httpd -- [OPTION] [DocumentRoot]
26+
# ruby -run -e colorize -- FILE
2627
# ruby -run -e help [COMMAND]
2728

2829
require "fileutils"
@@ -354,6 +355,25 @@ def httpd
354355
end
355356
end
356357

358+
##
359+
# Colorize ruby code.
360+
#
361+
# ruby -run -e colorize -- FILE
362+
#
363+
364+
def colorize
365+
begin
366+
require "irb/color"
367+
rescue LoadError
368+
raise "colorize requires irb 1.1.0 or later"
369+
end
370+
setup do |argv, |
371+
argv.each do |file|
372+
puts IRB::Color.colorize_code File.read(file)
373+
end
374+
end
375+
end
376+
357377
##
358378
# Display help message.
359379
#

0 commit comments

Comments
 (0)