diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/awk.html | 22 | ||||
-rw-r--r-- | tools/bash.html | 47 | ||||
-rw-r--r-- | tools/dot.html | 4 | ||||
-rw-r--r-- | tools/ffmpeg.html | 4 | ||||
-rw-r--r-- | tools/fish.html | 34 | ||||
-rw-r--r-- | tools/gdb.html | 2 | ||||
-rw-r--r-- | tools/git.html | 2 | ||||
-rw-r--r-- | tools/gnuplot.html | 40 | ||||
-rw-r--r-- | tools/pacman.html | 2 | ||||
-rw-r--r-- | tools/qemu.html | 8 | ||||
-rw-r--r-- | tools/radare2.html | 2 | ||||
-rw-r--r-- | tools/sed.html | 22 | ||||
-rw-r--r-- | tools/tmux.html | 2 | ||||
-rw-r--r-- | tools/zsh.html | 38 |
14 files changed, 134 insertions, 95 deletions
diff --git a/tools/awk.html b/tools/awk.html index 9d301da..bdf80b2 100644 --- a/tools/awk.html +++ b/tools/awk.html @@ -238,7 +238,7 @@ multiple times. Actions with those patterns are <strong>executed exactly once</s <h3 id="special-statements--functions"><a class="header" href="#special-statements--functions">Special statements & functions</a></h3> <ul> <li> -<p><code>printf "fmt", args...</code></p> +<p><code>printf "fmt", args...</code></p> <p>Print format string, args are comma separated.</p> <ul> <li><code>%s</code> string</li> @@ -251,12 +251,12 @@ For floats one can use <code>%N.Mf</code>, <code>N</code> is the total number in <code>M</code>.</p> </li> <li> -<p><code>sprintf("fmt", expr, ...)</code></p> +<p><code>sprintf("fmt", expr, ...)</code></p> <p>Format the expressions according to the format string. Similar as <code>printf</code>, but this is a function and return value can be assigned to a variable.</p> </li> <li> -<p><code>strftime("fmt")</code></p> +<p><code>strftime("fmt")</code></p> <p>Print time stamp formatted by <code>fmt</code>.</p> <ul> <li><code>%Y</code> full year (eg 2020)</li> @@ -290,7 +290,7 @@ prints the whole record.</p> </code></pre> <p>Matches records not starting with <code>#</code>.</p> <h3 id="range-patterns"><a class="header" href="#range-patterns">Range patterns</a></h3> -<pre><code class="language-bash">echo -e "a\nFOO\nb\nc\nBAR\nd" | \ +<pre><code class="language-bash">echo -e "a\nFOO\nb\nc\nBAR\nd" | \ awk '/FOO/,/BAR/ { print }' </code></pre> <p><code>/FOO/,/BAR/</code> define a range pattern of <code>begin_pattern, end_pattern</code>. When @@ -298,13 +298,17 @@ prints the whole record.</p> <code>end_pattern</code> is matched the range is <strong>turned off</strong>. This matches every record in the range <em>inclusive</em>.</p> <p>An <em>exclusive</em> range must be handled explicitly, for example as follows.</p> -<pre><code class="language-bash">echo -e "a\nFOO\nb\nc\nBAR\nd" | \ - awk '/FOO/,/BAR/ { if (!($1 ~ "FOO") && !($1 ~ "BAR")) { print } }' +<pre><code class="language-bash">echo -e "a\nFOO\nb\nc\nBAR\nd" | \ + awk '/FOO/,/BAR/ { if (!($1 ~ "FOO") && !($1 ~ "BAR")) { print } }' </code></pre> <h3 id="access-last-fields-in-records"><a class="header" href="#access-last-fields-in-records">Access last fields in records</a></h3> <pre><code class="language-bash">echo 'a b c d e f' | awk '{ print $NF $(NF-1) }' </code></pre> <p>Access last fields with arithmetic on the <code>NF</code> number of fields variable.</p> +<h3 id="split-on-multiple-tokens"><a class="header" href="#split-on-multiple-tokens">Split on multiple tokens</a></h3> +<pre><code class="language-bash">echo 'a,b;c:d' | awk -F'[,;:]' '{ printf "1=%s | 4=%s\n", $1, $4 }' +</code></pre> +<p>Use regex as field separator.</p> <h3 id="capture-in-variables"><a class="header" href="#capture-in-variables">Capture in variables</a></h3> <pre><code class="language-bash"># /proc/<pid>/status # Name: cat @@ -316,7 +320,7 @@ for f in /proc/*/status; do cat $f | awk ' /^VmRSS/ { rss = $2/1024 } /^Name/ { name = $2 } - END { printf "%16s %6d MB\n", name, rss }'; + END { printf "%16s %6d MB\n", name, rss }'; done | sort -k2 -n </code></pre> <p>We capture values from <code>VmRSS</code> and <code>Name</code> into variables and print them at the @@ -331,7 +335,7 @@ a 1' | awk '{ } END { for (v in vals) - printf "%s %d\n", v, vals[v] / cnts [v] + printf "%s %d\n", v, vals[v] / cnts [v] }' </code></pre> <p>Capture keys and values from different columns and some up the values. @@ -339,7 +343,7 @@ At the <code>END</code> we compute the average of each key.</p> <h3 id="run-shell-command-and-capture-output"><a class="header" href="#run-shell-command-and-capture-output">Run shell command and capture output</a></h3> <pre><code class="language-bash">cat /proc/1/status | awk ' /^Pid/ { - "ps --no-header -o user " $2 | getline user; + "ps --no-header -o user " $2 | getline user; print user }' </code></pre> diff --git a/tools/bash.html b/tools/bash.html index 580e941..91d44cb 100644 --- a/tools/bash.html +++ b/tools/bash.html @@ -192,7 +192,7 @@ 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="" +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 @@ -274,6 +274,19 @@ contains some nice visualization to explain bash redirections.</p> once.</p> <pre><code class="language-bash">vim -d <(grep foo bar) <(grep foo moose) </code></pre> +<h2 id="command-grouping"><a class="header" href="#command-grouping">Command grouping</a></h2> +<p>Execute commands in a group with or without subshell. Can be used to easily +redirect stdout/stderr of all commands in the group into one file.</p> +<pre><code class="language-bash"># Group commands without subshell. +v=abc ; { v=foo; echo $v; } ; echo $v +# foo +# foo + +# Group commands with subshell. +v=abc ; ( v=foo; echo $v; ) ; echo $v +# foo +# abc +</code></pre> <h2 id="argument-parsing-with-getopts"><a class="header" href="#argument-parsing-with-getopts">Argument parsing with <code>getopts</code></a></h2> <p>The <code>getopts</code> builtin uses following global variables:</p> <ul> @@ -296,11 +309,11 @@ once.</p> <h3 id="example"><a class="header" href="#example">Example</a></h3> <pre><code class="language-bash">#!/bin/bash function parse_args() { - while getopts "f:c" PARAM; do + while getopts "f:c" PARAM; do case $PARAM in - f) echo "GOT -f $OPTARG";; - c) echo "GOT -c";; - *) echo "ERR: print usage"; exit 1;; + f) echo "GOT -f $OPTARG";; + c) echo "GOT -c";; + *) echo "ERR: print usage"; exit 1;; esac done # users responsibility to reset OPTIND @@ -320,14 +333,14 @@ The match results can be accessed via the <code>$BASH_REMATCH</code> variable:</ <pre><code class="language-bash">INPUT='title foo : 1234' REGEX='^title (.+) : ([0-9]+)$' if [[ $INPUT =~ $REGEX ]]; then - echo "${BASH_REMATCH[0]}" # title foo : 1234 - echo "${BASH_REMATCH[1]}" # foo - echo "${BASH_REMATCH[2]}" # 1234 + echo "${BASH_REMATCH[0]}" # title foo : 1234 + echo "${BASH_REMATCH[1]}" # foo + echo "${BASH_REMATCH[2]}" # 1234 fi </code></pre> <blockquote> <p><strong>Caution</strong>: When specifying a <code>regex</code> in the <code>[[ ]]</code> block directly, quotes will be treated as part of the pattern. -<code>[[ $INPUT =~ "foo" ]]</code> will match against <code>"foo"</code> not <code>foo</code>!</p> +<code>[[ $INPUT =~ "foo" ]]</code> will match against <code>"foo"</code> not <code>foo</code>!</p> </blockquote> <h2 id="completion"><a class="header" href="#completion">Completion</a></h2> <p>The <code>complete</code> builtin is used to interact with the completion system.</p> @@ -358,11 +371,11 @@ against words generated by <code>option</code>.</p> # -u generate list with users # -e generate list with exported variables -# compare "f" against words "foo" "foobar" "bar" and generate matches -compgen -W "foo foobar bar" "f" +# compare "f" against words "foo" "foobar" "bar" and generate matches +compgen -W "foo foobar bar" "f" -# compare "hom" against file/dir names and generate matches -compgen -d -f "hom" +# compare "hom" against file/dir names and generate matches +compgen -d -f "hom" </code></pre> <h3 id="example-1"><a class="header" href="#example-1">Example</a></h3> <p>Skeleton to copy/paste for writing simple completions.</p> @@ -374,12 +387,12 @@ compgen -d -f "hom" local curr=$2 local prev=$3 - local opts="-c -s -f -h" + local opts="-c -s -f -h" case $prev in - -c) COMPREPLY=( $(compgen -W "green red blue" -- $curr) );; - -s) COMPREPLY=( $(compgen -W "low high" -- $curr) );; + -c) COMPREPLY=( $(compgen -W "green red blue" -- $curr) );; + -s) COMPREPLY=( $(compgen -W "low high" -- $curr) );; -f) COMPREPLY=( $(compgen -f -- $curr) );; - *) COMPREPLY=( $(compgen -W "$opts" -- $curr) );; + *) COMPREPLY=( $(compgen -W "$opts" -- $curr) );; esac } diff --git a/tools/dot.html b/tools/dot.html index 5e45abd..60a5c39 100644 --- a/tools/dot.html +++ b/tools/dot.html @@ -200,10 +200,10 @@ digraph { // Add multiple edges at once. stage2 -> { stage3_1, stage3_2 } // Add edge with custom attributes. - stage3_2 -> stage4 [label="some text"] + stage3_2 -> stage4 [label="some text"] // Set custom attributes for specific node. - stage4 [color=green,fillcolor=lightgray,style="filled,dashed",label="s4"] + stage4 [color=green,fillcolor=lightgray,style="filled,dashed",label="s4"] // Create a subgraph. This can be used to group nodes/edges or as scope for // global node/edge attributes. diff --git a/tools/ffmpeg.html b/tools/ffmpeg.html index 3c8a3f1..563a011 100644 --- a/tools/ffmpeg.html +++ b/tools/ffmpeg.html @@ -181,14 +181,14 @@ <p>Following snippet allows to select a window which is then captured.</p> <pre><code class="language-bash">#!/bin/bash -echo "Click on window to record .." +echo "Click on window to record .." # Extract window size and x,y offset. video_args=$(xwininfo \ | awk '/Absolute upper-left X:/ { xoff = $4 } /Absolute upper-left Y:/ { yoff=$4 } /Width:/ { if ($2 % 2 == 1) { width=$2-1; } else { width=$2; } } /Height:/ { if ($2 % 2 == 1) { height=$2-1; } else { height=$2; } } - END { printf "-video_size %dx%d -i :0.0+%d,%d", width, height, xoff, yoff }') + END { printf "-video_size %dx%d -i :0.0+%d,%d", width, height, xoff, yoff }') ffmpeg -framerate 25 -f x11grab $video_args -pix_fmt yuv420p $@ output.mp4 </code></pre> diff --git a/tools/fish.html b/tools/fish.html index 34faca9..26c920c 100644 --- a/tools/fish.html +++ b/tools/fish.html @@ -237,16 +237,16 @@ echo {a,b}{1,2} with <code>:</code> when quoted or exported to the environment.</p> <pre><code class="language-sh">set -x BLA_PATH a:b:c:d echo $BLA_PATH # a b c d -echo "$BLA_PATH" # a:b:c:d (quoted) +echo "$BLA_PATH" # a:b:c:d (quoted) env | grep BLA_PATH # BLA_PATH=a:b:c:d (env) set FOO_PATH x y z echo $FOO_PATH # x y z -echo "$FOO_PATH" # x:y:z +echo "$FOO_PATH" # x:y:z </code></pre> <h2 id="command-handling"><a class="header" href="#command-handling">Command Handling</a></h2> <pre><code class="language-sh"># sub-commands are not run in quotes -echo "ls output: "(ls) +echo "ls output: "(ls) </code></pre> <h3 id="io-redirection"><a class="header" href="#io-redirection">I/O redirection</a></h3> <pre><code class="language-sh"># 'noclobber', fail if 'log' already exists @@ -315,7 +315,7 @@ funced foo # edit function 'foo' <li><a href="https://fishshell.com/docs/current/completions.html">Writing your own completions</a></li> <li><a href="https://fishshell.com/docs/current/cmds/complete.html"><code>complete</code></a></li> </ul> -<pre><code class="language-sh">function moose --d "my moose fn" +<pre><code class="language-sh">function moose --d "my moose fn" # h/help : short / long option (boolean) # color : only long option (boolean) # u/user= : option with required argument, only last specified is taken @@ -325,18 +325,18 @@ funced foo # edit function 'foo' or return if set -ql _flag_help - echo "usage ..." + echo "usage ..." return 0 end set -ql _flag_file - and echo "file=$_flag_file | cnt:" (count $_flag_file) + and echo "file=$_flag_file | cnt:" (count $_flag_file) set -ql _flag_color - and echo "color=$_flag_color" + and echo "color=$_flag_color" set -ql _flag_user - and echo "user=$_flag_user" + and echo "user=$_flag_user" end # Delete all previous defined completions for 'moose'. @@ -348,31 +348,31 @@ complete -c moose --no-files # Help completion. # -n specifies a conditions. The completion is only active if the command # returns 0. -complete -c moose -s h -l help -n "not __fish_contains_opt -s h help" \ - --description "Print usage help and exit" +complete -c moose -s h -l help -n "not __fish_contains_opt -s h help" \ + --description "Print usage help and exit" # File completion. # -F force complete files (overwrite --no-files). # -r requires argument. complete -c moose -s f -l file -F -r \ - --description "Specify file (can be passed multiple times)" + --description "Specify file (can be passed multiple times)" # Color completion. # -a options for completion. # -x short for -r and --no-files (-f) -complete -c moose -x -l color -a "red blue" \ - --description "Specify a color." +complete -c moose -x -l color -a "red blue" \ + --description "Specify a color." # User completion. # -a options for completion. Call a function to generate arguments. -complete -c moose -x -s u -l user -a "(__fish_complete_users)" \ - --description "Specify a user" +complete -c moose -x -s u -l user -a "(__fish_complete_users)" \ + --description "Specify a user" </code></pre> <h2 id="prompt"><a class="header" href="#prompt">Prompt</a></h2> <p>The prompt is defined by the output of the <code>fish_prompt</code> function.</p> <pre><code class="language-sh">function fish_prompt set -l cmd_ret - echo "> "(pwd) $cmd_ret" " + echo "> "(pwd) $cmd_ret" " end </code></pre> <blockquote> @@ -397,7 +397,7 @@ string split SEP STRING # math math -b hex 4096 # output dec as hex math 0x1000 # output hex as dec -math "log2(1024)" # call functions +math "log2(1024)" # call functions math -s0 7/3 # integer division (by default float) # status diff --git a/tools/gdb.html b/tools/gdb.html index 4a0dcea..44846a6 100644 --- a/tools/gdb.html +++ b/tools/gdb.html @@ -356,7 +356,7 @@ thread name <name> </code></pre> <h2 id="configuration"><a class="header" href="#configuration">Configuration</a></h2> <pre><code class="language-markdown"> set disassembly-flavor <intel | att> - Set the disassembly style "flavor". + Set the disassembly style "flavor". set pagination <on | off> Turn on/off gdb's pagination. diff --git a/tools/git.html b/tools/git.html index fe62b83..2d64c24 100644 --- a/tools/git.html +++ b/tools/git.html @@ -247,7 +247,7 @@ branch has additional commits compared to remote branch). </code></pre> <h2 id="tags"><a class="header" href="#tags">Tags</a></h2> -<pre><code class="language-markdown"> git tag -a <tname> -m "descr" ........ creates an annotated tag (full object +<pre><code class="language-markdown"> git tag -a <tname> -m "descr" ........ creates an annotated tag (full object containing tagger, date, ...) git tag -l ........................... list available tags git checkout tag/<tname> ............. checkout specific tag diff --git a/tools/gnuplot.html b/tools/gnuplot.html index a794455..85ec9bd 100644 --- a/tools/gnuplot.html +++ b/tools/gnuplot.html @@ -185,30 +185,30 @@ gnuplot [opt] opt: -p ................ persist plot window -c <file> ......... run script file - -e "<cmd1>; .." ... run cmd(s) + -e "<cmd1>; .." ... run cmd(s) </code></pre> <h2 id="frequently-used-configuration"><a class="header" href="#frequently-used-configuration">Frequently used configuration</a></h2> <pre><code class="language-sh"># Plot title. -set title "the plot" +set title "the plot" # Labels. -set xlabel "abc" -set ylabel "def" +set xlabel "abc" +set ylabel "def" # Output format, 'help set term' for all output formats. set term svg # Output file. -set output "out.svg" +set output "out.svg" # Make axis logarithmic to given base. set logscale x 2 # Change separator, default is whitespace. -set datafile separator "," +set datafile separator "," </code></pre> <h2 id="plot"><a class="header" href="#plot">Plot</a></h2> <pre><code class="language-sh"># With specific style (eg lines, linespoint, boxes, steps, impulses, ..). -plot "<data_file>" with <plot_style> +plot "<data_file>" with <plot_style> > cat data.txt 1 1 3 @@ -217,30 +217,30 @@ plot "<data_file>" with <plot_style> 4 2 2 # Plot specific column. -plot "data.txt" using 1:2, "data.txt" using 1:3 -# Equivalent using the special file "", which re-uses the previous input file. -plot "data.txt" using 1:2, "" using 1:3 +plot "data.txt" using 1:2, "data.txt" using 1:3 +# Equivalent using the special file "", which re-uses the previous input file. +plot "data.txt" using 1:2, "" using 1:3 # Plot piped data. -plot "< head -n2 data.txt" +plot "< head -n2 data.txt" # Plot with alternate title. -plot "data.txt" title "moose" +plot "data.txt" title "moose" </code></pre> <h2 id="example-multiple-data-sets-in-on-plot"><a class="header" href="#example-multiple-data-sets-in-on-plot">Example: multiple data sets in on plot</a></h2> <pre><code class="language-sh"># file: mem_lat.plot -set title "memory latency (different strides)" -set xlabel "array in KB" -set ylabel "cycles / access" +set title "memory latency (different strides)" +set xlabel "array in KB" +set ylabel "cycles / access" set logscale x 2 -plot "stride_32.txt" title "32" with linespoints, \ - "stride_64.txt" title "64" with linespoints, \ - "stride_128.txt" title "128" with linespoints, \ - "stride_256.txt" title "256" with linespoints, \ - "stride_512.txt" title "512" with linespoints +plot "stride_32.txt" title "32" with linespoints, \ + "stride_64.txt" title "64" with linespoints, \ + "stride_128.txt" title "128" with linespoints, \ + "stride_256.txt" title "256" with linespoints, \ + "stride_512.txt" title "512" with linespoints </code></pre> <p>On Linux x86_64, <a href="gnuplot/mem_lat.c"><code>mem_lat.c</code></a> provides an example which can be run as follows.</p> diff --git a/tools/pacman.html b/tools/pacman.html index e36c851..72f0052 100644 --- a/tools/pacman.html +++ b/tools/pacman.html @@ -212,7 +212,7 @@ dependencies.</p> package and sort by size.</p> <pre><code class="language-text">pacman -Qetq | xargs pacman -Qi | awk '/Name/ { name=$3 } - /Installed Size/ { printf "%8.2f%s %s\n", $4, $5, name }' | + /Installed Size/ { printf "%8.2f%s %s\n", $4, $5, name }' | sort -h </code></pre> <p>Install package into different <code>root</code> directory but keep using the default diff --git a/tools/qemu.html b/tools/qemu.html index 25cf9b3..650ae67 100644 --- a/tools/qemu.html +++ b/tools/qemu.html @@ -365,10 +365,10 @@ qemu-system-x86_64 -monitor stdio -incoming tcp:0.0.0.0:12345 qemu-system-x86_64 -monitor stdio -cdrom <iso> # Save VM state to file. -(qemu) migrate "exec:gzip -c > vm.gz" +(qemu) migrate "exec:gzip -c > vm.gz" # Load VM from file. -qemu-system-x86_64 -monitor stdio -incoming "exec: gzip -d -c vm.gz" +qemu-system-x86_64 -monitor stdio -incoming "exec: gzip -d -c vm.gz" </code></pre> <blockquote> <p>The migration source machine and the migration target machine should be @@ -380,7 +380,7 @@ launched with the <strong>same</strong> parameters.</p> -cpu host \ -enable-kvm \ -kernel <dir>/arch/x86/boot/bzImage \ - -append "earlyprintk=ttyS0 console=ttyS0 nokaslr init=/init debug" \ + -append "earlyprintk=ttyS0 console=ttyS0 nokaslr init=/init debug" \ -initrd <dir>/initramfs.cpio.gz \ ... </code></pre> @@ -396,7 +396,7 @@ trace: test clean: $(RM) test test-bin test.o </code></pre> -<pre><code class="language-x86asm">.section .text, "ax" +<pre><code class="language-x86asm">.section .text, "ax" .global _start _start: diff --git a/tools/radare2.html b/tools/radare2.html index dd868f0..199a747 100644 --- a/tools/radare2.html +++ b/tools/radare2.html @@ -208,7 +208,7 @@ > rasm2 -a x86 'mov eax, 0xdeadbeef' b8efbeadde - > rasm2 -a x86 -d "b8efbeadde" + > rasm2 -a x86 -d "b8efbeadde" mov eax, 0xdeadbeef </code></pre> diff --git a/tools/sed.html b/tools/sed.html index 5796ea9..f44fb19 100644 --- a/tools/sed.html +++ b/tools/sed.html @@ -182,6 +182,8 @@ -i edit file in place -i.bk edit file in place and create backup file (with .bk suffix, can be specified differently) + --follow-symlinks + follow symlinks when editing in place -e SCRIPT add SCRIPT to commands to be executed (can be specified multiple times) -f FILE add content of FILE to command to be executed @@ -232,6 +234,12 @@ echo -e 'aa\nbb' | sed '2aABC' echo -e 'aa\nbb' | sed '2cABC' # aa # ABC + +# Insert before pattern match. +echo -e 'aa\nbb' | sed '/bb/i 123' +# aa +# 123 +# bb </code></pre> <h3 id="substitute-lines"><a class="header" href="#substitute-lines">Substitute lines</a></h3> <pre><code class="language-sh"># Substitute by regex. @@ -244,6 +252,20 @@ echo -e 'aafooaa\ncc' | sed 's/foo/MOOSE/' # BAR # bar </code></pre> +<h3 id="edit-inplace-through-symlink"><a class="header" href="#edit-inplace-through-symlink">Edit inplace through symlink</a></h3> +<pre><code class="language-sh">touch file +ln -s file link +ls -l link +# lrwxrwxrwx 1 johannst johannst 4 Feb 7 23:02 link -> file + +sed -i --follow-symlinks '1iabc' link +ls -l link +# lrwxrwxrwx 1 johannst johannst 4 Feb 7 23:02 link -> file + +sed -i '1iabc' link +ls -l link +# -rw-r--r-- 1 johannst johannst 0 Feb 7 23:02 link +</code></pre> </main> diff --git a/tools/tmux.html b/tools/tmux.html index f5847cb..3512eeb 100644 --- a/tools/tmux.html +++ b/tools/tmux.html @@ -215,7 +215,7 @@ tmux list-panes -F '#P' -t <s>:<w> list pane IDs for window <w& tmux selectp -t <s>:<w>.<p> select pane <p> in window <w> in session <s> # Run commands -tmux send -t <s>:<w>.<p> "ls" C-m send cmds/keys to pane +tmux send -t <s>:<w>.<p> "ls" C-m send cmds/keys to pane tmux run -t <p> <sh-cmd> run shell command <sh-cmd> in background and report output on pane -t <p> </code></pre> <p>For example cycle through all panes in all windows in all sessions:</p> diff --git a/tools/zsh.html b/tools/zsh.html index acdc32f..e6ec715 100644 --- a/tools/zsh.html +++ b/tools/zsh.html @@ -198,11 +198,11 @@ $RBUFFER # Edit buffer content right to cursor # create zle widget which adds text right of the cursor function add-text() { - RBUFFER="some text $RBUFFER" + RBUFFER="some text $RBUFFER" } zle -N add-text -bindkey "^p" add-text +bindkey "^p" add-text </code></pre> <h2 id="parameter"><a class="header" href="#parameter">Parameter</a></h2> <p>Default value:</p> @@ -336,10 +336,10 @@ option should be stored.</li> <pre><code class="language-zsh">#!/bin/zsh function test() { zparseopts -D -E -A opts f=flag o: -long: - echo "flag $flag" - echo "o $opts[-o]" - echo "long $opts[--long]" - echo "pos $1" + echo "flag $flag" + echo "o $opts[-o]" + echo "long $opts[--long]" + echo "pos $1" } test -f -o OPTION --long LONG_OPT POSITIONAL @@ -361,9 +361,9 @@ The match results can be accessed via the <code>$MATCH</code> variable and <pre><code class="language-zsh">INPUT='title foo : 1234' REGEX='^title (.+) : ([0-9]+)$' if [[ $INPUT =~ $REGEX ]]; then - echo "$MATCH" # title foo : 1234 - echo "$match[1]" # foo - echo "$match[2]" # 1234 + echo "$MATCH" # title foo : 1234 + echo "$match[1]" # foo + echo "$match[2]" # 1234 fi </code></pre> <h2 id="completion"><a class="header" href="#completion">Completion</a></h2> @@ -395,7 +395,7 @@ $words[CURRENT-1] # previous word (relative to cursor position) </code></pre> <ul> <li><code>MSG</code> simple string with header message</li> -<li><code>COMP</code> array of completions where each entry is <code>"opt:description"</code></li> +<li><code>COMP</code> array of completions where each entry is <code>"opt:description"</code></li> </ul> <pre><code class="language-zsh">function _foo() { local -a opts @@ -436,16 +436,16 @@ function _foo_color() { colors+=('green:green color') colors+=('red:red color') colors+=('blue:blue color') - _describe "color" colors + _describe "color" colors } function _foo() { _arguments \ - "-c[define color]:color:->s_color" \ - "-s[select sound]:sound:(low high)" \ - "-f[select file]:file:_files" \ - "-d[select dir]:dir:_files -/" \ - "-h[help]" + "-c[define color]:color:->s_color" \ + "-s[select sound]:sound:(low high)" \ + "-f[select file]:file:_files" \ + "-d[select dir]:dir:_files -/" \ + "-h[help]" case $state in s_color) _foo_color;; @@ -459,9 +459,9 @@ arguments such as</p> </code></pre> <pre><code class="language-zsh">function _foo() { _arguments \ - "1:opt 1:(a b c)" \ - ":opt next:(d e f)" \ - "*:opt all:(u v w)" + "1:opt 1:(a b c)" \ + ":opt next:(d e f)" \ + "*:opt all:(u v w)" } </code></pre> <p>Explanation:</p> |