From 8e89907c28fa6d3904c759afe5eef941209cafdb Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Sat, 18 Aug 2018 13:42:39 +0000 Subject: [PATCH] new config option: CHTSH_CURL_OPTIONS (fixes #80) --- README.md | 1 + share/cht.sh.txt | 42 +++++++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 6a521dd..87a6222 100644 --- a/README.md +++ b/README.md @@ -305,6 +305,7 @@ QUERY_OPTIONS="style=native" Other cht.sh configuration parameters: ``` +CHTSH_CURL_OPTIONS="-A curl" # curl options used for cht.sh queries CHTSH_URL=https://cht.sh # URL of the cheat.sh server ``` diff --git a/share/cht.sh.txt b/share/cht.sh.txt index ab982fd..d165262 100755 --- a/share/cht.sh.txt +++ b/share/cht.sh.txt @@ -39,22 +39,6 @@ if echo $KSH_VERSION | grep -q ' 93' && ! local foo 2>/dev/null; then alias local=typeset fi -# any better test not involving either OS matching or actual query? -if [ `uname -s` = OpenBSD ] && [ -x /usr/bin/ftp ]; then - curl() { - local opt args="-o -" - while getopts "b:s" opt; do - case $opt in - b) args="$args -c $OPTARG";; - s) args="$args -M -V";; - *) echo "internal error: unsupported cURL option '$opt'" >&2; exit 1;; - esac - done - shift $(($OPTIND - 1)) - /usr/bin/ftp $args "$@" - } -fi - get_query_options() { local query="$*" @@ -144,6 +128,31 @@ fi [ -z "$CHTSH_URL" ] && CHTSH_URL=https://cht.sh +# any better test not involving either OS matching or actual query? +if [ `uname -s` = OpenBSD ] && [ -x /usr/bin/ftp ]; then + curl() { + local opt args="-o -" + while getopts "b:s" opt; do + case $opt in + b) args="$args -c $OPTARG";; + s) args="$args -M -V";; + *) echo "internal error: unsupported cURL option '$opt'" >&2; exit 1;; + esac + done + shift $(($OPTIND - 1)) + /usr/bin/ftp $args "$@" + } +else + command -v curl >/dev/null || { echo 'DEPENDENCY: install "curl" to use cht.sh' >&2; exit 1; } + _CURL=$(command -v curl) + if [ x"$CHTSH_CURL_OPTIONS" != x ]; then + curl() { + $_CURL ${CHTSH_CURL_OPTIONS} "$@" + } + fi +fi + + if [ "$1" = --read ]; then read -r a || a=exit printf "%s\n" "$a" @@ -200,7 +209,6 @@ if [ "$is_macos" != yes ]; then command -v xsel >/dev/null || echo 'DEPENDENCY: please install "xsel" for "copy"' >&2 fi command -v rlwrap >/dev/null || { echo 'DEPENDENCY: install "rlwrap" to use cht.sh in the shell mode' >&2; exit 1; } -command -v curl >/dev/null || { echo 'DEPENDENCY: install "curl" to use cht.sh' >&2; exit 1; } mkdir -p "$HOME/.cht.sh/" lines=$(tput lines)