|
| 1 | +#!/usr/bin/env zsh |
| 2 | + |
| 3 | +[[ -z $1 ]] && print "No argument given\n" && exit |
| 4 | + |
| 5 | + |
| 6 | +unary_tests () { |
| 7 | + print "File tests for '$1':" |
| 8 | + [[ -r $1 ]] && print - "-r\treadable" |
| 9 | + [[ -w $1 ]] && print - "-w\twriteable" |
| 10 | + [[ -x $1 ]] && print - "-x\texecutable" |
| 11 | + [[ -O $1 ]] && print - "-O\towner" |
| 12 | + [[ -G $1 ]] && print - "-G\tgroup" |
| 13 | + |
| 14 | + print - |
| 15 | + [[ -a $1 ]] && print - "-a\texists" |
| 16 | + [[ -b $1 ]] && print - "-b\tblock special" |
| 17 | + [[ -c $1 ]] && print - "-c\tchar special" |
| 18 | + [[ -d $1 ]] && print - "-d\tdir" |
| 19 | + [[ -e $1 ]] && print - "-e\texists" |
| 20 | + [[ -f $1 ]] && print - "-f\tregular" |
| 21 | + [[ -g $1 ]] && print - "-g\tsetgid bit" |
| 22 | + [[ -h $1 ]] && print - "-h\tsym link" |
| 23 | + [[ -k $1 ]] && print - "-k\tsticky bit" |
| 24 | + [[ -p $1 ]] && print - "-p\tpipe" |
| 25 | + [[ -s $1 ]] && print - "-s\tnonzero size" |
| 26 | + [[ -u $1 ]] && print - "-u\tsetuid bit" |
| 27 | + [[ -L $1 ]] && print - "-L\tsym link" |
| 28 | + [[ -S $1 ]] && print - "-S\tsocket" |
| 29 | + [[ -N $1 ]] && print - "-N\taccessed after mod" |
| 30 | + print |
| 31 | + |
| 32 | + print "String tests for '$1':" |
| 33 | + [[ -n $1 ]] && print - "-n\tnonzero length" |
| 34 | + # [[ -o $1 ]] && print - "-o\toption set" |
| 35 | + # [[ -t $1 ]] && print - "-t\topen file descriptor" |
| 36 | + [[ -z $1 ]] && print - "-z\tzero length" |
| 37 | + print "\n--------------------\n" |
| 38 | + |
| 39 | +} |
| 40 | + |
| 41 | + |
| 42 | +binary_tests () { |
| 43 | + print "Binary comparisons:" |
| 44 | + [[ $1 -nt $2 ]] && print - "-nt\tnewer than" |
| 45 | + [[ $1 -ot $2 ]] && print - "-ot\tolder than" |
| 46 | + [[ $1 -ef $2 ]] && print - "-ef\tsame file" |
| 47 | + [[ $1 = $2 ]] && print "=\tequal strings" |
| 48 | + [[ $1 != $2 ]] && print "!=\tunequal strings" |
| 49 | + [[ $1 < $2 ]] && print "<\tsorts before" |
| 50 | + [[ $1 > $2 ]] && print ">\tsorts after" |
| 51 | + [[ $1 -eq $2 ]] && print - "-eq\tequal numbers" |
| 52 | + [[ $1 -ne $2 ]] && print - "-ne\tunequal numbers" |
| 53 | + [[ $1 -lt $2 ]] && print - "-lt\tless than" |
| 54 | + [[ $1 -gt $2 ]] && print - "-gt\tgreater than" |
| 55 | + [[ $1 -le $2 ]] && print - "-le\tless than or equal to" |
| 56 | + [[ $1 -ge $2 ]] && print - "-ge\tgreater than or equal to" |
| 57 | + # [[ ! "$1" ]] && print "!\tfalse" |
| 58 | + # [[ $1 && $2 ]] && print "&&\tlogical and" |
| 59 | + # [[ $1 || $2 ]] && print "&&\tlogical or" |
| 60 | +} |
| 61 | + |
| 62 | +unary_tests $1 |
| 63 | + |
| 64 | +if [[ -n $2 ]]; then |
| 65 | + unary_tests "$2" |
| 66 | + binary_tests "$1" "$2" |
| 67 | +fi |
| 68 | + |
| 69 | + |
0 commit comments