From 4ebfabeb0a29e58e6ac06435601b81ad11c564d9 Mon Sep 17 00:00:00 2001 From: johannst Date: Thu, 14 Jan 2021 21:30:05 +0000 Subject: deploy: 4de58de1947bf4fcfe16db8e9d2c9c920b1441d1 --- print.html | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 150 insertions(+), 6 deletions(-) (limited to 'print.html') diff --git a/print.html b/print.html index d3416cd..c033275 100644 --- a/print.html +++ b/print.html @@ -83,7 +83,7 @@ @@ -178,6 +178,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 @@ -186,7 +295,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>.

@@ -282,10 +391,13 @@ function _foo() { # expand cartesian product {a,b}{c,d} -

Parameter

-
# default param
+

Parameter

+
# 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
 
@@ -456,7 +568,7 @@ complete -F _foo foo
 
  • fish_default_key_bindings to use default key bindings
  • fish_vi_key_bindings to use vi key bindings
  • -

    Variables

    +

    Variables

    Available scopes

    • local variable local to a block
    • @@ -1386,6 +1498,7 @@ executed. To workaround that bug one can create a wrapper function which calls

      Resource analysis & monitor

      • lsof
      • +
      • ss
      • pidstat
      • pgrep
      • pmap
      • @@ -1434,9 +1547,40 @@ executed. To workaround that bug one can create a wrapper function which calls

        Show open connections to localhost for $USER:

        lsof -a -u $USER -i @localhost
         
        +

        Open connection to specific port

        +

        Show open connections to port :1234 for $USER:

        +
        lsof -a -u $USER -i :1234
        +

        IPv4 TCP connections in ESTABLISHED state

        lsof -i 4TCP -s TCP:ESTABLISHED
         
        +

        ss(8)

        +
        ss [option] [filter]
        +
        +
        [option]
        +  -p ..... Show process using socket
        +  -l ..... Show sockets in listening state
        +  -4/-6 .. Show IPv4/6 sockets
        +  -x ..... Show unix sockets
        +  -n ..... Show numeric ports (no resolve)
        +  -O ..... Oneline output per socket
        +
        +
        [filter]
        +  dport/sport PORT .... Filter for destination/source port
        +  dst/src ADDR ........ Filter for destination/source address
        +
        +  and/or .............. Logic operator
        +  ==/!= ............... Comparison operator
        +
        +  (EXPR) .............. Group exprs
        +
        +

        Examples

        +

        Show all tcp IPv4 sockets connecting to port 443:

        +
        ss -4 'dport 443'
        +
        +

        Show all tcp IPv4 sockets that don't connect to port 443 or connect to address 1.2.3.4.

        +
        ss -4 'dport != 443 or dst 1.2.3.4'
        +

        pidstat(1)

        pidstat [opt] [interval] [cont]
           -U [user]     show username instead UID, optionally only show for user
        @@ -1504,7 +1648,7 @@ major_pagefault: Happens when the page needed is NOT in memory, the kernel
           trace=signal ............... trace signal related syscalls
           signal ..................... trace signals delivered to the process
         
        -

        Examples

        +

        Examples

        Trace open(2) & socket(2) syscalls for a running process + child processes:

        strace -f -e trace=open,socket -p <pid>
         
        -- cgit v1.2.3