Skip to content

Commit

Permalink
configurable cheat.sh server in the cht.sh client (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
chubin committed Aug 18, 2018
1 parent c7a39d0 commit 8d12aab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ QUERY_OPTIONS="style=native"

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

Other cht.sh configuration parameters:

```
CHTSH_URL=https://cht.sh # URL of the cheat.sh server
```

### Tab completion

Expand Down
22 changes: 11 additions & 11 deletions share/cht.sh.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ do_query()
{
local query="$*"
local b_opts=
local uri="https://cht.sh/\"\$(get_query_options $query)\""
local uri="${CHTSH_URL}/\"\$(get_query_options $query)\""

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

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

gen_random_str()
Expand Down Expand Up @@ -142,6 +142,8 @@ if [ -e "$CHTSH_CONF" ]; then
. "$CHTSH_CONF"
fi

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

if [ "$1" = --read ]; then
read -r a || a=exit
printf "%s\n" "$a"
Expand All @@ -160,8 +162,6 @@ elif [ x"$1" = x--shell ]; then
shift
fi

prompt="cht.sh"

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

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

Expand Down Expand Up @@ -291,7 +291,7 @@ EOF
echo copy: Make at least one query first.
continue
else
curl -s https://cht.sh/"$(get_query_options "$query"?T)" > "$TMP1"
curl -s "${CHTSH_URL}"/"$(get_query_options "$query"?T)" > "$TMP1"
if [ "$is_macos" != yes ]; then
xsel -i < "$TMP1"
else
Expand All @@ -310,7 +310,7 @@ EOF
echo copy: Make at least one query first.
continue
else
curl -s https://cht.sh/"$(get_query_options "$query"?TQ)" > "$TMP1"
curl -s "${CHTSH_URL}"/"$(get_query_options "$query"?TQ)" > "$TMP1"
if [ "$is_macos" != yes ]; then
xsel -i < "$TMP1"
else
Expand Down Expand Up @@ -407,9 +407,9 @@ EOF
continue
;;
update)
[ -w "$0" ] || { echo "The script is readonly; please update manually: curl -s https://cht.sh/:bash | sudo tee $0"; continue; }
[ -w "$0" ] || { echo "The script is readonly; please update manually: curl -s "${CHTSH_URL}"/:bash | sudo tee $0"; continue; }
TMP2=$(mktemp /tmp/cht.sh.XXXXXXXXXXXXX)
curl -s https://cht.sh/:cht.sh > "$TMP2"
curl -s "${CHTSH_URL}"/:cht.sh > "$TMP2"
if ! cmp "$0" "$TMP2" > /dev/null 2>&1; then
if grep -q ^__CHTSH_VERSION= "$TMP2"; then
# section was vaildated by us already
Expand All @@ -428,7 +428,7 @@ EOF
insttime=$(ls -l -- "$0" | sed 's/ */ /g' | cut -d ' ' -f 6-8)
echo "cht.sh version $__CHTSH_VERSION of $__CHTSH_DATETIME; installed at: $insttime"
TMP2=$(mktemp /tmp/cht.sh.XXXXXXXXXXXXX)
if curl -s https://cht.sh/:cht.sh > "$TMP2"; then
if curl -s "${CHTSH_URL}"/:cht.sh > "$TMP2"; then
if ! cmp "$0" "$TMP2" > /dev/null 2>&1; then
echo "Update needed (type 'update' for that)".
else
Expand Down

0 comments on commit 8d12aab

Please sign in to comment.