]> arthur.barton.de Git - ax-zsh.git/blob - default_plugins/cheat/cheat.zshrc
Correctly test XDG_CACHE_HOME for writability for "stamp files"
[ax-zsh.git] / default_plugins / cheat / cheat.zshrc
1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # cheat: Setup https://cht.sh
3
4 if (( $+commands[fzf] )); then
5         # See <https://twitter.com/igor_chubin/status/1343294742315020293>
6         function c() {
7                 url="https://cht.sh"
8                 term=$(curl -ks "$url/:list" | IFS=+ fzf --preview "curl -ks '$url/{}'" -q "$*") \
9                         && curl -ks "$url/${term}" | ${PAGER:-less}
10         }
11 fi
12
13 # Don't overwrite a real "cheat" command!
14 (( $+commands[cheat] )) && return
15
16 function cheat() {
17         if (( $+commands[cht.sh] )); then
18                 if [[ $# -eq 0 ]]; then
19                         CHTSH_QUERY_OPTIONS="style=monokai" cht.sh --shell
20                 else
21                         CHTSH_QUERY_OPTIONS="style=monokai" cht.sh "$@" \
22                          | ${PAGER:-less}
23                 fi
24                 return $?
25         fi
26
27         url="https://cht.sh/$@?style=monokai"
28
29         if (( $+commands[curl] )); then
30                 curl -s "$url" | ${PAGER:-less}
31         elif (( $+commands[wget] )); then
32                 wget -qO - "$url" | ${PAGER:-less}
33         else
34                 echo "Neither cht.sh(1), curl(1) nor wget(1) found!" >&2
35                 return 1
36         fi
37 }