Skip to content

Commit 8d12aab

Browse files
committed
configurable cheat.sh server in the cht.sh client (chubin#98)
1 parent c7a39d0 commit 8d12aab

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ QUERY_OPTIONS="style=native"
302302

303303
(`curl cht.sh/:styles-demo` to see all supported styles).
304304

305+
Other cht.sh configuration parameters:
306+
307+
```
308+
CHTSH_URL=https://cht.sh # URL of the cheat.sh server
309+
```
305310

306311
### Tab completion
307312

share/cht.sh.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ do_query()
7171
{
7272
local query="$*"
7373
local b_opts=
74-
local uri="https://cht.sh/\"\$(get_query_options $query)\""
74+
local uri="${CHTSH_URL}/\"\$(get_query_options $query)\""
7575

7676
if [ -e "$HOME/.cht.sh/id" ]; then
7777
b_opts="-b \"\$HOME/.cht.sh/id\""
@@ -105,7 +105,7 @@ prepare_query()
105105

106106
get_list_of_sections()
107107
{
108-
curl -s https://cht.sh/:list | grep -v '/.*/' | grep '/$' | xargs
108+
curl -s "${CHTSH_URL}"/:list | grep -v '/.*/' | grep '/$' | xargs
109109
}
110110

111111
gen_random_str()
@@ -142,6 +142,8 @@ if [ -e "$CHTSH_CONF" ]; then
142142
. "$CHTSH_CONF"
143143
fi
144144

145+
[ -z "$CHTSH_URL" ] && CHTSH_URL=https://cht.sh
146+
145147
if [ "$1" = --read ]; then
146148
read -r a || a=exit
147149
printf "%s\n" "$a"
@@ -160,8 +162,6 @@ elif [ x"$1" = x--shell ]; then
160162
shift
161163
fi
162164

163-
prompt="cht.sh"
164-
165165
prompt="cht.sh"
166166
opts=""
167167
input=""
@@ -175,7 +175,7 @@ done
175175
query=$(echo "$input" | sed 's@ *$@@; s@^ *@@; s@ @/@; s@ @+@g')
176176

177177
if [ "$shell_mode" != yes ]; then
178-
curl -s https://cht.sh/"$(get_query_options "$query")"
178+
curl -s "${CHTSH_URL}"/"$(get_query_options "$query")"
179179
exit 0
180180
else
181181
new_section="$1"
@@ -192,7 +192,7 @@ else
192192
fi
193193
if [ -n "$this_query" ] && [ -z "$CHEATSH_RESTART" ]; then
194194
printf "$this_prompt$this_query\n"
195-
curl -s https://cht.sh/"$(get_query_options "$query")"
195+
curl -s "${CHTSH_URL}"/"$(get_query_options "$query")"
196196
fi
197197
fi
198198

@@ -291,7 +291,7 @@ EOF
291291
echo copy: Make at least one query first.
292292
continue
293293
else
294-
curl -s https://cht.sh/"$(get_query_options "$query"?T)" > "$TMP1"
294+
curl -s "${CHTSH_URL}"/"$(get_query_options "$query"?T)" > "$TMP1"
295295
if [ "$is_macos" != yes ]; then
296296
xsel -i < "$TMP1"
297297
else
@@ -310,7 +310,7 @@ EOF
310310
echo copy: Make at least one query first.
311311
continue
312312
else
313-
curl -s https://cht.sh/"$(get_query_options "$query"?TQ)" > "$TMP1"
313+
curl -s "${CHTSH_URL}"/"$(get_query_options "$query"?TQ)" > "$TMP1"
314314
if [ "$is_macos" != yes ]; then
315315
xsel -i < "$TMP1"
316316
else
@@ -407,9 +407,9 @@ EOF
407407
continue
408408
;;
409409
update)
410-
[ -w "$0" ] || { echo "The script is readonly; please update manually: curl -s https://cht.sh/:bash | sudo tee $0"; continue; }
410+
[ -w "$0" ] || { echo "The script is readonly; please update manually: curl -s "${CHTSH_URL}"/:bash | sudo tee $0"; continue; }
411411
TMP2=$(mktemp /tmp/cht.sh.XXXXXXXXXXXXX)
412-
curl -s https://cht.sh/:cht.sh > "$TMP2"
412+
curl -s "${CHTSH_URL}"/:cht.sh > "$TMP2"
413413
if ! cmp "$0" "$TMP2" > /dev/null 2>&1; then
414414
if grep -q ^__CHTSH_VERSION= "$TMP2"; then
415415
# section was vaildated by us already
@@ -428,7 +428,7 @@ EOF
428428
insttime=$(ls -l -- "$0" | sed 's/ */ /g' | cut -d ' ' -f 6-8)
429429
echo "cht.sh version $__CHTSH_VERSION of $__CHTSH_DATETIME; installed at: $insttime"
430430
TMP2=$(mktemp /tmp/cht.sh.XXXXXXXXXXXXX)
431-
if curl -s https://cht.sh/:cht.sh > "$TMP2"; then
431+
if curl -s "${CHTSH_URL}"/:cht.sh > "$TMP2"; then
432432
if ! cmp "$0" "$TMP2" > /dev/null 2>&1; then
433433
echo "Update needed (type 'update' for that)".
434434
else

0 commit comments

Comments
 (0)