parent
42086bee57
commit
abdf894edf
1 changed files with 8 additions and 4 deletions
|
@ -11,14 +11,18 @@ RESET = "\x1b[m"
|
|||
|
||||
split = ARGV.delete('-v')
|
||||
|
||||
if ARGV.empty?
|
||||
def usage
|
||||
puts "usage: #$0 [-v] FILENAME[:LINENO][:IGNORED]"
|
||||
exit 1
|
||||
end
|
||||
|
||||
file, center = ARGV.first.split(':')
|
||||
usage if ARGV.empty?
|
||||
|
||||
unless File.readable? file
|
||||
file, center = ARGV.first.split(':')
|
||||
usage unless file
|
||||
|
||||
path = File.expand_path(file)
|
||||
unless File.readable? path
|
||||
puts "File not found: #{file}"
|
||||
exit 1
|
||||
end
|
||||
|
@ -29,7 +33,7 @@ height /= 2 if split
|
|||
height -= 2 # preview border
|
||||
offset = [1, center - height / 3].max
|
||||
|
||||
IO.popen(['sh', '-c', COMMAND.gsub('{}', Shellwords.shellescape(file))]) do |io|
|
||||
IO.popen(['sh', '-c', COMMAND.gsub('{}', Shellwords.shellescape(path))]) do |io|
|
||||
io.each_line.drop(offset - 1).take(height).each_with_index do |line, lno|
|
||||
if lno + offset == center
|
||||
puts REVERSE + line.chomp.gsub(ANSI) { |m| m + REVERSE } + RESET
|
||||
|
|
Loading…
Add table
Reference in a new issue