]> arthur.barton.de Git - ax-zsh.git/commitdiff
New "mankier" plugin
authorAlexander Barton <alex@barton.de>
Fri, 19 Apr 2019 16:52:59 +0000 (18:52 +0200)
committerAlexander Barton <alex@barton.de>
Fri, 19 Apr 2019 16:52:59 +0000 (18:52 +0200)
This sets up functions to use *ManKier*, a online manual page service:
<https://www.mankier.com/>

plugins/mankier/README.md [new file with mode: 0644]
plugins/mankier/mankier.zshrc [new file with mode: 0644]

diff --git a/plugins/mankier/README.md b/plugins/mankier/README.md
new file mode 100644 (file)
index 0000000..15e3671
--- /dev/null
@@ -0,0 +1,12 @@
+## mankier
+
+Setup some functions to use *ManKier*, a online manual page service:
+<https://www.mankier.com/>
+
+### Prerequisites
+
+- `curl`(1)
+
+### Functions
+
+- `explain`: Explain a command using ManKier's online API.
diff --git a/plugins/mankier/mankier.zshrc b/plugins/mankier/mankier.zshrc
new file mode 100644 (file)
index 0000000..bfe6108
--- /dev/null
@@ -0,0 +1,24 @@
+# AX-ZSH: Alex' Modular ZSH Configuration
+# mankier.zshrc: Setup ManKier online manual page service.
+
+[[ -z "$AXZSH_PLUGIN_CHECK" ]] || return 92
+
+# curl(1) is required to access the online API
+(( $+commands[curl] )) || return
+
+explain () {
+       # Explain a shell command. See:
+       # <https://www.mankier.com/blog/explaining-shell-commands-in-the-shell.html>
+
+       local api_url="https://www.mankier.com/api/v2"
+
+       if [[ "$#" -eq 0 ]]; then
+               while read 'cmd?Explain: '; do
+                       [[ -n "$cmd" ]] || break
+                       curl -Gs "$api_url/explain/?cols=$(tput cols)" --data-urlencode q="$cmd" | less
+               done
+               echo "Bye!"
+       else
+               curl -Gs "$api_url/explain/?cols=$(tput cols)" --data-urlencode q="$*" | less
+       fi
+}