-
-
Save Phlogistique/2023440 to your computer and use it in GitHub Desktop.
Open vim at specified line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby1.9.1 | |
require 'shellwords' | |
files = [] | |
opts = [] | |
ARGV.each do |f| | |
if File.exists? f | |
files << [f, nil] | |
elsif f =~ /(.+):(.+?):?$/ | |
if File.exists? $1 | |
files << [$1, $2] | |
else | |
$stderr.puts %(WARNING: file #$1 does not exist, treating "#{f}" as an option) | |
opts << f | |
end | |
else | |
opts << f | |
end | |
end | |
cmd = ["vim", *opts] | |
if files.empty? | |
elsif files.length == 1 | |
file = files.first | |
cmd << file[0] | |
cmd << "+" + file[1] if file[1] | |
else | |
plus = [] | |
files.each do |file| | |
plus << "tabe #{file[0].shellescape}" | |
plus << file[1] if file[1] | |
end | |
cmd << "+" + plus.join(' | ') << "+tabr|q" | |
end | |
exec *cmd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment