mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-07 21:24:40 +08:00
@@ -11,14 +11,18 @@ RESET = "\x1b[m"
|
|||||||
|
|
||||||
split = ARGV.delete('-v')
|
split = ARGV.delete('-v')
|
||||||
|
|
||||||
if ARGV.empty?
|
def usage
|
||||||
puts "usage: #$0 [-v] FILENAME[:LINENO][:IGNORED]"
|
puts "usage: #$0 [-v] FILENAME[:LINENO][:IGNORED]"
|
||||||
exit 1
|
exit 1
|
||||||
end
|
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}"
|
puts "File not found: #{file}"
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
@@ -29,7 +33,7 @@ height /= 2 if split
|
|||||||
height -= 2 # preview border
|
height -= 2 # preview border
|
||||||
offset = [1, center - height / 3].max
|
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|
|
io.each_line.drop(offset - 1).take(height).each_with_index do |line, lno|
|
||||||
if lno + offset == center
|
if lno + offset == center
|
||||||
puts REVERSE + line.chomp.gsub(ANSI) { |m| m + REVERSE } + RESET
|
puts REVERSE + line.chomp.gsub(ANSI) { |m| m + REVERSE } + RESET
|
||||||
|
|||||||
Reference in New Issue
Block a user