Warning, /frameworks/syntax-highlighting/autotests/folding/test.zsh.fold is written in an unsupported language. File is not indexed.
0001 # basic types: 0002 echo 'single quoted string' 0003 echo "double quoted string" 0004 echo $'string with esc\apes\x0din it' 0005 echo $"string meant to be translated" 0006 0007 0008 # comments: 0009 # this is a comment 0010 #this too 0011 echo this is#nt a comment 0012 dcop kate EditInterface#1 #this is 0013 grep -e "^default/linux/amd64/" |\ #this is not a comment but #this is 0014 mkdir this\ isnt\ #a\ comment 0015 mkdir this\ isnt\\\;#a\ comment 0016 mkdir this\\ #is a comment 0017 0018 # brace expansion 0019 mv my_file.{JPG,jpg} 0020 echo f.{01..100..3} f.{#..Z} f.{\{..\}} f.{$i..$j..$p} 0021 echo f.{01..100} f.{a..Z} f.{'a'..$Z} 0022 # no brace expansion 0023 echo f.{..100} f.{a..Z..} 0024 0025 0026 # special characters are escaped: 0027 echo \(output\) \&\| \> \< \" \' \* 0028 0029 0030 # variable substitution: 0031 echo $filename.ext 0032 echo $filename_ext 0033 echo ${filename}_ext 0034 echo text${array[$subscript]}.text 0035 echo text${array["string"]}.text 0036 echo short are $_, $$, $?, ${@}, etc. 0037 echo ${variable/a/d} 0038 echo ${1:-default} 0039 echo ${10} $10a 0040 echo $! $=! 0041 0042 0043 # expression subst: 0044 echo <beginfold id='1'>$((</beginfold id='1'> cd << ed + 1 <endfold id='1'>))</endfold id='1'> 0045 0046 0047 # command subst: 0048 echo <beginfold id='2'>$(</beginfold id='2'>ls -l<endfold id='2'>)</endfold id='2'> 0049 echo `cat myfile` 0050 0051 0052 # file subst: 0053 echo <beginfold id='2'>$(</beginfold id='2'><$filename<endfold id='2'>)</endfold id='2'> 0054 echo <beginfold id='2'>$(</beginfold id='2'></path/to/myfile<endfold id='2'>)</endfold id='2'> 0055 0056 # process subst: 0057 sort <(show_labels) | sed 's/a/bg' > my_file.txt 2>&1 0058 0059 0060 # All substitutions also work in strings: 0061 echo "subst ${in}side string" 'not $inside this ofcourse' 0062 echo "The result is <beginfold id='1'>$((</beginfold id='1'> $a + $b <endfold id='1'>))</endfold id='1'>. Thanks!" 0063 echo "Your homedir contains `ls $HOME |wc -l` files." 0064 0065 0066 # Escapes in strings: 0067 p="String \` with \$ escapes \" "; 0068 0069 0070 # keywords are black, builtins dark purple and common commands lighter purple 0071 set 0072 exit 0073 login 0074 0075 0076 # Other colorings: 0077 error() <beginfold id='3'>{</beginfold id='3'> 0078 cat /usr/bin/lesspipe.sh 0079 runscript >& redir.bak 0080 exec 3>&4 0081 <endfold id='3'>}</endfold id='3'> 0082 0083 0084 # do - done make code blocks 0085 while <beginfold id='1'>[</beginfold id='1'> $p -lt $q <endfold id='1'>]</endfold id='1'> 0086 <beginfold id='4'>do</beginfold id='4'> 0087 chown 0644 $file.$p 0088 <endfold id='4'>done</endfold id='4'> 0089 0090 0091 # braces as well 0092 run_prog | sort -u | 0093 <beginfold id='3'>{</beginfold id='3'> 0094 echo Header 0095 while read a b d 0096 <beginfold id='4'>do</beginfold id='4'> 0097 echo $a/$b/$c 0098 <endfold id='4'>done</endfold id='4'> 0099 echo Footer 0100 <endfold id='3'>}</endfold id='3'> 0101 0102 0103 # Any constructions can be nested: 0104 echo "A long string with <beginfold id='2'>$(</beginfold id='2'> 0105 <beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>[</beginfold id='1'> $count -gt 100 <endfold id='1'>]</endfold id='1'> ; then 0106 echo "much" 0107 else 0108 echo "not much" 0109 <endfold id='5'>fi</endfold id='5'> <endfold id='2'>)</endfold id='2'> substitutions." ; 0110 0111 0112 # Even the case construct is correctly folded: 0113 test -f blaat && 0114 <beginfold id='2'>(</beginfold id='2'> do_something 0115 <beginfold id='6'>case</beginfold id='6'> $p in 0116 *bak<beginfold id='7'>)</beginfold id='7'> 0117 do_bak $p 0118 <endfold id='7'>;;</endfold id='7'> 0119 *<beginfold id='7'>)</beginfold id='7'> 0120 dont_bak $p 0121 <endfold id='7'>;;</endfold id='7'> 0122 <endfold id='6'>esac</endfold id='6'> 0123 <endfold id='2'>)</endfold id='2'> # despite the extra parentheses in the case construction. 0124 0125 0126 # more control flow 0127 while :; 0128 break 0129 continue 0130 return 0131 <endfold id='4'>done</endfold id='4'> 0132 0133 0134 # variable assignments: 0135 DIR=/dev 0136 p=`ls` 0137 LC_ALL="nl" dcop 'kate*' 0138 _VAR=val 0139 ARR=(this is an array) 0140 ARR2=([this]=too [and]="this too") 0141 usage="$0 -- version $VERSION 0142 Multiple lines of output 0143 can be possible." 0144 ANSWER=yes # here 'yes' isn't highlighed as command 0145 0146 0147 # Some commands expect variable names, these are colored correctly: 0148 export PATH=/my/bin:$PATH BLAAT 0149 export A B D 0150 local p=3 x y='\' 0151 read x y z <<< $hallo 0152 unset B 0153 declare -a VAR1 VAR2 && exit 0154 declare less a && b 0155 declare a=(1 2) 0156 getopts :h:l::d arg 0157 read #comment 0158 let a=4+4 3+a b=c+3 d+3 d*4 # * is a glob 0159 0160 # options are recoqnized: 0161 zip -f=file.zip 0162 ./configure --destdir=/usr 0163 make destdir=/usr/ 0164 0165 0166 # [[ and [ correctly need spaces to be regarded as structure, 0167 # otherwise they are patterns (currently treated as normal text) 0168 <beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>[</beginfold id='1'> "$p" == "" <endfold id='1'>]</endfold id='1'> ; then 0169 ls /usr/bin/[a-z]* 0170 elif <beginfold id='1'>[[</beginfold id='1'> $p == 0 <endfold id='1'>]]</endfold id='1'> ; then 0171 ls /usr/share/$p 0172 <endfold id='5'>fi</endfold id='5'> 0173 0174 # Fixed: 0175 ls a[ab]* # dont try to interprete as assignment with subscript (fixed) 0176 a[ab] 0177 a[ab]=sa 0178 0179 0180 # Here documents are difficult to catch: 0181 cat > myfile << __EOF__ 0182 You're right, this is definitely no bash code 0183 But ls more $parameters should be expanded. 0184 __EOF__ 0185 0186 0187 # quoted: 0188 cat << "EOF" | egrep "this" >&4 # the rest of the line is still considered bash source 0189 You're right, this is definitely no bash code 0190 But ls more $parameters should be expanded. :-> 0191 EOF 0192 0193 cat <<bla || exit 0194 bla bla 0195 bla 0196 0197 0198 # indented: 0199 <beginfold id='5'>if</beginfold id='5'> true 0200 then 0201 cat <<- EOF 0202 Indented text with a $dollar or \$two 0203 EOF 0204 elif <beginfold id='1'>[</beginfold id='1'> -d $file <endfold id='1'>]</endfold id='1'>; then 0205 cat <<- "EOF" 0206 Indented text without a $dollar 0207 EOF 0208 <endfold id='5'>fi</endfold id='5'> 0209 0210 <beginfold id='5'>if</beginfold id='5'> ! <beginfold id='3'>{</beginfold id='3'> cmd1 && cmd2 ; <endfold id='3'>}</endfold id='3'>; then echo ok ; <endfold id='5'>fi</endfold id='5'> 0211 <beginfold id='5'>if</beginfold id='5'> ! <beginfold id='3'>{</beginfold id='3'>cmd1 && cmd2<endfold id='3'>}</endfold id='3'>; then echo ok ; <endfold id='5'>fi</endfold id='5'> 0212 <beginfold id='5'>if</beginfold id='5'> ! cmd1 arg; then echo ok ; <endfold id='5'>fi</endfold id='5'> 0213 0214 <beginfold id='6'>case</beginfold id='6'> 1 in 0215 2<beginfold id='7'>)</beginfold id='7'> echo xxx; 0216 <endfold id='7'>;;</endfold id='7'> 0217 ?<beginfold id='7'>)</beginfold id='7'> foo || yyy ; foo abc || echo abc <endfold id='7'>;;</endfold id='7'> 0218 1<beginfold id='7'>)</beginfold id='7'> echo yyy; 0219 <endfold id='7'></endfold id='7'><endfold id='6'>esac</endfold id='6'> 0220 0221 ls #should be outside of case 1 folding block 0222 0223 for i in `ls tests/auto/output/*.html`; <beginfold id='4'>do</beginfold id='4'> 0224 refFile=`echo $i | sed -e s,build,src, | sed -e s,output,reference, | sed -e s,.html,.ref.html,` 0225 cp -v $i $refFile 0226 <endfold id='4'>done</endfold id='4'> 0227 0228 ## >Settings >Configure Kate >Fonts & Colors >Highlitghing Text Styles >Scripts/Bash >Option >Change colors to some distinct color 0229 ## 1- In following line the -ucode should not be colored as option 0230 0231 pacman -Syu --needed intel-ucode grub 0232 pacman -syu --needed intel-ucode grub 0233 0234 <beginfold id='1'>[[</beginfold id='1'> $line_name =~ \{([0-9]{1,})\}\{([0-9]{1,})\}(.*) <endfold id='1'>]]</endfold id='1'> 0235 <beginfold id='1'>[[</beginfold id='1'> $name =~ (.*)_(S[0-9]{2})(E[0-9]{2,3}[a-z]{0,1})_(.*) <endfold id='1'>]]</endfold id='1'> 0236 rm /data/{hello1,hello2}/input/{bye1,$bye2}/si{a,${b},c{k,p{e,a}}}/*.non 0237 rm /data/{aa,{e,i}t{b,c} # Not closed 0238 rm /data/{aa,{e,i}t{b,c}} 0239 rm /data/{aa,{i}} 0240 rm /data{aa{bb{cc{dd}}}} 0241 rm /data{aaa`aaa}aa`aaa}a 0242 0243 # TODO ` 0244 0245 # commands 0246 abc 0247 cp 0248 : 0249 . 0250 :#nokeyword 0251 path/cmd 0252 ec\ 0253 ho 0254 2 0255 'a'c 0256 $ab 0257 ${ab}c 0258 \ a 0259 !a 0260 'a'[ 0261 \ [ 0262 !a[ 0263 a{}d 0264 a{bc}d 0265 a{b,c}d 0266 a'b'c 0267 a$bc 0268 a${bc}d 0269 a\ b 0270 a!b 0271 0272 # commands + params 0273 shortopt -ol -f/fd/fd -hfd/fds - -ol'a'b -f'a'/fd/fd -h'a'fd/fds 0274 longopt --long-a --long-b=value --file=* --file=file* --file=dir/file 0275 longopt --long-a'a'b --long'a'-b=value --fi'a'le=* 0276 noopt 3 3d -f -- -f --xx dir/file 0277 opt param#nocomment ab'a'cd ~a .a #comments 0278 path path/file dir/ / // 3/f a@/ 'a'/b d/'a'b a\ d/f f/f\ 0279 ile 0280 path ~ ~/ ~a/ . .. ./a ../a 0281 path /path/* /path/f* /path/f@ /path/f@(|) {a/b} a{b}/c a/b{c} a/{b} a/{b}c 0282 glob ? * ?f *f f* f? **/ ~/* ~* /path/f* 'a'* 'a'f/? 0283 # ksh pattern is in conflict with extended pattern 0284 extglob @ @(*) @(f*|f??(f)) f!(+(?(@(*(f)f)f)f)f)f @'a'@(|) a@(?) 0285 echo *.*~(lex|parse).[ch](^D^l1) 0286 echo /tmp/foo*(u0^@:t) *(W,X) *(%W) 0287 subs f! f!! f!s 'a'!s \( $v {a,b} {a} {a}/d {a\,} {a,} {a,\},b} ds/{a,b}sa/s 0288 0289 ls !?main 0290 ls <beginfold id='2'>$(</beginfold id='2'>echo NF<endfold id='2'>)</endfold id='2'>(:a) 0291 ls ${(s.:.)PATH} | grep '^...s' 0292 ls (#i)*.pmm 0293 ls (#ia1)README 0294 ls (*/)#bar 0295 ls (../)#junk2/down.txt(:a) 0296 ls (^(backup*|cache*|list*|tmp)/)##*(.) 0297 ls (_|)fred.php 0298 ls (dev*|fred*|joe*)/index* 0299 ls (x*~x[3-5]) 0300 ls (xx|yy) 0301 ls *(*@) 0302 ls *(+nt) 0303 ls *(.)^php~*.c~*.txt 0304 ls *(.L-20) 0305 ls *(.L0) 0306 ls *(.Om[1,5]) 0307 ls *(.^m0) 0308 ls *(.e#age 2017-10-01:00:00:00 2017-10-08:23:59:59#) /tmp 0309 ls *(.e-age 2018/09/01 2018/01/01-) 0310 ls *(.f644) 0311 ls *(.g:root:) 0312 ls *(.m-1) 0313 ls *(.mM+6) 0314 ls *(.mh+3) 0315 ls *(.mh-3) 0316 ls *(.mh3) 0317 ls *(.mw+2) 0318 ls *(.om[0,5]e-age 2017/09/01 2017/10/01-) 0319 ls *(.om[2,$]) old/ 0320 ls *(.rwg:nobody:u:root:) 0321 ls *(.u:apache:) 0322 ls *(/) 0323 ls *(/^F) 0324 ls *(L0f.go-w.) 0325 ls *(Lk+100) 0326 ls *(Lm+2) 0327 ls *(R) 0328 ls *([1,10]) 0329 ls *(^/,f44?,f.gu+w.,oL+rand,oe:"$cmd -x":P:echo::h) 0330 ls *(m4) 0331 ls *(mh0) 0332 ls *(mw3) 0333 ls *(${globqualifiers}N) 0334 ls *(\^'/') 0335 ls **.php 0336 ls **/*(#ia2)readme 0337 ls **/*(-@) 0338 ls **/*(.) 0339 ls **/*(.:g-w:) 0340 ls **/*(.Lm+10) 0341 ls **/*(D/e:'[[ -e $REPLY/index.php && -e $REPLY/index.html ]]':) 0342 ls **/*(u0WLk+10m0) 0343 ls **/*.(js|php|css)~(djr|libs|dompdf)/*~*/junk/* 0344 ls **/*.(js|php|css)~(libs|locallibs|test|dompdf)/* 0345 ls **/*.(php|inc) 0346 ls **/*.(php|inc)~(libs|locallibs)/*(.OL[1,5]) 0347 ls **/*.txt(D.om[1,5]) 0348 ls **/*~*(${~${(j/|/)fignore}})(.^*) 0349 ls **/*~*vssver.scc(.om[1,20]) 0350 ls **/*~pdf/*(.m0om[1,10]) 0351 ls **/^(vssver.scc|*.ini)(.om[1,20]) 0352 ls **/^vssver.scc(.om[1,20]) 0353 ls **/index.php~dev*(/*)## 0354 ls **/main.{php,js,css} 0355 ls *.(jpg|gif|png)(.) 0356 ls *.*(e-age 2018/06/01 now-) 0357 ls *.*(mM4) 0358 ls *.*~(lex|parse).[ch](^D^l1) 0359 ls *.*~[a-m]*(u:nobody:g:apache:.xX) 0360 ls *.c(#q:s/#%(#b)s(*).c/'S${match[1]}.C'/) 0361 ls *.c(:r) 0362 ls *.c~lex.c 0363 ls *.h~(fred|foo).h 0364 ls *.{aux,dvi,log,toc} 0365 ls *.{jpg,gif}(.N) 0366 ls *[^2].php~*template* 0367 ls *y(2|).cfm 0368 ls *y2#.cfm 0369 ls *~*.*(.) 0370 ls ./*(Om[1,-11]) 0371 ls ./**/*(/od) 2> /dev/null 0372 ls ./**/*.(php|inc|js) 0373 ls ./**/*.{inc,php} 0374 ls ./*.back(#qN) 0375 ls ./{html,live}/**/*.(php|inc|js)~(**/wiki|**/dompdf)/* 0376 ls /path/**/*(.a+10e{'stat -sA u +uidr $REPLY; f[$u]="$f[$u]$REPLY"'}) 0377 ls <-> <-6> <4-> <4-5> 0<-> {1..5} {2,3} {00..03} (4|5) [3-4] [3-47-8] 0? ?2 *2 0378 ls =some_file 0379 ls DATA_[0-9](#c,4).csv 0380 ls DATA_[0-9](#c3).csv 0381 ls DATA_[0-9](#c4,).csv 0382 ls DATA_[0-9](#c4,7).csv 0383 ls PHP*/**/*.php 0384 ls [01]<->201[45]/Daily\ report*.csv(e#age 2014/10/22 now#) 0385 ls ^*.(css|php)(.) 0386 ls ^?*.* 0387 ls ^?*.*(D) 0388 ls ^?*.[^.]*(D) 0389 ls a(#c3).txt 0390 ls file<20-> 0391 ls foot(fall)#.pl 0392 ls fred<76-88>.pl 0393 ls fred<76->.pl 0394 ls fred^erick* 0395 ls fred{09..13}.pl 0396 ls fred{joe,sid}.pl 0397 ls x*~(x3|x5) 0398 ls x*~^x[3,5] 0399 ls x*~x[3,5] 0400 ls x^[3,5] 0401 ls y2#.cfm y{2,}.cfm y(2|).cfm {y2,y}.cfm (y|y2).cfm y*.cfm 0402 ls {^dev*,}/index.php(.N) 0403 ls {_,}fred.php 0404 ls {p..q}<5->{1..4}.(#I)php(.N) 0405 ls ~1/*(.om[1]) 0406 ls **/*.php~*junk*/* #find all calls to mail, ignoring junk directories 0407 ls **/(*.cfm~(ctpigeonbot|env).cfm) 0408 ls **/*.{js,php,css}~(libs|temp|tmp|test)/* 0409 ls */*.php~libs/*~temp/*~test/* 0410 ls **/(*.cfm~(ctpigeonbot|env).cfm)~*((#s)|/)junk*/*(.) 0411 ls **/*.(js|php|css)~(libs|temp|test)/* 0412 ls **/*.(js|php|css)~libs/*~temp/*~test/* 0413 ls report/**/*.{inc,php} # searching for a php variable 0414 ls *.log(Ne-age 2006/10/04:10:15 2006/10/04:12:45-) 0415 ls <beginfold id='2'>$(</beginfold id='2'>echo /c/aax/*(.om[1])<endfold id='2'>)</endfold id='2'>(+cyg) & 0416 ls *~vssver.scc(.om[1]) 0417 ls /c/aax/*(.om[1]+cyg) 0418 ls ${(ps:\0:)"<beginfold id='2'>$(</beginfold id='2'>grep -lZ foobar ./*.txt(.)<endfold id='2'>)</endfold id='2'>"} 0419 ls [[[[]]x* 0420 0421 2 - f -f 0422 !a -f 0423 'a' -f 0424 $a -f 0425 ! cmd 0426 0427 # coproc command (#460301) 0428 coproc ls thisfiledoesntexist 2>&1 0429 coproc <beginfold id='3'>{</beginfold id='3'> ls thisfiledoesntexist; read; <endfold id='3'>}</endfold id='3'> 2>&1 0430 0431 # redirections (prefix) 0432 <<<s cat 0433 <<<'s' cat 0434 <<<'s's cat 0435 <<<s's's cat 0436 <<<s${s}s cat 0437 <<< s${s}s cat 0438 >&2 cat 0439 <f cat 0440 2>3 cat 0441 2>&3 cat 0442 2>& 3 cat 0443 2>f cat 0444 &>f cat 0445 2>>(xless) cat 0446 2<<(xless) cat 0447 2>>(xless)cat 0448 2<<(xless)cat 0449 0450 # redirections 0451 cat f>2 0452 cat d/f>2 0453 cat d/f >2 0454 cat d/f >& 2 0455 cat >2 d/f 0456 cat > 2 0457 cat <(echo) <(echo a) <(echo a/f) <(echo ) <(echo a ) <(echo a/f ) 0458 cat 2>>(xless) 0459 cat 2<<(xless) 0460 cat 2>&1 &>f &>>f 2<&1- 2<>f 2<<heredoc 0461 bla bla 0462 heredoc 0463 <<-'h' cat 0464 bla 0465 h 0466 <<"'" cat 0467 bla 0468 ' 0469 r=<beginfold id='2'>$(</beginfold id='2'>xxx $@ 2>&1<endfold id='2'>)</endfold id='2'> 0470 0471 # branches 0472 cat a|cat 0473 cat a&cat 0474 cat a||cat 0475 cat a&&cat 0476 cat a;cat 0477 cat a | cat 0478 cat a & cat 0479 cat a || cat 0480 cat a && cat 0481 cat a ; cat 0482 cat a'a';cat 0483 0484 # substitutions 0485 echo '' 'a' '\' "" "a" "\\" "$a" "a""a"'a''a' a'b'c a"b"c a$'\n'c 0486 echo a!bc a{a}b a{b,c}d a{b,{d,e}}d a\ b 0487 echo a$bc a$b/c a${b}c a<beginfold id='1'>$((</beginfold id='1'>b-3<endfold id='1'>))</endfold id='1'>c a<beginfold id='2'>$(</beginfold id='2'>b<endfold id='2'>)</endfold id='2'>c a<beginfold id='2'>$(</beginfold id='2'>a b c<endfold id='2'>)</endfold id='2'>c 0488 echo ${a[*]} ${a[@]} ${a[${b}]} ${a:-x$z} ${a/g} ${a//f/f} ${a//f*/f*} 0489 echo ${!} ${!a} ${#a[1]} ${a:1:$b} <beginfold id='1'>$((</beginfold id='1'>++i,i--<endfold id='1'>))</endfold id='1'> 0490 echo ${a:^v} ${=a:/#%a#?*/bla} ${x#??(#i)} ${das:-{}<a.zsh} 0491 echo ${(f)"<beginfold id='2'>$(</beginfold id='2'><$1<endfold id='2'>)</endfold id='2'>"} ${${(Az)l}[$2]} ${(f)"<beginfold id='2'>$(</beginfold id='2'>eval ${(q)@[2,$]}<endfold id='2'>)</endfold id='2'>"} 0492 echo ${(@)foo} ${(@)foo[1,2]} ${${(A)name}[1]} ${(AA)=name=...} ${(Q)${(z)foo}} 0493 echo ${(ps.$sep.)val} ${(ps.${sep}.)val} ${(s.$sep.)val} ${(s.)(.)val} 0494 echo ${(pr:2+3::_::$d:)var} ${(r:2+3::_::$d:)var} 0495 echo ${${:-=cat}:h} 0496 $foo:h34:a:gs/dfs/fds/:s/fds/d'd'f xyz $foo: $foo:O $foo:A 0497 3=$foo:QQQ xyz $a[3,$]:h3:t1:e 0498 echo ${${~foo}//\*/*.c} 0499 echo !$ !!:$ !* !!:* !-2:2 !:-3 !:2* !:2- !:2-3 !^ !:1 !!:1 0500 echo "$bg[blue]$fg[yellow]highlight a message" 0501 echo "$bg[red]$fg[black]${(l:42::-:)}" 0502 echo "${${(@)foo[2,4]}[2]}" 0503 echo "${(j::)${(@Oa)${(s::):-hello}}}" 0504 echo "${(j::)${(@Oa)${(s::):-hello}}}" 0505 echo "<a href='$url'>$anchortext</a>" 0506 echo <beginfold id='1'>$((</beginfold id='1'> sin(1/4.0)**2 + cos(1/4.0)**2 - 1 <endfold id='1'>))</endfold id='1'> 0507 echo $a[${RANDOM}%1000] $a[${RANDOM}%11+10] 0508 echo $convtable[158] 0509 echo ${array[0]: -7 : + 22 } ${array[1]: num } 0510 echo ${parameter##word} ${parameter%%word} 0511 echo $f ' # $fred' 0512 echo $f:e $f:h $f:h:h $f:r $f:t $f:t:r $file:r 0513 echo ${(C)foo:gs/-/ /:r} ${(M)0%%<->} ${(j/x/s/x/)foo} ${(l:$COLUMNS::-:)} 0514 echo ${(l:3::0:)${RANDOM}} ${(s/x/)foo%%1*} ${0##*[!0-9]} 0515 echo ${a:2:2} ${a:2} ${a[1,3]} ${d/#?/} ${d/%?/} ${d[1,-2]} ${d[2,$]} 0516 echo ${d[2,-1]} ${file##*/} ${file%.*} ${texfilepath%/*.*} *(f:u+rx,o-x:) 0517 echo *(f:u+rx:) **/*(@-^./=%p) **/*(@-^./=%p) convert_csv.php(:a) 0518 cd <beginfold id='2'>$(</beginfold id='2'>locate -l1 -r "/zoo.txt$"<endfold id='2'>)</endfold id='2'>(:h) # cd to directory of first occurence of a file zoo.txt 0519 cd ${<beginfold id='2'>$(</beginfold id='2'>!!<endfold id='2'>)</endfold id='2'>[3]:h} # cd to 3rd in list 0520 cd ${<beginfold id='2'>$(</beginfold id='2'>locate zoo.txt<endfold id='2'>)</endfold id='2'>[1]:h} 0521 cd ${drive}/inetpub/wwwdev/www.some.co.uk/ 0522 cd **/*.php(.om[1]:h) # cd to directory of newest php file 0523 cd - 0524 cd /tmp/test/;touch {1..5} {6,7,8,12} {00..03} 0525 cd ~www/admin 0526 chmod g+w **/* 0527 chmod someuser /**/*(D^u:${(j.:u:.)${(f)"<beginfold id='2'>$(</beginfold id='2'></etc/passwd<endfold id='2'>)</endfold id='2'>"}%%:*}:) 0528 cp *.mp3(mh-4) /tmp # copy files less than 4 hours old 0529 cp -a file1 file # -a transfer permissions etc of file1 to file2preserve 0530 file **/*(D@) | fgrep broken 0531 file **/*(D@) | fgrep broken 0532 file=${1/#\//C:\/} # substitute / with c:/ Beginning of string 0533 file=${1/%\//C:\/} # substitute / with c:/ End of string 0534 file=${1/\//C:\/} # substitute / with c:/ ANYWHERE in string 0535 filelst+=($x) 0536 filelst[<beginfold id='1'>$((</beginfold id='1'>$#filelst+1<endfold id='1'>))</endfold id='1'>]=$x 0537 files=(${(f)"<beginfold id='2'>$(</beginfold id='2'>egrepcmd1l<endfold id='2'>)</endfold id='2'>"} ) 0538 files=(${(f)"<beginfold id='2'>$(</beginfold id='2'>ls *$**<endfold id='2'>)</endfold id='2'>"}(.N)) # ")` 0539 files=(**/*(ND.L0m+0m-2)) 0540 mkdir $f:h;touch $f 0541 mv Licence\ to\ Print\ Money.pdf !#^:gs/\\ // 0542 path=(${path:#$path_to_remove}) 0543 path=(${path:|excl}) 0544 pattern=${(b)str} 0545 pattern=${(q)str} 0546 print "$aa[one\"two\"three\"quotes]" 0547 print "$bg[cyan]$fg[blue]Welcome to man zsh-lovers" >> $TTY 0548 print <beginfold id='1'>$((</beginfold id='1'> [#8] x = 32, y = 32 <endfold id='1'>))</endfold id='1'> 0549 print <beginfold id='1'>$((</beginfold id='1'>${${(z)${(f)"<beginfold id='2'>$(</beginfold id='2'>dirs -v<endfold id='2'>)</endfold id='2'>"}[-1]}[1]} + 1<endfold id='1'>))</endfold id='1'> # or 0550 print <beginfold id='2'>$(</beginfold id='2'>history -n -1|sed 's/.* //'<endfold id='2'>)</endfold id='2'> 0551 print $aa[(e)*] 0552 print $ass_array[one] 0553 print $x $y 0554 print ${#path[1]} # length of first element in path array 0555 print ${#path} # length of "path" array 0556 print ${<beginfold id='2'>$(</beginfold id='2'> date <endfold id='2'>)</endfold id='2'>[2,4]} # Print words two to four of output of ’date’: 0557 print ${<beginfold id='2'>$(</beginfold id='2'>/sbin/ifconfig tun0<endfold id='2'>)</endfold id='2'>[6]} 0558 print ${${<beginfold id='2'>$(</beginfold id='2'> LC_ALL=C /sbin/ifconfig lo <endfold id='2'>)</endfold id='2'>[6]}#addr:} 0559 print ${${<beginfold id='2'>$(</beginfold id='2'>LC_ALL=C /sbin/ifconfig eth0<endfold id='2'>)</endfold id='2'>[7]}:gs/addr://} 0560 print ${${(Cs:-:):-fred-goat-dog.jpg}%.*} 0561 print ${${(z)<beginfold id='2'>$(</beginfold id='2'>history -n -1<endfold id='2'>)</endfold id='2'>}[-1]} 0562 print ${${(z)history[<beginfold id='1'>$((</beginfold id='1'>HISTCMD-1<endfold id='1'>))</endfold id='1'>]}[-1]} 0563 print ${(L)s// /-}.jpg 0564 print ${(L)s:gs/ /-/}.jpg 0565 print ${(S)foo//${~sub}/$rep} 0566 print ${(k)ass_array} # prints keys 0567 print ${(v)ass_array} # prints values 0568 print ${JUNK/%./_} # substitute last . for a _ 0569 print ${JUNK/.(#e)/_} # substitute last . for a _ 0570 print ${arr//(#m)[aeiou]/${(U)MATCH}} 0571 print ${array:t} 0572 print ${foo%%$'\n'} # strip out a trailing carriage return 0573 print ${foo//$'\n'} # strip out any carriage returns (some systems use \r) 0574 print ${foo//${~sub}/$rep} 0575 print ${foo: 1 + 2} 0576 print ${foo:<beginfold id='1'>$((</beginfold id='1'> 1 + 2<endfold id='1'>))</endfold id='1'>} 0577 print ${foo:<beginfold id='2'>$(</beginfold id='2'>echo 1 + 2<endfold id='2'>)</endfold id='2'>} 0578 print ${foo:3} 0579 print ${param:&} (last substitute) 0580 print ${somevar//[^[:alnum:]]/_} # replace all non-alphanumerics with _ the // indicates global substitution 0581 print ${string[(r)d?,(r)h?]} 0582 print '\e[1;34m fred' 0583 print (*/)#zsh_us.ps 0584 print *(e:age 2006/10/04 2006/10/09:) 0585 print **/*(/^F) | xargs -n1 -t rmdir #delete empty directories 0586 print *.c(e_'[[ ! -e $REPLY:r.o ]]'_) 0587 print -C 1 $X # print each array element on it's own line 0588 print -l "${(s.:.)line}" 0589 print -l $MATCH X $match 0590 print -l $accum 0591 print -l *(n:t) # order by name strip directory 0592 print -l **/*(-@) 0593 print -l **/*(On:t) # recursive reverse order by name, strip directory 0594 print -r -- $^X.$^Y 0595 print -r -- ${(qq)m} > $nameoffile # save it 0596 print -rC1 /tmp/foo*(u0^@:t) 0597 print -rC1 b*.pro(#q:s/pro/shmo/)(#q.:s/builtin/shmiltin/) 0598 print -rC2 -- ${1:[...]}/*(D:t) 0599 print -rl $HOME/${(l:20::?:)~:-}* 0600 print -rl -- ${${=mapfile[/etc/passwd]}:#*(#i)root*} 0601 print -rl /**/*~^*/path(|/*) 0602 print {<beginfold id='1'>$((</beginfold id='1'>##n<endfold id='1'>))</endfold id='1'>..<beginfold id='1'>$((</beginfold id='1'>##y<endfold id='1'>))</endfold id='1'>}P\ 10P | dc 0603 print root@192.168.168.157:${PWD/test/live}v 0604 0605 0606 # conditions 0607 <beginfold id='1'>[</beginfold id='1'> a <endfold id='1'>]</endfold id='1'> 0608 <beginfold id='1'>[</beginfold id='1'> -f f'f'f <endfold id='1'>]</endfold id='1'> 0609 <beginfold id='1'>[</beginfold id='1'> -f f]'f'f] <endfold id='1'>]</endfold id='1'> 0610 <beginfold id='1'>[</beginfold id='1'> -t 13 <endfold id='1'>]</endfold id='1'> 0611 <beginfold id='1'>[</beginfold id='1'> -t 13] <endfold id='1'>]</endfold id='1'> 0612 <beginfold id='1'>[</beginfold id='1'> -t 13] <endfold id='1'>]</endfold id='1'> 0613 <beginfold id='1'>[</beginfold id='1'> -v abc <endfold id='1'>]</endfold id='1'> 0614 <beginfold id='1'>[</beginfold id='1'> -z abc <endfold id='1'>]</endfold id='1'> 0615 <beginfold id='1'>[</beginfold id='1'> abc -ef abc <endfold id='1'>]</endfold id='1'> 0616 <beginfold id='1'>[</beginfold id='1'> abc -ef abc <endfold id='1'>]</endfold id='1'> 0617 <beginfold id='1'>[</beginfold id='1'> abc-ef -ef abc-ef <endfold id='1'>]</endfold id='1'> 0618 <beginfold id='1'>[</beginfold id='1'> abc == abc <endfold id='1'>]</endfold id='1'> 0619 <beginfold id='1'>[</beginfold id='1'> abc < abc <endfold id='1'>]</endfold id='1'> 0620 <beginfold id='1'>[</beginfold id='1'> abc -eq abc <endfold id='1'>]</endfold id='1'> 0621 <beginfold id='1'>[[</beginfold id='1'> abc -eq abc <endfold id='1'>]]</endfold id='1'> 0622 <beginfold id='1'>[</beginfold id='1'> 1+2 -eq 1+2 <endfold id='1'>]</endfold id='1'> 0623 <beginfold id='1'>[[</beginfold id='1'> 1+2 -eq 1+2 <endfold id='1'>]]</endfold id='1'> 0624 <beginfold id='1'>[</beginfold id='1'> a = b <endfold id='1'>c</endfold id='1'> ] 0625 <beginfold id='1'>[</beginfold id='1'> -z 1 -a 1 -eq 1 <endfold id='1'>]</endfold id='1'> 0626 <beginfold id='1'>[</beginfold id='1'> 2 -eq 1 -o 1 -eq 1 <endfold id='1'>]</endfold id='1'> 0627 <beginfold id='2'>(</beginfold id='2'> <beginfold id='1'>[</beginfold id='1'> a = b <endfold id='1'>]</endfold id='1'> <endfold id='2'>)</endfold id='2'> 0628 <beginfold id='2'>(</beginfold id='2'><beginfold id='1'>[</beginfold id='1'> a = b <endfold id='1'>]</endfold id='1'><endfold id='2'>)</endfold id='2'> 0629 <beginfold id='1'>[[</beginfold id='1'> a = b <endfold id='1'>c</endfold id='1'> ]] 0630 <beginfold id='1'>[[</beginfold id='1'> x =~ a(b c|$)' '{1,}[a[.digit.]] <endfold id='1'>]]</endfold id='1'> 0631 <beginfold id='1'>[[</beginfold id='1'> x =~ [ <endfold id='1'>] </endfold id='1'>]] 0632 <beginfold id='1'>[[</beginfold id='1'> x =~ ([ ]) <endfold id='1'>]]</endfold id='1'> 0633 <beginfold id='1'>[[</beginfold id='1'> x =~ [ <endfold id='1'>]]</endfold id='1'> 0634 <beginfold id='1'>[[</beginfold id='1'> x =~ ([) <endfold id='1'>]]</endfold id='1'> 0635 <beginfold id='1'>[[</beginfold id='1'> (a =~ a) <endfold id='1'>]]</endfold id='1'> 0636 <beginfold id='1'>[[</beginfold id='1'> (a =~ 0637 a) <endfold id='1'>]]</endfold id='1'> 0638 <beginfold id='1'>[[</beginfold id='1'> a =~ a || a -eq 2 <endfold id='1'>]]</endfold id='1'> 0639 <beginfold id='1'>[[</beginfold id='1'> (a =~ a) || a -eq 2 <endfold id='1'>]]</endfold id='1'> 0640 <beginfold id='1'>[[</beginfold id='1'> a<b <endfold id='1'>]]</endfold id='1'> 0641 <beginfold id='1'>[[</beginfold id='1'> a <b <endfold id='1'>]]</endfold id='1'> 0642 <beginfold id='1'>[[</beginfold id='1'> a< b <endfold id='1'>]]</endfold id='1'> 0643 <beginfold id='1'>[[</beginfold id='1'> a < b <endfold id='1'>]]</endfold id='1'> 0644 <beginfold id='1'>[[</beginfold id='1'>(! -d .)<endfold id='1'>]]</endfold id='1'> 0645 <beginfold id='1'>[[</beginfold id='1'> ! -d . <endfold id='1'>]]</endfold id='1'> 0646 <beginfold id='1'>[[</beginfold id='1'> !(-d .) <endfold id='1'>]]</endfold id='1'> 0647 <beginfold id='1'>[[</beginfold id='1'> -f a || -f b <endfold id='1'>]]</endfold id='1'> 0648 <beginfold id='1'>[[</beginfold id='1'> -f a||-f b <endfold id='1'>]]</endfold id='1'> 0649 <beginfold id='1'>[[</beginfold id='1'> ! (a -eq b) <endfold id='1'>]]</endfold id='1'> 0650 <beginfold id='1'>[</beginfold id='1'> -d `echo .`] <endfold id='1'>]</endfold id='1'> 0651 <beginfold id='1'>[[</beginfold id='1'> -d `echo .`]] <endfold id='1'>]]</endfold id='1'> 0652 <beginfold id='1'>[[</beginfold id='1'> a != b && ${a}a = b${b} <endfold id='1'>]]</endfold id='1'> 0653 <beginfold id='1'>[[</beginfold id='1'> 0654 1 -eq 2 0655 <endfold id='1'>]]</endfold id='1'> 0656 <beginfold id='1'>[[</beginfold id='1'> 0657 1 0658 -eq 0659 2 0660 <endfold id='1'>]]</endfold id='1'> 0661 <beginfold id='1'>[[</beginfold id='1'> -""(#i)* == $x <endfold id='1'>]]</endfold id='1'> 0662 <beginfold id='1'>[[</beginfold id='1'> <endfold id='1'>]]</endfold id='1'> 0663 <beginfold id='1'>[[</beginfold id='1'> -f <endfold id='1'>]]</endfold id='1'> 0664 <beginfold id='1'>[[</beginfold id='1'> -f <0-99> <endfold id='1'>]]</endfold id='1'> 0665 <beginfold id='1'>[[</beginfold id='1'> $1 == <-> <endfold id='1'>]]</endfold id='1'> 0666 <beginfold id='1'>[[</beginfold id='1'> ?*<0-99> = <0-99> <endfold id='1'>]]</endfold id='1'> 0667 <beginfold id='1'>[[</beginfold id='1'> -f = ?*<0-99> <endfold id='1'>]]</endfold id='1'> 0668 <beginfold id='1'>[[</beginfold id='1'> a/sa[s = dsad?*<0-9>dsa$ds <endfold id='1'>]]</endfold id='1'> 0669 <beginfold id='1'>[[</beginfold id='1'> a/sa[s = dsad?*<0-9>ds/a$ds <endfold id='1'>]]</endfold id='1'> 0670 <beginfold id='1'>[[</beginfold id='1'> a =~ <1-2>a<->a<-2>a<2->a([!d]a?s[x[:alnum:]]|d?)p <endfold id='1'>]]</endfold id='1'> 0671 <beginfold id='1'>[[</beginfold id='1'> -n file*(#qN) <endfold id='1'>]]</endfold id='1'> 0672 <beginfold id='1'>[[</beginfold id='1'> ( -f foo || -f bar ) && $report = y* <endfold id='1'>]]</endfold id='1'> && print File exists. 0673 <beginfold id='1'>[[</beginfold id='1'> $str = ${~pattern} <endfold id='1'>]]</endfold id='1'> 0674 <beginfold id='1'>[[</beginfold id='1'> $str = ${~pattern} <endfold id='1'>]]</endfold id='1'> 0675 <beginfold id='1'>[[</beginfold id='1'> "?" = ${(~j.|.)array} <endfold id='1'>]]</endfold id='1'> 0676 <beginfold id='2'>(</beginfold id='2'> <beginfold id='1'>[[</beginfold id='1'> a = b <endfold id='1'>]]</endfold id='1'> <endfold id='2'>)</endfold id='2'> 0677 <beginfold id='2'>(</beginfold id='2'><beginfold id='1'>[[</beginfold id='1'> a = b <endfold id='1'>]]</endfold id='1'><endfold id='2'>)</endfold id='2'> 0678 0679 <beginfold id='1'>[[</beginfold id='1'> #comm1 0680 #comm2 0681 ! #comm3 0682 p[1] #comm4 0683 == #comm5 0684 p[2] #comm6 0685 #comm7 0686 #comm8 0687 <endfold id='1'>]]</endfold id='1'> 0688 0689 <beginfold id='1'>[[</beginfold id='1'> #comm1 0690 #comm2 0691 -f #comme3 0692 #comm4 0693 p[2] #comm5 0694 #comm6 0695 #comm7 0696 <endfold id='1'>]]</endfold id='1'> 0697 0698 <beginfold id='1'>[</beginfold id='1'> a -eq 2 <endfold id='1'>]</endfold id='1'> || <beginfold id='1'>[</beginfold id='1'> a -eq 2] <endfold id='1'>]</endfold id='1'> && <beginfold id='1'>[[</beginfold id='1'> a -eq 2 <endfold id='1'>]]</endfold id='1'> || <beginfold id='1'>[[</beginfold id='1'> a != b <endfold id='1'>]]</endfold id='1'>; 0699 <beginfold id='1'>[</beginfold id='1'> a -eq 2 <endfold id='1'>]</endfold id='1'>||<beginfold id='1'>[</beginfold id='1'> a -eq 2] <endfold id='1'>]</endfold id='1'>&&<beginfold id='1'>[[</beginfold id='1'> a -eq 2 <endfold id='1'>]]</endfold id='1'>||<beginfold id='1'>[[</beginfold id='1'> a != b <endfold id='1'>]]</endfold id='1'>; 0700 0701 <beginfold id='1'>((</beginfold id='1'>3+1+a+$c*(x) & 0x4342_2fd+03-08_5/23#D9a@_^8<endfold id='1'>))</endfold id='1'> 0702 <beginfold id='1'>((</beginfold id='1'>1.3/(2-(a-4))<endfold id='1'>))</endfold id='1'> 0703 0704 # they are not arithmetic evaluations... 0705 <beginfold id='2'>(</beginfold id='2'><beginfold id='2'>(</beginfold id='2'>cmd && cmd<endfold id='2'>)</endfold id='2'> || cmd<endfold id='2'>)</endfold id='2'> 0706 <beginfold id='2'>$(</beginfold id='2'><beginfold id='2'>(</beginfold id='2'>cmd && cmd<endfold id='2'>)</endfold id='2'> || cmd<endfold id='2'>)</endfold id='2'> 0707 <beginfold id='1'>((</beginfold id='1'>cmd && 0708 cmd<endfold id='1'></endfold id='1'><beginfold id='2'>)</beginfold id='2'> || cmd<endfold id='2'>)</endfold id='2'> 0709 <beginfold id='1'>$((</beginfold id='1'>cmd && 0710 cmd<endfold id='1'></endfold id='1'><beginfold id='2'>)</beginfold id='2'> || cmd<endfold id='2'>)</endfold id='2'> 0711 0712 print <beginfold id='1'>$((</beginfold id='1'> [#_] sqrt(1e7) 0__39 1423e23 .2443 43.34 34.43e4 .d<endfold id='1'>))</endfold id='1'> 0713 0714 <beginfold id='3'>{</beginfold id='3'> echo 0715 echo 0716 <endfold id='3'>}</endfold id='3'> 0717 <beginfold id='3'>{</beginfold id='3'> echo ; <endfold id='3'>}</endfold id='3'> 0718 <beginfold id='3'>{</beginfold id='3'> echo <endfold id='3'>}</endfold id='3'> 0719 <beginfold id='3'>{</beginfold id='3'>echo<endfold id='3'>}</endfold id='3'> 0720 <beginfold id='3'>{</beginfold id='3'>ls f<endfold id='3'>}</endfold id='3'> always <beginfold id='3'>{</beginfold id='3'>ls<endfold id='3'>}</endfold id='3'> 0721 <beginfold id='3'>{</beginfold id='3'>echo {a}<endfold id='3'>}</endfold id='3'> 0722 }echo 0723 echo {a} {a/b} a{b}/c a/b{c} a/{b} a/{b}c d/{{a}} 0724 echo {a{a{a}}} 0725 echo {a{a{a}a}a}a 0726 echo {a 0727 echo a} 0728 echo{a} 0729 echo{a{a{a}}} 0730 echo{a{a{a}a}a}a 0731 echo{a 0732 echo} 0733 0734 <beginfold id='3'>{</beginfold id='3'> <beginfold id='3'>{</beginfold id='3'>echo a<endfold id='3'>}</endfold id='3'> <endfold id='3'>}</endfold id='3'> 0735 <beginfold id='3'>{</beginfold id='3'> <beginfold id='3'>{</beginfold id='3'>echo a}a<endfold id='3'>}</endfold id='3'> <endfold id='3'>}</endfold id='3'> 0736 <beginfold id='3'>{</beginfold id='3'> <beginfold id='3'>{</beginfold id='3'> echo a <endfold id='3'>}</endfold id='3'> <endfold id='3'>}</endfold id='3'> 0737 <beginfold id='3'>{</beginfold id='3'> <beginfold id='3'>{</beginfold id='3'> echo a}a <endfold id='3'>}</endfold id='3'> <endfold id='3'>}</endfold id='3'> 0738 0739 <beginfold id='3'>{</beginfold id='3'> <beginfold id='3'>{</beginfold id='3'>echo a/b<endfold id='3'>}</endfold id='3'> <endfold id='3'>}</endfold id='3'> 0740 <beginfold id='3'>{</beginfold id='3'> <beginfold id='3'>{</beginfold id='3'>echo a/b}a<endfold id='3'>}</endfold id='3'> <endfold id='3'>}</endfold id='3'> 0741 <beginfold id='3'>{</beginfold id='3'> <beginfold id='3'>{</beginfold id='3'> echo a/b <endfold id='3'>}</endfold id='3'> <endfold id='3'>}</endfold id='3'> 0742 <beginfold id='3'>{</beginfold id='3'> <beginfold id='3'>{</beginfold id='3'> echo a/b}a <endfold id='3'>}</endfold id='3'> <endfold id='3'>}</endfold id='3'> 0743 0744 <beginfold id='3'>{</beginfold id='3'> <beginfold id='3'>{</beginfold id='3'>echo >a/b<endfold id='3'>}</endfold id='3'> <endfold id='3'>}</endfold id='3'> 0745 <beginfold id='3'>{</beginfold id='3'> <beginfold id='3'>{</beginfold id='3'>echo >a/b}a<endfold id='3'>}</endfold id='3'> <endfold id='3'>}</endfold id='3'> 0746 <beginfold id='3'>{</beginfold id='3'> <beginfold id='3'>{</beginfold id='3'> echo >a/b <endfold id='3'>}</endfold id='3'> <endfold id='3'>}</endfold id='3'> 0747 <beginfold id='3'>{</beginfold id='3'> <beginfold id='3'>{</beginfold id='3'> echo >a/b}a <endfold id='3'>}</endfold id='3'> <endfold id='3'>}</endfold id='3'> 0748 0749 <beginfold id='3'>{</beginfold id='3'>ab}c<endfold id='3'>}</endfold id='3'> 0750 <beginfold id='3'>{</beginfold id='3'>a,b}c<endfold id='3'>}</endfold id='3'> 0751 <beginfold id='3'>{</beginfold id='3'>ab<endfold id='3'>}</endfold id='3'>[} 0752 <beginfold id='3'>{</beginfold id='3'>a,b<endfold id='3'>}</endfold id='3'>[} 0753 0754 cat >f{oo,ar} 0755 0756 <beginfold id='2'>(</beginfold id='2'>echo ; echo<endfold id='2'>)</endfold id='2'> 0757 <beginfold id='2'>(</beginfold id='2'>echo 0758 echo<endfold id='2'>)</endfold id='2'> 0759 <beginfold id='2'>(</beginfold id='2'>echo a<endfold id='2'>)</endfold id='2'> 0760 test a -eq b 0761 0762 # functions 0763 a() <beginfold id='3'>{</beginfold id='3'> echo x; <endfold id='3'>}</endfold id='3'> 0764 a () <beginfold id='3'>{</beginfold id='3'> echo x; <endfold id='3'>}</endfold id='3'> 0765 function f <beginfold id='3'>{</beginfold id='3'> echo x; <endfold id='3'>}</endfold id='3'> 0766 kde.org() <beginfold id='3'>{</beginfold id='3'> echo x; <endfold id='3'>}</endfold id='3'> 0767 --func() <beginfold id='3'>{</beginfold id='3'> echo x; <endfold id='3'>}</endfold id='3'> 0768 noglob function f <beginfold id='3'>{</beginfold id='3'> echo x; <endfold id='3'>}</endfold id='3'> 0769 0770 # variables 0771 a=(a b c) 0772 a='a' 0773 a+=b 0774 a[1]='a' 0775 a[$i]='x' 0776 a[<beginfold id='1'>$((</beginfold id='1'> 0777 2+4 0778 <endfold id='1'>))</endfold id='1'>]='x' 0779 a=([a]=2 `echo` -s > 'ds') 0780 a=(#comment 0781 value#nocomment #comment) 0782 ) 0783 a=a cat 0784 a=`ls` cat 0785 a[2+3][d]=5 0786 0787 # control structure 0788 for name in a b c {d,e} ; <beginfold id='4'>do</beginfold id='4'> echo ; <endfold id='4'>done</endfold id='4'> 0789 for name; <beginfold id='4'>do</beginfold id='4'> echo ; <endfold id='4'>done</endfold id='4'> 0790 for name do echo ; <endfold id='4'>done</endfold id='4'> 0791 for ((i=0;i<5;++i)) ; <beginfold id='4'>do</beginfold id='4'> echo $i ; <endfold id='4'>done</endfold id='4'> 0792 for ((i=1;$#A[i];i++)) echo $A[$i] 0793 for c ({1..50}) <beginfold id='3'>{</beginfold id='3'>php ./test.php; sleep 5;<endfold id='3'>}</endfold id='3'> 0794 for count in {1..10}; <beginfold id='4'>do</beginfold id='4'> echo $count ; <endfold id='4'>done</endfold id='4'> 0795 for f (*(.)) mv $f fixed_$f 0796 for f (**/x) cp newx $f 0797 for f (*.txt) <beginfold id='3'>{</beginfold id='3'> echo $f <endfold id='3'>}</endfold id='3'> 0798 for f in **/x; <beginfold id='4'>do</beginfold id='4'>;cp newx $f; <endfold id='4'>done</endfold id='4'> 0799 for f in */include/dbcommon.php; <beginfold id='4'>do</beginfold id='4'>;cp dbcommon.php $f; <endfold id='4'>done</endfold id='4'> 0800 for file (*(ND-.)) IFS= read -re < $file 0801 for i (./*.mp3)<beginfold id='3'>{</beginfold id='3'>mpg321 --w - $i > ${i:r}.wav<endfold id='3'>}</endfold id='3'> 0802 for i in *(.); mv $i ${i:u} # `bar to `BAR 0803 for i in **/*(D@); <beginfold id='1'>[[</beginfold id='1'> -f $i || -d $i <endfold id='1'>]]</endfold id='1'> || echo $i 0804 for i in **/*.gif; convert $i $i:r.jpg 0805 for i in {3,4}; sed s/flag=2/flag=$i/ fred.txt > fred$i.txt 0806 for ip ({217..219} 225) <beginfold id='3'>{</beginfold id='3'>echo -n $ip ;ping -n 1 11.2.2.$ip| grep Received<endfold id='3'>}</endfold id='3'> 0807 for user (${(k)f}) <beginfold id='3'>{</beginfold id='3'>print -rn $f[$user]|mailx -s "..." $user<endfold id='3'>}</endfold id='3'> 0808 for x ( 1 2 {7..4} a b c {p..n} *.php) <beginfold id='3'>{</beginfold id='3'>echo $x<endfold id='3'>}</endfold id='3'> 0809 select name in a ; <beginfold id='4'>do</beginfold id='4'> echo ; <endfold id='4'>done</endfold id='4'> 0810 select name; <beginfold id='4'>do</beginfold id='4'> echo ; <endfold id='4'>done</endfold id='4'> 0811 <beginfold id='5'>if</beginfold id='5'> : ; then echo ; elif <beginfold id='1'>[[</beginfold id='1'> : <endfold id='1'>]]</endfold id='1'> ; then echo ; else echo ; <endfold id='5'>fi</endfold id='5'> 0812 <beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>[</beginfold id='1'> $# -gt 0 <endfold id='1'>]</endfold id='1'>;then string=$*;else;string=<beginfold id='2'>$(</beginfold id='2'>getclip<endfold id='2'>)</endfold id='2'>;<endfold id='5'>fi</endfold id='5'> 0813 <beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>[</beginfold id='1'> $# -gt 0 <endfold id='1'>]</endfold id='1'>;then string=$*;else;string=<beginfold id='2'>$(</beginfold id='2'>getclip<endfold id='2'>)</endfold id='2'>;<endfold id='5'>fi</endfold id='5'> # get parameter OR paste buffer 0814 <beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>[[</beginfold id='1'> (($x -lt 8) && ($y -ge 32)) || (($z -gt 32) && ($w -eq 16)) <endfold id='1'>]]</endfold id='1'> ; then print "complex combinations"; <endfold id='5'>fi</endfold id='5'> 0815 <beginfold id='5'>if</beginfold id='5'> builtin cd $1 &> /dev/null ; then echo ; <endfold id='5'>fi</endfold id='5'> 0816 <beginfold id='5'>if</beginfold id='5'> grep -iq 'matching' *.php ;then echo "Found" ;else echo "Not Found"; fim=("${(@Q)${(z)"<beginfold id='2'>$(</beginfold id='2'>cat -- $nameoffile<endfold id='2'>)</endfold id='2'>"}}") <endfold id='5'>fi</endfold id='5'> 0817 while : || : ; <beginfold id='4'>do</beginfold id='4'> echo ; <endfold id='4'>done</endfold id='4'> 0818 while <beginfold id='2'>(</beginfold id='2'>true<endfold id='2'>)</endfold id='2'><beginfold id='3'>{</beginfold id='3'>echo -n .;sleep 1<endfold id='3'>}</endfold id='3'> 0819 while <beginfold id='2'>(</beginfold id='2'>true<endfold id='2'>)</endfold id='2'><beginfold id='3'>{</beginfold id='3'>echo .;sleep 1<endfold id='3'>}</endfold id='3'> 0820 while true ;<beginfold id='4'>do</beginfold id='4'> date; sleep 5; <endfold id='4'>done</endfold id='4'> # forever 0821 while true; <beginfold id='4'>do</beginfold id='4'> echo "infinite loop"; sleep 5; <endfold id='4'>done</endfold id='4'> 0822 until : ; : ; <beginfold id='4'>do</beginfold id='4'> echo ; <endfold id='4'>done</endfold id='4'> 0823 <beginfold id='6'>case</beginfold id='6'> a in a<beginfold id='7'>)</beginfold id='7'> <endfold id='7'></endfold id='7'><endfold id='6'>esac</endfold id='6'> 0824 <beginfold id='6'>case</beginfold id='6'> a in a<beginfold id='7'>)</beginfold id='7'> echo ; <endfold id='7'></endfold id='7'><endfold id='6'>esac</endfold id='6'> 0825 <beginfold id='6'>case</beginfold id='6'> pwd in (patt1<beginfold id='7'>)</beginfold id='7'> echo ; echo <endfold id='7'>;;</endfold id='7'> (patt*<beginfold id='7'>)</beginfold id='7'> echo <endfold id='7'>;&</endfold id='7'> patt?|patt<beginfold id='7'>)</beginfold id='7'> echo <endfold id='7'>;|</endfold id='7'> 0826 patt<beginfold id='7'>)</beginfold id='7'> echo <endfold id='7'>;;</endfold id='7'> <endfold id='6'>esac</endfold id='6'> 0827 repeat 1+2+`echo 1`+23 <beginfold id='4'>do</beginfold id='4'> echo pl; <endfold id='4'>done</endfold id='4'> 0828 repeat 3 time sleep 3 # single command 0829 repeat 5 ;<beginfold id='4'>do</beginfold id='4'> date; sleep 5; <endfold id='4'>done</endfold id='4'> # multi 0830 foreach x y z ( a `a b`; c ) echo ;end 0831 for x y ( a b bc d ds ) echo $x $y 0832 for x y in a b c ; echo $x $y 0833 for x y ; echo $x $y 0834 <beginfold id='6'>case</beginfold id='6'> w { a<beginfold id='7'>)</beginfold id='7'> echo <endfold id='7'>;&</endfold id='7'> (b?<beginfold id='7'>)</beginfold id='7'> echo <endfold id='7'></endfold id='7'><endfold id='6'>}</endfold id='6'> 0835 <beginfold id='6'>case</beginfold id='6'> a in 0836 #a) echo ;; 0837 a#<beginfold id='7'>)</beginfold id='7'> echo <endfold id='7'>;;</endfold id='7'> 0838 <endfold id='6'>esac</endfold id='6'> 0839 0840 for name in a 0841 b c ; 0842 <beginfold id='4'>do</beginfold id='4'> 0843 echo 0844 <endfold id='4'>done</endfold id='4'> 0845 0846 <beginfold id='6'>case</beginfold id='6'> a in 0847 a\( | b*c? <beginfold id='7'>)</beginfold id='7'> echo 0848 <beginfold id='2'>(</beginfold id='2'>b$c<endfold id='2'>)</endfold id='2'> # no pattern 0849 <endfold id='7'>;;</endfold id='7'> 0850 (b$c<beginfold id='7'>)</beginfold id='7'> <endfold id='7'>;;</endfold id='7'> 0851 # no pattern 0852 (b$c<beginfold id='7'>)</beginfold id='7'> 0853 <endfold id='7'></endfold id='7'><endfold id='6'>esac</endfold id='6'> 0854 0855 <beginfold id='6'>case</beginfold id='6'> "$1" in 0856 "a"<beginfold id='7'>)</beginfold id='7'> run_a|&a<endfold id='7'>;;</endfold id='7'> 0857 "b"<beginfold id='7'>)</beginfold id='7'> run_b<endfold id='7'>;;</endfold id='7'> 0858 "c"<beginfold id='7'>)</beginfold id='7'> run_c<endfold id='7'>;;</endfold id='7'> 0859 *<beginfold id='7'>)</beginfold id='7'> echo "Plase choose between 'a', 'b' or 'c'" && exit 1<endfold id='7'>;;</endfold id='7'> 0860 <endfold id='6'>esac</endfold id='6'> 0861 0862 <beginfold id='6'>case</beginfold id='6'> $ans in 0863 1|a<beginfold id='7'>)</beginfold id='7'> sdba $key<endfold id='7'>;;</endfold id='7'> 0864 2|f<beginfold id='7'>)</beginfold id='7'> sdbf $key<endfold id='7'>;;</endfold id='7'> 0865 3|i<beginfold id='7'>)</beginfold id='7'> sdbi $key<endfold id='7'>;;</endfold id='7'> 0866 *<beginfold id='7'>)</beginfold id='7'> echo "wrong answer $ans\n" <endfold id='7'>;;</endfold id='7'> 0867 <endfold id='6'>esac</endfold id='6'> 0868 0869 <beginfold id='6'>case</beginfold id='6'> "$ans" in 0870 2|${prog}9<beginfold id='7'>)</beginfold id='7'> cd "<beginfold id='2'>$(</beginfold id='2'>cat /c/aam/${prog}9<endfold id='2'>)</endfold id='2'>" <endfold id='7'>;;</endfold id='7'> 0871 **<beginfold id='7'>)</beginfold id='7'> echo "wrong number $ans\n" <endfold id='7'>;;</endfold id='7'> 0872 <endfold id='6'>esac</endfold id='6'> 0873 0874 select f in <beginfold id='2'>$(</beginfold id='2'>ls **/*.tex |egrep -i "${param}[^/]*.tex"<endfold id='2'>)</endfold id='2'> 0875 <beginfold id='4'>do</beginfold id='4'> 0876 <beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>[[</beginfold id='1'> "$REPLY" = q <endfold id='1'>]]</endfold id='1'> 0877 then 0878 break 0879 elif <beginfold id='1'>[[</beginfold id='1'> -n "$f" <endfold id='1'>]]</endfold id='1'>; then 0880 gvim $f 0881 <endfold id='5'>fi</endfold id='5'> 0882 <endfold id='4'>done</endfold id='4'> 0883 0884 for d (. ./**/*(N/m-2)) <beginfold id='3'>{</beginfold id='3'> 0885 print -r -- $'\n'${d}: 0886 cd $d && <beginfold id='3'>{</beginfold id='3'> 0887 l=(*(Nm-2)) 0888 <beginfold id='1'>((</beginfold id='1'>$#l<endfold id='1'>))</endfold id='1'> && ls -ltd -- $l 0889 cd ~- 0890 <endfold id='3'>}</endfold id='3'> 0891 <endfold id='3'>}</endfold id='3'> 0892 0893 for f in http://zsh.sunsite.dk/Guide/zshguide{,{01..08}}.html; <beginfold id='4'>do</beginfold id='4'> 0894 lynx -source $f >${f:t} 0895 <endfold id='4'>done</endfold id='4'> 0896 0897 for f in ./**/*(-@); <beginfold id='4'>do</beginfold id='4'> 0898 stat +link -A l $f 0899 <beginfold id='2'>(</beginfold id='2'>cd $f:h & <beginfold id='1'>[[</beginfold id='1'> -e $l.gz <endfold id='1'>]]</endfold id='1'><endfold id='2'>)</endfold id='2'> & ln -sf $l.gz $f 0900 <endfold id='4'>done</endfold id='4'> 0901 0902 for ((i=1; i <= $#fpath; ++i)); <beginfold id='4'>do</beginfold id='4'> 0903 dir=$fpath[i] 0904 zwc=${dir:t}.zwc 0905 <beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>[[</beginfold id='1'> $dir == (.|..) || $dir == (.|..)/* <endfold id='1'>]]</endfold id='1'>; then 0906 continue 0907 <endfold id='5'>fi</endfold id='5'> 0908 files=($dir/*(N-.)) 0909 <beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>[[</beginfold id='1'> -w $dir:h && -n $files <endfold id='1'>]]</endfold id='1'>; then 0910 files=(${${(M)files%/*/*}#/}) 0911 <beginfold id='5'>if</beginfold id='5'> <beginfold id='2'>(</beginfold id='2'> cd $dir:h && 0912 zrecompile -p -U -z $zwc $files <endfold id='2'>)</endfold id='2'>; then 0913 fpath[i]=$fpath[i].zwc 0914 <endfold id='5'>fi</endfold id='5'> 0915 <endfold id='5'>fi</endfold id='5'> 0916 <endfold id='4'>done</endfold id='4'> 0917 0918 <beginfold id='5'>if</beginfold id='5'> ztcp pwspc 2811; then 0919 tcpfd=$REPLY 0920 handler() <beginfold id='3'>{</beginfold id='3'> 0921 zle -I 0922 local line 0923 <beginfold id='5'>if</beginfold id='5'> ! read -r line <&$1; then 0924 # select marks this fd if we reach EOF, 0925 # so handle this specially. 0926 print "[Read on fd $1 failed, removing.]" >&2 0927 zle -F $1 0928 return 1 0929 <endfold id='5'>fi</endfold id='5'> 0930 print -r - $line 0931 <endfold id='3'>}</endfold id='3'> 0932 zle -F $tcpfd handler 0933 <endfold id='5'>fi</endfold id='5'> 0934 0935 while <beginfold id='1'>[[</beginfold id='1'> $? -eq 0 <endfold id='1'>]]</endfold id='1'> <beginfold id='4'>do</beginfold id='4'> 0936 b=($=ZPCRE_OP) 0937 accum+=$MATCH 0938 pcre_match -b -n $b[2] -- $string 0939 <endfold id='4'>done</endfold id='4'> 0940 0941 # bug #380229 0942 ${str:<beginfold id='1'>$((</beginfold id='1'>${#a[1]}+1<endfold id='1'>))</endfold id='1'>} 0943 0944 # from http://zshwiki.org/home/examples/hardstatus 0945 function title <beginfold id='3'>{</beginfold id='3'> 0946 <beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>[[</beginfold id='1'> $TERM == "screen" <endfold id='1'>]]</endfold id='1'>; then 0947 # Use these two for GNU Screen: 0948 print -nR $'\033k'$1$'\033'\\ 0949 0950 print -nR $'\033]0;'$2$'\a' 0951 elif <beginfold id='1'>[[</beginfold id='1'> $TERM == "xterm" || $TERM == "rxvt" <endfold id='1'>]]</endfold id='1'>; then 0952 # Use this one instead for XTerms: 0953 print -nR $'\033]0;'$*$'\a' 0954 <endfold id='5'>fi</endfold id='5'> 0955 <endfold id='3'>}</endfold id='3'> 0956 0957 function precmd <beginfold id='3'>{</beginfold id='3'> 0958 title zsh "$PWD" 0959 <endfold id='3'>}</endfold id='3'> 0960 0961 function preexec <beginfold id='3'>{</beginfold id='3'> 0962 emulate -L zsh 0963 local -a cmd; cmd=(${(z)1}) 0964 title $cmd[1]:t "$cmd[2,-1]" 0965 <endfold id='3'>}</endfold id='3'> 0966 0967 function ddump()<beginfold id='3'>{</beginfold id='3'>diff -w ~dump/"$1" "$1"<endfold id='3'>}</endfold id='3'> # diff local file with new one in dump 0968 function g{0..9} <beginfold id='3'>{</beginfold id='3'> gmark $0 $* <endfold id='3'>}</endfold id='3'> # declaring multiple functions 0969 function hello_function <beginfold id='3'>{</beginfold id='3'> echo "hello world" ; zle .accept-line<endfold id='3'>}</endfold id='3'> 0970 function scd()<beginfold id='3'>{</beginfold id='3'>setopt nonomatch;e=/dev/null;cd $1(/) &> $e||cd $1*(/) &> $e||cd *$1(/) &> $e||cd *${1}*(/) &> $e||echo sorry<endfold id='3'>}</endfold id='3'> 0971 function vx{0..9} <beginfold id='3'>{</beginfold id='3'>gvim.exe c:/aax/${0/#v/} &<endfold id='3'>}</endfold id='3'> 0972 function {xyt,xyy} <beginfold id='3'>{</beginfold id='3'> <beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>[</beginfold id='1'> "$0" = "xyy" <endfold id='1'>]</endfold id='1'>; then echo run xyy code; else echo run xyt code; <endfold id='5'>fi</endfold id='5'> ; echo run common code <endfold id='3'>}</endfold id='3'> # 0973 0974 # creating a family of functions 0975 # generate hrefs from url 0976 function href{,s} 0977 <beginfold id='3'>{</beginfold id='3'> 0978 # href creates an HTML hyperlink from a URL 0979 # hrefs creates an HTML hyperlink from a URL with modified anchor text 0980 PROGNAME=`basename $0` 0981 url=`cat /dev/clipboard` 0982 <beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>[</beginfold id='1'> "$PROGNAME" = "href" <endfold id='1'>]</endfold id='1'> ; then 0983 href="<a href='$url'>$url" 0984 elif <beginfold id='1'>[</beginfold id='1'> "$PROGNAME" = "hrefs" <endfold id='1'>]</endfold id='1'> ; then 0985 anchortext=${${(C)url//[_-]/ }:t} 0986 href="<a href='$url'>$anchortext" 0987 <endfold id='5'>fi</endfold id='5'> 0988 echo -n $col 0989 echo $href > /dev/clipboard | more 0990 <endfold id='3'>}</endfold id='3'> 0991 0992 # create vim scratch files va,vb to vz 0993 function vx{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,q,r,s,t,u,v,w,x,y,z} 0994 <beginfold id='3'>{</beginfold id='3'> 0995 scratchfile=${0/#v/} 0996 gvim.exe c:/aax/$scratchfile & 0997 <endfold id='3'>}</endfold id='3'> 0998 0999 VDF()<beginfold id='3'>{</beginfold id='3'>cd *(/om[1]);F=<beginfold id='2'>$(</beginfold id='2'>echo *(.om[1])<endfold id='2'>)</endfold id='2'>;vi $F<endfold id='3'>}</endfold id='3'> 1000 cyg()<beginfold id='3'>{</beginfold id='3'>reply=("<beginfold id='2'>$(</beginfold id='2'>cygpath -m $REPLY<endfold id='2'>)</endfold id='2'>")<endfold id='3'>}</endfold id='3'> 1001 f ()<beginfold id='3'>{</beginfold id='3'>for i; <beginfold id='4'>do</beginfold id='4'> echo $i;<endfold id='4'>done</endfold id='4'><endfold id='3'>}</endfold id='3'> 1002 fg_light_red=$'%{\e[1;31m%}' 1003 fn() <beginfold id='3'>{</beginfold id='3'> setopt localtraps; trap '' INT; sleep 3; <endfold id='3'>}</endfold id='3'> 1004 nt() <beginfold id='3'>{</beginfold id='3'> <beginfold id='1'>[[</beginfold id='1'> $REPLY -nt $NTREF <endfold id='1'>]]</endfold id='1'> <endfold id='3'>}</endfold id='3'> 1005 preexec()<beginfold id='3'>{</beginfold id='3'> echo using $@[1]<endfold id='3'>}</endfold id='3'> 1006 take()<beginfold id='3'>{</beginfold id='3'><beginfold id='1'>[</beginfold id='1'> $# -eq 1 <endfold id='1'>]</endfold id='1'> && mkdir "$1" && cd "$1"<endfold id='3'>}</endfold id='3'> # create a directory and move to it in one go 1007 1008 caption always "%3n %t%? (%u)%?%?: %h%?" 1009 1010 preexec() <beginfold id='3'>{</beginfold id='3'> 1011 emulate -L zsh 1012 local -a cmd; cmd=(${(z)1}) # Re-parse the command line 1013 1014 # Construct a command that will output the desired job number. 1015 <beginfold id='6'>case</beginfold id='6'> $cmd[1] in 1016 fg<beginfold id='7'>)</beginfold id='7'> 1017 <beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>((</beginfold id='1'> $#cmd == 1 <endfold id='1'>))</endfold id='1'>; then 1018 # No arguments, must find the current job 1019 cmd=(builtin jobs -l %+) 1020 else 1021 # Replace the command name, ignore extra args. 1022 cmd=(builtin jobs -l ${(Q)cmd[2]}) 1023 <endfold id='5'>fi</endfold id='5'><endfold id='7'>;;</endfold id='7'> 1024 %*<beginfold id='7'>)</beginfold id='7'> cmd=(builtin jobs -l ${(Q)cmd[1]})<endfold id='7'>;;</endfold id='7'> # Same as "else" above 1025 exec<beginfold id='7'>)</beginfold id='7'> shift cmd<endfold id='7'>;&</endfold id='7'> # If the command is 'exec', drop that, because 1026 # we'd rather just see the command that is being 1027 # exec'd. Note the ;& to fall through. 1028 *<beginfold id='7'>)</beginfold id='7'> title $cmd[1]:t "$cmd[2,-1]" # Not resuming a job, 1029 return<endfold id='7'>;;</endfold id='7'> # so we're all done 1030 <endfold id='6'>esac</endfold id='6'> 1031 1032 local -A jt; jt=(${(kv)jobtexts}) # Copy jobtexts for subshell 1033 1034 # Run the command, read its output, and look up the jobtext. 1035 # Could parse $rest here, but $jobtexts (via $jt) is easier. 1036 $cmd >>(read num rest 1037 cmd=(${(z)${(e):-\$jt$num}}) 1038 title $cmd[1]:t "$cmd[2,-1]") 2>/dev/null 1039 <endfold id='3'>}</endfold id='3'> 1040 1041 function precmd() <beginfold id='3'>{</beginfold id='3'> 1042 title zsh "$IDENTITY:<beginfold id='2'>$(</beginfold id='2'>print -P %~<endfold id='2'>)</endfold id='2'>" 1043 <endfold id='3'>}</endfold id='3'> 1044 1045 "%{^[]0;screen ^En (^Et) ^G%}" 1046 1047 print -nRP $'\033k%(!.#\[.)'$1$'%'$\(\(20\-${#1}\)\)$'< ..<'${${2:+${${${@[${#${@}}]##/*/}/#/ }:-}}//\"/}$'%(!.\].)\033'\\ 1048 1049 c() <beginfold id='3'>{</beginfold id='3'> echo -E "<beginfold id='2'>$(</beginfold id='2'><$1<endfold id='2'>)</endfold id='2'>" <endfold id='3'>}</endfold id='3'> 1050 col() <beginfold id='3'>{</beginfold id='3'> for l in ${(f)"<beginfold id='2'>$(</beginfold id='2'><$1<endfold id='2'>)</endfold id='2'>"} ; echo ${${(Az)l}[$2]} <endfold id='3'>}</endfold id='3'> 1051 colx() <beginfold id='3'>{</beginfold id='3'> for l in ${(f)"<beginfold id='2'>$(</beginfold id='2'>eval ${(q)@[2,$]}<endfold id='2'>)</endfold id='2'>"} ; echo ${${(Az)l}[$1]} <endfold id='3'>}</endfold id='3'> 1052 1053 <beginfold id='1'>[[</beginfold id='1'> -r /etc/ssh/ssh_known_hosts <endfold id='1'>]]</endfold id='1'> && _global_ssh_hosts=(${${${${(f)"<beginfold id='2'>$(</beginfold id='2'></etc/ssh/ssh_known_hosts<endfold id='2'>)</endfold id='2'>"}:#[\|]*}%%\ *}%%,*}) || _global_ssh_hosts=() 1054 _ssh_hosts=(${${${${(f)"<beginfold id='2'>$(</beginfold id='2'><$HOME/.ssh/known_hosts<endfold id='2'>)</endfold id='2'>"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=() 1055 _ssh_config=(<beginfold id='2'>$(</beginfold id='2'>cat ~/.ssh/config | sed -ne 's/Host[=\t ]//p'<endfold id='2'>)</endfold id='2'>) || _ssh_config=() 1056 : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"<beginfold id='2'>$(</beginfold id='2'></etc/hosts<endfold id='2'>)</endfold id='2'>"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=() 1057 1058 prefix='(I:'$@[<beginfold id='1'>$((</beginfold id='1'>$i+1<endfold id='1'>))</endfold id='1'>]':)'$prefix || prefix='${('$tmp'I:'$@[<beginfold id='1'>$((</beginfold id='1'>$i+1<endfold id='1'>))</endfold id='1'>]':'${prefix[<beginfold id='1'>$((</beginfold id='1'>$#tmp+4<endfold id='1'>))</endfold id='1'>,-1]} 1059 prefix='${'${j:+($j)}$prefix; suffix+=':#'${@[<beginfold id='1'>$((</beginfold id='1'>$i+1<endfold id='1'>))</endfold id='1'>]//(#m)[\/\'\"]/\\$MATCH}'}' 1060 cmd+='<'${(q)@[<beginfold id='1'>$((</beginfold id='1'>$i+1<endfold id='1'>))</endfold id='1'>]}';' 1061 C=${OPTARG//(#m)[[\/\'\"\\]/\\$MATCH} 1062 $=p $e'"$(<'${(j:<:)${(q)@}}')"'$m 1063 1064 zshaddhistory() <beginfold id='3'>{</beginfold id='3'> 1065 print -sr -- ${1%%$'\n'} 1066 fc -p .zsh_local_history 1067 <endfold id='3'>}</endfold id='3'> 1068 1069 TRAPINT() <beginfold id='3'>{</beginfold id='3'> 1070 print "Caught SIGINT, aborting." 1071 return <beginfold id='1'>$((</beginfold id='1'> 128 + $1 <endfold id='1'>))</endfold id='1'> 1072 <endfold id='3'>}</endfold id='3'> 1073 1074 zsh_directory_name() <beginfold id='3'>{</beginfold id='3'> 1075 emulate -L zsh 1076 setopt extendedglob 1077 local -a match mbegin mend 1078 <beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>[[</beginfold id='1'> $1 = d <endfold id='1'>]]</endfold id='1'>; then 1079 # turn the directory into a name 1080 <beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>[[</beginfold id='1'> $2 = (#b)(/home/pws/perforce/)([^/]##)* <endfold id='1'>]]</endfold id='1'>; then 1081 typeset -ga reply 1082 reply=(p:$match[2] <beginfold id='1'>$((</beginfold id='1'> ${#match[1]} + ${#match[2]} <endfold id='1'>))</endfold id='1'> ) 1083 else 1084 return 1 1085 <endfold id='5'>fi</endfold id='5'> 1086 elif <beginfold id='1'>[[</beginfold id='1'> $1 = n <endfold id='1'>]]</endfold id='1'>; then 1087 # turn the name into a directory 1088 <beginfold id='1'>[[</beginfold id='1'> $2 != (#b)p:(?*) <endfold id='1'>]]</endfold id='1'> && return 1 1089 typeset -ga reply 1090 reply=(/home/pws/perforce/$match[1]) 1091 elif <beginfold id='1'>[[</beginfold id='1'> $1 = c <endfold id='1'>]]</endfold id='1'>; then 1092 # complete names 1093 local expl 1094 local -a dirs 1095 dirs=(/home/pws/perforce/*(/:t)) 1096 dirs=(p:${^dirs}) 1097 _wanted dynamic-dirs expl 'dynamic directory' compadd -S\] -a dirs 1098 return 1099 else 1100 return 1 1101 <endfold id='5'>fi</endfold id='5'> 1102 return 0 1103 <endfold id='3'>}</endfold id='3'> 1104 1105 <beginfold id='2'>(</beginfold id='2'><endfold id='2'>)</endfold id='2'> <beginfold id='3'>{</beginfold id='3'> 1106 print File $1: 1107 cat $1 1108 <endfold id='3'>}</endfold id='3'> =(print This be the verse) 1109 1110 <beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>[[</beginfold id='1'> $foo = (a|an)_(#b)(*) <endfold id='1'>]]</endfold id='1'>; then 1111 print ${foo[$mbegin[1],$mend[1]]} 1112 <endfold id='5'>fi</endfold id='5'> 1113 1114 zshaddhistory() <beginfold id='3'>{</beginfold id='3'> 1115 emulate -L zsh 1116 ## uncomment if HISTORY_IGNORE 1117 ## should use EXTENDED_GLOB syntax 1118 # setopt extendedglob 1119 <beginfold id='1'>[[</beginfold id='1'> $1 != ${~HISTORY_IGNORE} <endfold id='1'>]]</endfold id='1'> 1120 <endfold id='3'>}</endfold id='3'> 1121 1122 pick-recent-dirs-file() <beginfold id='3'>{</beginfold id='3'> 1123 <beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>[[</beginfold id='1'> $PWD = ~/text/writing(|/*) <endfold id='1'>]]</endfold id='1'>; then 1124 reply=(~/.chpwd-recent-dirs-writing) 1125 else 1126 reply=(+) 1127 <endfold id='5'>fi</endfold id='5'> 1128 <endfold id='3'>}</endfold id='3'> 1129 1130 run-help-ssh() <beginfold id='3'>{</beginfold id='3'> 1131 emulate -LR zsh 1132 local -a args 1133 # Delete the "-l username" option 1134 zparseopts -D -E -a args l: 1135 # Delete other options, leaving: host command 1136 args=(${@:#-*}) 1137 <beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>[[</beginfold id='1'> ${#args} -lt 2 <endfold id='1'>]]</endfold id='1'>; then 1138 man ssh 1139 else 1140 run-help $args[2] 1141 <endfold id='5'>fi</endfold id='5'> 1142 <endfold id='3'>}</endfold id='3'> 1143 1144 local -A zdn_top=( 1145 g ~/git 1146 ga ~/alternate/git 1147 gs /scratch/$USER/git/:second2 1148 :default: /:second1 1149 ) 1150 1151 <beginfold id='1'>((</beginfold id='1'> $#files > 0 <endfold id='1'>))</endfold id='1'> && print -rl -- $files | \ 1152 mailx -s "empty files" foo [at] bar.tdl 1153 1154 print -r -- $s[3] ${(l:4:)s[4]} ${(l:8:)s[5]} \ 1155 ${(l:8:)s[6]} ${(l:8:)s[8]} $s[10] $f ${s[14]:+-> $s[14]} 1156 1157 paste <(cut -f1 file1) <(cut -f3 file2) | 1158 tee >(process1) >(process2) >/dev/null 1159 1160 ls \ 1161 > x* 1162 1163 sed ' 1164 s/mvoe/move/g 1165 s/thier/their/g' myfile 1166 1167 1168 trap ' 1169 # code 1170 ' NAL 1171 1172 !! # previous command 1173 !!:0 !^ !:2 !$ !#$ !#:2 !#1 !#0 1174 !!:gs/fred/joe/ # edit previous command replace all fred by joe 1175 !!:gs/fred/joe/ # edit previous command replace all fred by joe 1176 !!:s/fred/joe/ # Note : sadly no regexp available with :s/// 1177 !!:s/fred/joe/ # edit previous command replace first fred by joe 1178 !$ (last argument of previous command) 1179 !$:h (last argument, strip one level) 1180 !$:h:h (last argument, strip two levels) 1181 !-2 # command before last 1182 !1 # oldest command in your history 1183 !42 # Re-execute history command 42 1184 !42:p 1185 !?echo 1186 !?saket?:s/somefile1/somefile2/ 1187 1188 <beginfold id='1'>((</beginfold id='1'>$#l<endfold id='1'>))</endfold id='1'> && ls -ltd -- $l 1189 <beginfold id='1'>((</beginfold id='1'>val2 = val1 * 2<endfold id='1'>))</endfold id='1'> 1190 <beginfold id='2'>(</beginfold id='2'>mycmd =(myoutput)<endfold id='2'>)</endfold id='2'> &! 1191 : *(.e{'grep -q pattern $REPLY || print -r -- $REPLY'}) 1192 : > /apache/access.log # truncate a log file 1193 < readme.txt 1194 A=(1 2 5 6 7 9) # pre-populate an array 1195 C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico /bin/zsh --login 1196 C=3 && F=<beginfold id='2'>$(</beginfold id='2'>print *(.om[1,$C])<endfold id='2'>)</endfold id='2'> && for f (<beginfold id='2'>$(</beginfold id='2'>print $F<endfold id='2'>)</endfold id='2'>)<beginfold id='3'>{</beginfold id='3'>php -l $f<endfold id='3'>}</endfold id='3'> && scp -rp <beginfold id='2'>$(</beginfold id='2'>print $F<endfold id='2'>)</endfold id='2'> user@192.168.1.1:$PWD 1197 EDITOR='/bin/vim' 1198 FILE=<beginfold id='2'>$(</beginfold id='2'>echo *(.om[1])<endfold id='2'>)</endfold id='2'> && ls -l $FILE && ssh 192.168.1.1 -l root "zsh -c 'ls -l $PWD/$FILE'" 1199 FILES=( .../files/* ) 1200 IFS=$'\n\n'; print -rl -- ${(Oau)${(Oa)<beginfold id='2'>$(</beginfold id='2'>cat file;echo .<endfold id='2'>)</endfold id='2'>[1,-2]}} 1201 IPREFIX=${PREFIX%%\=*}= 1202 PREFIX=${PREFIX#*=} 1203 PROMPT3="Choose File : " 1204 PROMPT="%{$bg[cyan]%}%% " 1205 PS3="$fg_light_red Select file : " 1206 REPORTTIME=10 # Automatically /Report CPU usage for commands running longer than 10 seconds 1207 RPROMPT="[%t]" <beginfold id='2'>(</beginfold id='2'>display the time<endfold id='2'>)</endfold id='2'> 1208 X=(x1 x2) 1209 Y=(+ -) 1210 <beginfold id='1'>[[</beginfold id='1'> "<beginfold id='2'>$(</beginfold id='2'>< $i<endfold id='2'>)</endfold id='2'>" = *\((${(j:|:)~@})\)* <endfold id='1'>]]</endfold id='1'> && echo $i:h:t 1211 <beginfold id='1'>[[</beginfold id='1'> $OSTYPE == (#i)LINUX*(#I) <endfold id='1'>]]</endfold id='1'>; 1212 <beginfold id='1'>[[</beginfold id='1'> 'cell=456' =~ '(cell)=(\d+)' <endfold id='1'>]]</endfold id='1'> && echo $match[1,2] $MATCH 1213 <beginfold id='1'>[[</beginfold id='1'> -e $L/config.php <endfold id='1'>]]</endfold id='1'> && cp -p -update $T/config.php $L 1214 <beginfold id='1'>[[</beginfold id='1'> -n ${key[Left]} <endfold id='1'>]]</endfold id='1'> && bindkey "${key[Left]}" backward-char 1215 <beginfold id='1'>[[</beginfold id='1'> 1 = 0 <endfold id='1'>]]</endfold id='1'> && echo eq || echo neq 1216 <beginfold id='1'>[[</beginfold id='1'> alphabetical -regex-match ^a([^a]+)a([^a]+)a <endfold id='1'>]]</endfold id='1'> && 1217 ^chim^&-&ney-&-&-cheree # reuse LHS 1218 ^fred^joe # edit previous command replace fred by joe 1219 ^php^cfm # modify previous command (good for correcting spellos) 1220 ^str1^str2^:G # replace as many as possible 1221 ^str1^str2^:u:p # replace str1 by str2 change case and just display 1222 a=(**/*(.D));echo $#a # count files in a (huge) hierarchy 1223 a=(1 2 3 4); b=(a b); print ${a:^b} 1224 a=(a b); b=(1 2); print -l "${a:^b}"; print -l "${${a:^b}}" 1225 a=12345 1226 aa[(e)*]=star 1227 accum=() 1228 alias '..'='cd ..' 1229 alias -g ...='../..' 1230 alias -g NF='*(.om[1])' # newest file 1231 alias gcd="cd $MCD" # double quote stops once only evaluation 1232 alias mcd="MCD=<beginfold id='2'>$(</beginfold id='2'>pwd<endfold id='2'>)</endfold id='2'>" # double quote stops once only evaluation 1233 anchortext=${${(C)url//[_-]/ }:t} # titlecase 1234 arr=(veldt jynx grimps waqf zho buck) 1235 array=(~/.zshenv ~/.zshrc ~/.zlogout) 1236 autoload edit-command-line 1237 autoload -Uz up-line-or-beginning-search 1238 autoload colors ; colors 1239 bindkey "^N" most-recent-file 1240 bindkey -s "^[OS" "\^d\^c\n" 1241 bindkey -s "^[[18~" "ls -l\n" 1242 c=(*.c) o=(*.o(N)) eval 'ls ${${c:#(${~${(j:|:)${o:r}}}).c}:?done}' 1243 cd !$:h 1244 cd !?ls 1245 diff <(find / | sort) <(cat /var/lib/dpkg/info/*.list | sort) 1246 dpath=${upath/#\/c\//c:/} # convert /c/path/ to c:\path\ 1247 drive=<beginfold id='2'>$(</beginfold id='2'><beginfold id='1'>[[</beginfold id='1'> "$LOGNAME" != davidr <endfold id='1'>]]</endfold id='1'> && echo '/o' || echo '/c'<endfold id='2'>)</endfold id='2'> # trad way 1248 drive=${${${LOGNAME:#davidr}:+/o}:-/c} # zsh way 1249 egrep -i "^ *mail\(" **/*.php 1250 eval "$1=$PWD" 1251 eval "m=(<beginfold id='2'>$(</beginfold id='2'>cat -- $nameoffile<endfold id='2'>)</endfold id='2'>" 1252 feh $FILES[$RANDOM%$#FILES+1] 1253 foo="twinkle twinkle little star" sub="t*e" rep="spy" 1254 foo=$'bar\n\nbaz\n' 1255 foo=fred-goat-dog.jpg 1256 fred=<beginfold id='1'>$((</beginfold id='1'>6**2 + 6<endfold id='1'>))</endfold id='1'> # can do maths 1257 <beginfold id='1'>((</beginfold id='1'> $# == 0 <endfold id='1'>))</endfold id='1'>; 1258 <beginfold id='1'>[</beginfold id='1'> "$p1" = "end" <endfold id='1'>]</endfold id='1'> || <beginfold id='1'>[</beginfold id='1'> "$p1" = "-e" <endfold id='1'>]</endfold id='1'> 1259 <beginfold id='1'>[</beginfold id='1'> $# -gt 0 <endfold id='1'>]</endfold id='1'> # parameter cnt > 0 (arguments) 1260 <beginfold id='1'>[</beginfold id='1'> $cnt -eq 1 <endfold id='1'>]</endfold id='1'> 1261 <beginfold id='1'>[[</beginfold id='1'> "$1" == [0-9] <endfold id='1'>]]</endfold id='1'> # if $1 is a digit 1262 <beginfold id='1'>[[</beginfold id='1'> "$p2" == *[a-zA-Z][a-zA-Z][a-zA-Z]* <endfold id='1'>]]</endfold id='1'> # contains at least 3 letters 1263 <beginfold id='1'>[[</beginfold id='1'> "$pwd" == *$site2* <endfold id='1'>]]</endfold id='1'> 1264 <beginfold id='1'>[[</beginfold id='1'> "$url" = www* <endfold id='1'>]]</endfold id='1'> # begins with www 1265 <beginfold id='1'>[[</beginfold id='1'> -e /c/aam/z$1 <endfold id='1'>]]</endfold id='1'> # file exists 1266 p1 p2 p3 1267 pcre_compile -m "\d{5}" 1268 pcre_match -b -- $string 1269 perl -ne 's/(<\/\w+>)/$1\n/g; print' < NF > <beginfold id='2'>$(</beginfold id='2'>print NF<endfold id='2'>)</endfold id='2'>.txt 1270 ps -p $$ | grep $$ | awk '{print $NF}' 1271 r oldstr=newstr 1272 r\m <beginfold id='2'>$(</beginfold id='2'>locate nohup.out<endfold id='2'>)</endfold id='2'> 1273 read -r line <&$fd; print -r - $line 1274 read ans ; # read in a parameter 1275 setopt EXTENDED_GLOB # lots of clever stuff requires this 1276 source ${ZDOTDIR:-$HOME}/.zkbd/$TERM-$VENDOR-$OSTYPE 1277 ssh -t root@192.18.001.001 'sh -c "cd /tmp && exec zsh -l"' 1278 ssh 192.168.1.218 -l root "zsh -c 'for i (/usr/*(/)) {ls \$i }'" 1279 sshpass -p myppassword scp -rp * user@18.128.158.158:${PWD/staging/release} 1280 str=aa,bb,cc;print ${(j:,:)${(qq)${(s:,:)str}}} # quotify a string 1281 tel blenkinsop | grep -o "[[:alnum:][:graph:]]*@[[:alnum:][:graph:]]*" # filter just an email address from a text stream (not zsh) 1282 touch {t,p}{01..99}.{php,html,c} # generate 600 test files 1283 touch {y,y2}.cfm 1284 trap - INT 1285 typeset "aa[one\"two\"three\"quotes]"=QQQ 1286 typeset -A aa 1287 typeset -A ass_array; ass_array=(one 1 two 2 three 3 four 4) 1288 typeset -A convtable 1289 typeset -i 16 y 1290 unsetopt XTRACE VERBOSE 1291 unsetopt localtraps 1292 upath=${wpath//\\/\/} # convert backslashes to forward slashes (Dos to Unix 1293 url='www.some.com/some_strIng-HERe' 1294 val=a:b:c 1295 var=133;<beginfold id='5'>if</beginfold id='5'> <beginfold id='1'>[[</beginfold id='1'> "$var" = <-> <endfold id='1'>]]</endfold id='1'> ; then echo "$var is numeric" ;<endfold id='5'>fi</endfold id='5'> 1296 var=ddddd; <beginfold id='1'>[[</beginfold id='1'> "$var" =~ ^d+$ <endfold id='1'>]]</endfold id='1'> && echo matched || echo did not match 1297 var=dddee; regexp="^e+$"; <beginfold id='1'>[[</beginfold id='1'> "$var" =~ $regexp <endfold id='1'>]]</endfold id='1'> && echo $regexp matched $var || echo $regexp did not match $var 1298 vared -p "choose 1-3 : " -c ans 1299 vared PATH 1300 whence -vsa ${(k)commands[(I)zsh*]} # search for zsh* 1301 widget 1302 wpath=${wpath//\//\\\\} # substitute Unix / with dos \ slashes 1303 x=$? 1304 zmodload -F zsh/stat b:zstat 1305 zsh -lxic : 2> >(grep "> alias 'web'") 1306 <beginfold id='3'>{</beginfold id='3'> paste <(cut -f1 file1) <(cut -f3 file2) <endfold id='3'>}</endfold id='3'> > >(process)