From 94722a6e28f398f78e8be5e9c78f59f44ad98444 Mon Sep 17 00:00:00 2001 From: Christian Lentfort Date: Wed, 18 Jun 2014 18:29:26 +0200 Subject: [PATCH] Added explainshell module --- modules/explainshell/README.md | 10 +++++++++ modules/explainshell/init.zsh | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 modules/explainshell/README.md create mode 100644 modules/explainshell/init.zsh diff --git a/modules/explainshell/README.md b/modules/explainshell/README.md new file mode 100644 index 00000000..28297efe --- /dev/null +++ b/modules/explainshell/README.md @@ -0,0 +1,10 @@ +#Explainshell + +Adds a keybinding to open (explainshell.com)[http://www.explainshell.com] with the content of the command line. + +##Settings + +###Key-Binding +The keybinding to open (explainshell.com)[http://www.explainshell.com] + +`zstyle ':prezto:module:explainshell' key-binding '^K'` diff --git a/modules/explainshell/init.zsh b/modules/explainshell/init.zsh new file mode 100644 index 00000000..b84d2e14 --- /dev/null +++ b/modules/explainshell/init.zsh @@ -0,0 +1,38 @@ +# +# Adds a explain function and explainshell widget +# +# Authors +# C Lentfort +# + + +function explain { + # base url with first command already injected + # $ explain tar + # => http://explainshel.com/explain/tar?args= + url="http://explainshell.com/explain/$1?args=" + + # removes $1 (tar) from arguments ($@) + shift; + + # iterates over remaining args and adds builds the rest of the url + for i in "$@"; do + url=$url"$i""+" + done + + # opens url in browser + $BROWSER -t $url &> /dev/null +} + +function explainshell { + explain $BUFFER +} + +zle -N explainshell + +zstyle -s ':prezto:module:explainshell' key-binding 'key_binding' +if [[ -n "$key_binding" ]]; then + bindkey "$key_binding" explainshell +fi + +unset key_binding