plan9/rc/bin/ape/ls
2014-02-08 22:26:48 -08:00

67 lines
1.2 KiB
Bash
Executable File

#!/bin/rc
# flags common to GNU and BSD ls
# -A all except . and ..
# -C force mc
# -F usual
# -H follow symlinks
# -L follow symlinks
# -R recursive list
# -U unsorted (gnu)
#
# -a include .files
# -c show ctime
# -d dirs
# -f no sorting
# -i inode numbers
# -l long
# -p put slash after dir (-F)
# -r reverse
# -s sizes
# -t time sort
# -u utime
# -1 single-column
flagfmt='A,C,F,H,L,R,U,a,c,d,f,i,l,p,r,s,t,u,1'
args='[file ...]'
if(! ifs=() eval `{aux/getflags $*}){
aux/usage
exit usage
}
fn fixlong {
echo total 1000
/$cputype/bin/sed 's/^(.).(.........) . [0-9]+ /\1\2 1 /'
}
fn qid2inode {
/$cputype/bin/sed 's/^\(([^ ]+).*\) /\1 /'
}
post=cat
post2=cat
all=()
# ignore -A
if(~ $flagC 1) post=mc
if(~ $flagF 1) all=($all -F)
# ignore -H, -L
# save -R for later
if(~ $flagU 1) all=($all -n)
# ignore -a, -c
if(~ $flagd 1) all=($all -d)
if(~ $flagf 1) all=($all -n)
if(~ $flagl 1) { all=($all -l); post=fixlong }
if(~ $flagi 1) { all=($all -q); post2=qid2inode }
if(~ $flagp 1) all=($all -F)
if(~ $flagr 1) all=($all -r)
if(~ $flags 1) all=($all -s)
if(~ $flagt 1) all=($all -t)
if(~ $flagu 1) all=($all -u)
# ignore -1
/$cputype/bin/ls $all $* | $post | $post2