【发布时间】:2012-01-19 07:25:10
【问题描述】:
我正在使用 Ruby 制作命令行工具。它会在屏幕上打印很多文本。目前,我正在使用 shell 管道 (may_app | more) 来执行此操作。但我认为最好有一个默认寻呼机。
就像你在执行 git log 时看到的一样。可以使用git --nopager log 禁用寻呼机。
我在谷歌上做了很多工作,找到了一颗宝石:hirb,但这似乎有点矫枉过正。
经过多次尝试,我目前正在使用 shell 包装器:
#!/bin/bash
# xray.rb is the core script
# doing the main logic and will
# output many rows of text on
# screen
XRAY=$HOME/fdev-xray/xray.rb
if [ "--nopager" == "$1" ]; then
shift
$XRAY $*
else
$XRAY $* | more
fi
它有效。但是有没有更好的方法?
【问题讨论】:
标签: ruby command-line pager