Last active
August 29, 2015 13:56
-
-
Save mdippery/9285087 to your computer and use it in GitHub Desktop.
Like `brew cat`, but automatically displays the output in a pager. Drop it in a directory on your $PATH and chmod +x it. Now you can run `brew less <formula>`!
This file contains 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
# Thanks to <http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby> | |
def run_pager | |
return if PLATFORM =~ /win32/ | |
return unless STDOUT.tty? | |
read, write = IO.pipe | |
unless Kernel.fork | |
STDOUT.reopen(write) | |
STDERR.reopen(write) if STDERR.tty? | |
read.close | |
write.close | |
return | |
end | |
STDIN.reopen(read) | |
read.close | |
write.close | |
Kernel.select [STDIN] | |
pager = ENV['HOMEBREW_PAGER'] || ENV['PAGER'] || 'less' | |
exec pager rescue exec "/bin/sh", "-c", pager | |
end | |
raise FormulaUnspecifiedError if ARGV.named.empty? | |
run_pager | |
exec "cat", ARGV.formulae.first.path, *ARGV.options_only |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment