Top Level Namespace

Defined Under Namespace

Modules: Github

Instance Method Summary collapse

Instance Method Details

#run_pagerObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hubmaster.rb', line 13

def run_pager
  return if RUBY_PLATFORM =~ /win32/
  return unless STDOUT.tty?
  
  read, write = IO.pipe
  
  unless Kernel.fork # Child process
    STDOUT.reopen(write)
    STDERR.reopen(write) if STDERR.tty?
    read.close
    write.close
    return
  end
  
  STDIN.reopen(read)
  read.close
  write.close

  ENV['LESS'] = 'FSRX' # Don't page if the input is short enough

  Kernel.select [STDIN] # Wait until we have input before we start the pager
  pager = ENV['PAGER'] || 'less'
  exec pager rescue exec "/bin/sh", "-c", pager
end