From 449b66753370d6b64bc9aa7e5c0592ba0fe6f680 Mon Sep 17 00:00:00 2001 From: johannst Date: Wed, 16 Sep 2020 22:23:09 +0000 Subject: deploy: 2e329ad934ef010fd94afe965f14ab895dcb515e --- tools/zsh.html | 320 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 320 insertions(+) create mode 100644 tools/zsh.html (limited to 'tools/zsh.html') diff --git a/tools/zsh.html b/tools/zsh.html new file mode 100644 index 0000000..6584e5b --- /dev/null +++ b/tools/zsh.html @@ -0,0 +1,320 @@ + + + + + + zsh - Notes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + +
+
+

zsh(1)

+

Keybindings

+

Change input mode:

+
bindkey -v              change to vi keymap
+bindkey -e              change to emacs keymap
+
+

Define key-mappings:

+
bindkey                 list mappings in current keymap
+bindkey in-str cmd      create mapping for `in-str` to `cmd`
+bindkey -r in-str       remove binding for `in-str`
+
+# C-v <key>             dump <key> code, which can be used in `in-str`
+# zle -l                list all functions for keybindings
+# man zshzle(1)         STANDARD WIDGETS: get description of functions
+
+

Completion

+

Installation

+

Completion functions are provided via files and need to be placed in a location +covered by $fpath. By convention the completion files are names as _<CMD>.

+

A completion skeleton for the command foo, stored in _foo

+
#compdef _foo foo
+
+function _foo() {
+	...
+}
+
+

Alternatively one can install a completion function explicitly by calling compdef <FUNC> <CMD>.

+

Completion Variables

+

Following variables are available in Completion functions:

+
$words              # array with command line in words
+$#words             # number words
+$CURRENT            # index into $words for cursor position
+$words[CURRENT-1]   # previous word (relative to cursor position)
+
+

Completion Functions

+
    +
  • _describe simple completion, just words + description
  • +
  • _arguments sophisticated completion, allow to specify actions
  • +
+

Completion with _describe

+
_describe MSG COMP
+
+
    +
  • MSG simple string with header message
  • +
  • COMP array of completions where each entry is "opt:description"
  • +
+
function _foo() {
+    local -a opts
+    opts=('bla:desc for bla' 'blu:desc for blu')
+    _describe 'foo-msg' opts
+}
+compdef _foo foo
+
+foo <TAB><TAB>
+ -- foo-msg --
+bla  -- desc for bla
+blu  -- desc for blu
+
+

Completion with _arguments

+
_arguments SPEC [SPEC...]
+
+

where SPEC can have one of the following forms:

+
    +
  • OPT[DESC]:MSG:ACTION
  • +
  • N:MSG:ACTION
  • +
+

Available actions

+
(op1 op2)   list possible matches
+->VAL       set $state=VAL and continue, `$state` can be checked later in switch case
+FUNC        call func to generate matches
+{STR}       evaluate `STR` to generate matches
+
+

Example

+

Skeleton to copy/paste for writing simple completions.

+

Assume a program foo with the following interface:

+
foo -c green|red|blue -s low|high -f <file> -d <dir> -h
+
+

The completion handler could be implemented as follows in a file called _foo:

+
#compdef _foo foo
+
+function _foo_color() {
+    local colors=()
+    colors+=('green:green color')
+    colors+=('red:red color')
+    colors+=('blue:blue color')
+    _describe "color" colors
+}
+
+function _foo() {
+    _arguments                              \
+        "-c[define color]:color:->s_color"  \
+        "-s[select sound]:color:(low high)" \
+        "-f[select file]:file:_files"       \
+        "-d[select dir]:fir:_files -/"      \
+        "-h[help]"
+
+    case $state in
+        s_color) _foo_color;;
+    esac
+}
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3