[fzf#vim#with_preview] Expand relative path

Close #261
This commit is contained in:
Junegunn Choi 2016-12-08 13:30:06 +09:00
parent 42086bee57
commit abdf894edf
No known key found for this signature in database
GPG key ID: 254BC280FEF9C627

View file

@ -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