-
-
Save sinisterchipmunk/925094 to your computer and use it in GitHub Desktop.
Very simple script to display a specified line in a file, plus the line immediately preceding and following it. I whipped this up as a quick solution to manually following a particularly vague stack trace from Jax (github.com/sinisterchipmunk/jax).
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 ruby | |
def fail(msg) | |
puts msg | |
puts | |
exit | |
end | |
fail "Usage: line [filename] [lineno]" if !ARGV[0] || !ARGV[1] || !File.file?(ARGV[0]) | |
lines = File.read(ARGV[0]).lines.to_a | |
lineno = ARGV[1].to_i - 1 | |
fail "There are only #{lines.length} lines in the file" if lineno >= lines.length | |
print " " | |
puts(lineno <= 0 ? "<bof>" : lines[lineno-1]) | |
print "> " | |
puts lines[lineno] | |
print " " | |
puts(lineno >= lines.length-1 ? "<eof>" : lines[lineno+1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment