Skip to content

Instantly share code, notes, and snippets.

@mdippery
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdippery/9285087 to your computer and use it in GitHub Desktop.
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>`!
# 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