Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also use pager for normal queries (but skip paging when output is not to a terminal) #299

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 17 additions & 17 deletions share/cht.sh.txt
Expand Up @@ -478,6 +478,21 @@ elif [ x"$1" = x--mode ]; then
exit "$?"
fi

mkdir -p "$CHTSH_HOME/"
lines=''; [ -t 1 ] && lines=$(tput lines)

if command -v less >/dev/null; then
defpager="less -R"
elif command -v more >/dev/null; then
defpager="more"
else
defpager="cat"
fi

TMP1=$(mktemp /tmp/cht.sh.XXXXXXXXXXXXX)
trap 'rm -f $TMP1 $TMP2' EXIT
trap 'true' INT

prompt="cht.sh"
opts=""
input=""
Expand All @@ -491,7 +506,7 @@ done
query=$(echo "$input" | sed 's@ *$@@; s@^ *@@; s@ @/@; s@ @+@g')

if [ "$shell_mode" != yes ]; then
curl -s "${CHTSH_URL}"/"$(get_query_options "$query")"
do_query "$query"
exit 0
else
new_section="$1"
Expand All @@ -509,7 +524,7 @@ else
fi
if [ -n "$this_query" ] && [ -z "$CHEATSH_RESTART" ]; then
printf "$this_prompt$this_query\n"
curl -s "${CHTSH_URL}"/"$(get_query_options "$query")"
do_query "$query"
fi
fi

Expand All @@ -522,17 +537,6 @@ if [ "$is_macos" != yes ]; then
fi
command -v rlwrap >/dev/null || { echo 'DEPENDENCY: install "rlwrap" to use cht.sh in the shell mode' >&2; exit 1; }

mkdir -p "$CHTSH_HOME/"
lines=$(tput lines)

if command -v less >/dev/null; then
defpager="less -R"
elif command -v more >/dev/null; then
defpager="more"
else
defpager="cat"
fi

cmd_cd() {
if [ $# -eq 0 ]; then
section=""
Expand Down Expand Up @@ -757,10 +761,6 @@ cmd_version() {
rm -f "$TMP2" > /dev/null 2>&1
}

TMP1=$(mktemp /tmp/cht.sh.XXXXXXXXXXXXX)
trap 'rm -f $TMP1 $TMP2' EXIT
trap 'true' INT

if ! [ -e "$CHTSH_HOME/.hushlogin" ] && [ -z "$this_query" ]; then
echo "type 'help' for the cht.sh shell help"
fi
Expand Down