]> arthur.barton.de Git - ax-zsh.git/commitdiff
cheat: Add c() function for browsing cht.sh when fzf(1) is available
authorAlexander Barton <alex@barton.de>
Sun, 17 Jan 2021 21:03:04 +0000 (22:03 +0100)
committerAlexander Barton <alex@barton.de>
Sun, 17 Jan 2021 21:03:04 +0000 (22:03 +0100)
default_plugins/cheat/cheat.zshrc

index 0fe13b60c1608161ff23813675cffd9ad174643f..7ddb321bcd5b2b1accaec1edd242e451ea7e3681 100644 (file)
@@ -1,6 +1,15 @@
 # AX-ZSH: Alex' Modular ZSH Configuration
 # cheat: Setup https://cht.sh
 
+if (( $+commands[fzf] )); then
+       # See <https://twitter.com/igor_chubin/status/1343294742315020293>
+       function c() {
+               url="https://cht.sh"
+               term=$(curl -ks "$url/:list" | IFS=+ fzf --preview "curl -ks '$url/{}'" -q "$*") \
+                       && curl -ks "$url/${term}" | ${PAGER:-less}
+       }
+fi
+
 # Don't overwrite a real "cheat" command!
 (( $+commands[cheat] )) && return