]> arthur.barton.de Git - ax-zsh.git/blobdiff - default_plugins/cheat/cheat.zshrc
cheat: Enhance plugin a bit
[ax-zsh.git] / default_plugins / cheat / cheat.zshrc
index bfec74789441f60cc3fb727547b099316875493b..0fe13b60c1608161ff23813675cffd9ad174643f 100644 (file)
@@ -1,18 +1,28 @@
 # AX-ZSH: Alex' Modular ZSH Configuration
-# cheat: Setup http://cheat.sh
+# cheat: Setup https://cht.sh
 
 # Don't overwrite a real "cheat" command!
 (( $+commands[cheat] )) && return
 
 function cheat() {
-       url="http://cheat.sh/$@?style=monokai"
+       if (( $+commands[cht.sh] )); then
+               if [[ $# -eq 0 ]]; then
+                       CHTSH_QUERY_OPTIONS="style=monokai" cht.sh --shell
+               else
+                       CHTSH_QUERY_OPTIONS="style=monokai" cht.sh "$@" \
+                        | ${PAGER:-less}
+               fi
+               return $?
+       fi
+
+       url="https://cht.sh/$@?style=monokai"
 
        if (( $+commands[curl] )); then
                curl -s "$url" | ${PAGER:-less}
        elif (( $+commands[wget] )); then
                wget -qO - "$url" | ${PAGER:-less}
        else
-               echo "Neither curl(1) nor wget(1) found!" >&2
+               echo "Neither cht.sh(1), curl(1) nor wget(1) found!" >&2
                return 1
        fi
 }