Tighten Main(), and use pager by default

The use of `[ -t 1 ]` won't check for interactivity, rather, whether
STDOUT is viable? If so, it might be best to check the `$-` variable
(I think that's it) for the `i` character, like the standard default
Debian `.bashrc` interactivity checks. Or, my preference, check the
`$PS1` is not empty, which works well in my own `.bashrc` file.

The `Main()` function was spread a bit too far, but is now more
appropriate; has no real impact, just clarify when reading.

Although the use of less(1) pager is enabled by default, it can be
disabled now with the `--no-pager|-P` flags.
pull/134/head
terminalforlife 4 years ago
parent 17454dc8f4
commit 66a38b7196

@ -16,11 +16,11 @@ Usage(){
-h, --help - Display this help information.
-D, --no-subdirs - Ignore the 'sheets/_*' subdirectories.
-N, --no-preview - Omit the preview of each triggered line.
-P, --no-pager - Do not use less(1) to page the output.
-S, --no-summary - Omit the summary before $Progrm exits.
-W, --no-whilelist - Do not use the whitelist file.
-c, --colorize - Provide color via esscape sequences.
-l, --limit [INT] - Override the limit of 80 columns.
-p, --pager - Use less(1) to page the output.
-w, --wl-file [FILE] - Use an alternative whitelist file.
Files to whitelist must be placed line-by-line; one path per line.
@ -55,8 +55,8 @@ while [ "$1" ]; do
if ! [[ $MaxCols =~ ^[0-9]+$ ]]; then
Err 1 'Invalid column maximum provided.'
fi ;;
--pager|-p)
DoLess='True' ;;
--no-pager|-P)
NoPager='True' ;;
--no-preview|-N)
NoPreview='True' ;;
--colorize|-c)
@ -94,20 +94,20 @@ case $PWD in
Err 1 "Not within the 'cheat.sheets/tests' directory." ;;
esac
Main(){
Dirs=(../sheets/*)
[ "$NoSubDirs" == 'True' ] || Dirs+=(../sheets/*/*)
# If the whitelist file exists, use it, unless whitelisting is disabled.
# Keeping this test outside of the loop to avoid unnecessary processing.
if [ "$NoWhiteList" != 'True' ] && [ -f "$WLFile" ]; then
# Read the whitelist file, line-by-line, generating an array thereof.
Whitelisted=()
while read; do
Whitelisted+=("../${REPLY#cheat.sheets/}")
done < "$WLFile"
fi
Dirs=(../sheets/*)
[ "$NoSubDirs" == 'True' ] || Dirs+=(../sheets/*/*)
# If the whitelist file exists, use it, unless whitelisting is disabled.
# Keeping this test outside of the loop to avoid unnecessary processing.
if [ "$NoWhiteList" != 'True' ] && [ -f "$WLFile" ]; then
# Read the whitelist file, line-by-line, generating an array thereof.
Whitelisted=()
while read; do
Whitelisted+=("../${REPLY#cheat.sheets/}")
done < "$WLFile"
fi
Main(){
for File in "${Dirs[@]}"; {
[ -f "$File" ] || continue
@ -172,7 +172,7 @@ Main(){
fi
}
if [ "$DoLess" == 'True' ]; then
if [ -t 1 -a "$NoPager" != 'True' ]; then
# Redirecting STDERR to address less(1) bug causing summary to display
# where it shouldn't; only seems to happen when colorization is enabled.
Main 2>&1 | less -r

Loading…
Cancel
Save