Skip to content

Commit 8e89907

Browse files
committed
new config option: CHTSH_CURL_OPTIONS (fixes chubin#80)
1 parent 8d12aab commit 8e89907

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ QUERY_OPTIONS="style=native"
305305
Other cht.sh configuration parameters:
306306

307307
```
308+
CHTSH_CURL_OPTIONS="-A curl" # curl options used for cht.sh queries
308309
CHTSH_URL=https://cht.sh # URL of the cheat.sh server
309310
```
310311

share/cht.sh.txt

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,6 @@ if echo $KSH_VERSION | grep -q ' 93' && ! local foo 2>/dev/null; then
3939
alias local=typeset
4040
fi
4141

42-
# any better test not involving either OS matching or actual query?
43-
if [ `uname -s` = OpenBSD ] && [ -x /usr/bin/ftp ]; then
44-
curl() {
45-
local opt args="-o -"
46-
while getopts "b:s" opt; do
47-
case $opt in
48-
b) args="$args -c $OPTARG";;
49-
s) args="$args -M -V";;
50-
*) echo "internal error: unsupported cURL option '$opt'" >&2; exit 1;;
51-
esac
52-
done
53-
shift $(($OPTIND - 1))
54-
/usr/bin/ftp $args "$@"
55-
}
56-
fi
57-
5842
get_query_options()
5943
{
6044
local query="$*"
@@ -144,6 +128,31 @@ fi
144128

145129
[ -z "$CHTSH_URL" ] && CHTSH_URL=https://cht.sh
146130

131+
# any better test not involving either OS matching or actual query?
132+
if [ `uname -s` = OpenBSD ] && [ -x /usr/bin/ftp ]; then
133+
curl() {
134+
local opt args="-o -"
135+
while getopts "b:s" opt; do
136+
case $opt in
137+
b) args="$args -c $OPTARG";;
138+
s) args="$args -M -V";;
139+
*) echo "internal error: unsupported cURL option '$opt'" >&2; exit 1;;
140+
esac
141+
done
142+
shift $(($OPTIND - 1))
143+
/usr/bin/ftp $args "$@"
144+
}
145+
else
146+
command -v curl >/dev/null || { echo 'DEPENDENCY: install "curl" to use cht.sh' >&2; exit 1; }
147+
_CURL=$(command -v curl)
148+
if [ x"$CHTSH_CURL_OPTIONS" != x ]; then
149+
curl() {
150+
$_CURL ${CHTSH_CURL_OPTIONS} "$@"
151+
}
152+
fi
153+
fi
154+
155+
147156
if [ "$1" = --read ]; then
148157
read -r a || a=exit
149158
printf "%s\n" "$a"
@@ -200,7 +209,6 @@ if [ "$is_macos" != yes ]; then
200209
command -v xsel >/dev/null || echo 'DEPENDENCY: please install "xsel" for "copy"' >&2
201210
fi
202211
command -v rlwrap >/dev/null || { echo 'DEPENDENCY: install "rlwrap" to use cht.sh in the shell mode' >&2; exit 1; }
203-
command -v curl >/dev/null || { echo 'DEPENDENCY: install "curl" to use cht.sh' >&2; exit 1; }
204212

205213
mkdir -p "$HOME/.cht.sh/"
206214
lines=$(tput lines)

0 commit comments

Comments
 (0)