From 4ebfabeb0a29e58e6ac06435601b81ad11c564d9 Mon Sep 17 00:00:00 2001 From: johannst Date: Thu, 14 Jan 2021 21:30:05 +0000 Subject: deploy: 4de58de1947bf4fcfe16db8e9d2c9c920b1441d1 --- tools/awk.html | 2 +- tools/bash.html | 7 +++- tools/emacs.html | 2 +- tools/fish.html | 2 +- tools/gdb.html | 2 +- tools/git.html | 2 +- tools/gpg.html | 2 +- tools/index.html | 2 +- tools/radare2.html | 2 +- tools/tmux.html | 2 +- tools/zsh.html | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 11 files changed, 125 insertions(+), 13 deletions(-) (limited to 'tools') diff --git a/tools/awk.html b/tools/awk.html index d4695ee..37f10e9 100644 --- a/tools/awk.html +++ b/tools/awk.html @@ -81,7 +81,7 @@ diff --git a/tools/bash.html b/tools/bash.html index 1f3b722..cf5a5ed 100644 --- a/tools/bash.html +++ b/tools/bash.html @@ -81,7 +81,7 @@ @@ -160,9 +160,12 @@ {a,b}{c,d}

Parameter

-
# default param
+
# default value
 bar=${foo:-some_val}  # if $foo set, then bar=$foo else bar=some_val
 
+# alternate value
+bar=${foo:+bla $foo}  # if $foo set, then bar="bla $foo" else bar=""
+
 # check param set
 bar=${foo:?msg}  # if $foo set, then bar=$foo else exit and print msg
 
diff --git a/tools/emacs.html b/tools/emacs.html
index f26dd0d..40bd275 100644
--- a/tools/emacs.html
+++ b/tools/emacs.html
@@ -81,7 +81,7 @@
 
         
diff --git a/tools/fish.html b/tools/fish.html
index ed8a9a8..006c794 100644
--- a/tools/fish.html
+++ b/tools/fish.html
@@ -81,7 +81,7 @@
 
         
diff --git a/tools/gdb.html b/tools/gdb.html
index 4b955da..8f901be 100644
--- a/tools/gdb.html
+++ b/tools/gdb.html
@@ -81,7 +81,7 @@
 
         
diff --git a/tools/git.html b/tools/git.html
index e61a4da..c675e62 100644
--- a/tools/git.html
+++ b/tools/git.html
@@ -81,7 +81,7 @@
 
         
diff --git a/tools/gpg.html b/tools/gpg.html
index 5a4fea3..4c7818d 100644
--- a/tools/gpg.html
+++ b/tools/gpg.html
@@ -81,7 +81,7 @@
 
         
diff --git a/tools/index.html b/tools/index.html
index b91857e..149af9c 100644
--- a/tools/index.html
+++ b/tools/index.html
@@ -81,7 +81,7 @@
 
         
diff --git a/tools/radare2.html b/tools/radare2.html
index 413b4ff..bb50b80 100644
--- a/tools/radare2.html
+++ b/tools/radare2.html
@@ -81,7 +81,7 @@
 
         
diff --git a/tools/tmux.html b/tools/tmux.html
index 1e49342..045ec1e 100644
--- a/tools/tmux.html
+++ b/tools/tmux.html
@@ -81,7 +81,7 @@
 
         
diff --git a/tools/zsh.html b/tools/zsh.html
index b476c33..2a540ab 100644
--- a/tools/zsh.html
+++ b/tools/zsh.html
@@ -81,7 +81,7 @@
 
         
@@ -163,6 +163,115 @@ bindkey -r in-str       remove binding for `in-str`
 # zle -l                list all functions for keybindings
 # man zshzle(1)         STANDARD WIDGETS: get description of functions
 
+

Access edit buffer in zle widget:

+
$BUFFER       # Entire edit buffer content
+$LBUFFER      # Edit buffer content left to cursor
+$RBUFFER      # Edit buffer content right to cursor
+
+# create zle widget which adds text right of the cursor
+function add-text() {
+    RBUFFER="some text $RBUFFER"
+}
+zle -N add-text
+
+bindkey "^p" add-text
+
+

Parameter

+

Default value:

+
# default value
+echo ${foo:-defval}   # defval
+foo=bar
+echo ${foo:-defval}   # bar
+
+

Alternative value:

+
echo ${foo:+altval}   # ''
+foo=bar
+echo ${foo:+altval}   # altval
+
+

Check variable set, error if not set:

+
echo ${foo:?msg}      # print `msg` and return errno `1`
+foo=bar
+echo ${foo:?msg}      # bar
+
+

Sub-string ${var:offset:length}:

+
foo=abcdef
+echo ${foo:1:3}       # bcd
+
+

Trim prefix ${var#prefix}:

+
foo=bar.baz
+echo ${foo#bar}       # .baz
+
+

Trim suffix ${var%suffix}:

+
foo=bar.baz
+echo ${foo%.baz}      # bar
+
+

Substitute pattern ${var/pattern/replace}:

+
foo=aabbccbbdd
+echo ${foo/bb/XX}    # aaXXccbbdd
+echo ${foo//bb/XX}   # aaXXccXXdd
+# replace prefix
+echo ${foo/#bb/XX}   # aabbccbbdd
+echo ${foo/#aa/XX}   # XXbbccbbdd
+# replace suffix
+echo ${foo/%bb/XX}   # aabbccbbdd
+echo ${foo/%dd/XX}   # aabbccbbXX
+
+
+

Note: prefix/suffix/pattern are expanded as pathnames.

+
+

Variables

+
# Variable with local scope
+local var=val
+
+# Read-only variable
+readonly var=bal
+
+

Indexed arrays:

+
arr=(aa bb cc dd)
+echo $arr[1]           # aa
+echo $arr[-1]          # dd
+
+arr+=(ee)
+echo $arr[-1]          # ee
+
+echo $arr[1,3]         # aa bb cc
+
+

Associative arrays:

+
typeset -A arr
+arr[x]='aa'
+arr[y]='bb'
+echo $arr[x]           # aa
+
+

Tied arrays:

+
typeset -T VEC vec=(1 2 3) '|'
+
+echo $vec              # 1 2 3
+echo $VEC              # 1|2|3
+
+

Unique arrays (set):

+
typeset -U vec=(1 2 3)
+
+echo $vec             # 1 2 3
+vec+=(1 2 4)
+echo $vec             # 1 2 3 4
+
+

Expansion Flags

+

Join array to string j:sep::

+
foo=(1 2 3 4)
+echo ${(j:-:)foo}     # 1-2-3-4
+echo ${(j:\n:)foo}    # join with new lines
+
+

Split string to array s:sep:

+
foo='1-2-3-4'
+bar=(${(s:-:)foo})    # capture as array
+echo $bar             # 1 2 3 4
+echo $bar[2]          # 2
+
+

Upper/Lower case string:

+
foo=aaBB
+echo ${(L)foo}        # aabb
+echo ${(U)foo}        # AABB
+

Completion

Installation

Completion functions are provided via files and need to be placed in a location @@ -171,7 +280,7 @@ covered by $fpath. By convention the completion files are names as

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

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

-- cgit v1.2.3