ls 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/rc
  2. # flags common to GNU and BSD ls
  3. # -A all except . and ..
  4. # -C force mc
  5. # -F usual
  6. # -H follow symlinks
  7. # -L follow symlinks
  8. # -R recursive list
  9. # -U unsorted (gnu)
  10. #
  11. # -a include .files
  12. # -c show ctime
  13. # -d dirs
  14. # -f no sorting
  15. # -i inode numbers
  16. # -l long
  17. # -p put slash after dir (-F)
  18. # -r reverse
  19. # -s sizes
  20. # -t time sort
  21. # -u utime
  22. # -1 single-column
  23. flagfmt='A,C,F,H,L,R,U,a,c,d,f,i,l,p,r,s,t,u,1'
  24. args='[file ...]'
  25. if(! ifs=() eval `{aux/getflags $*}){
  26. aux/usage
  27. exit usage
  28. }
  29. fn fixlong {
  30. echo total 1000
  31. /$cputype/bin/sed 's/^(.).(.........) . [0-9]+ /\1\2 1 /'
  32. }
  33. fn qid2inode {
  34. /$cputype/bin/sed 's/^\(([^ ]+).*\) /\1 /'
  35. }
  36. post=cat
  37. post2=cat
  38. all=()
  39. # ignore -A
  40. if(~ $flagC 1) post=mc
  41. if(~ $flagF 1) all=($all -F)
  42. # ignore -H, -L
  43. # save -R for later
  44. if(~ $flagU 1) all=($all -n)
  45. # ignore -a, -c
  46. if(~ $flagd 1) all=($all -d)
  47. if(~ $flagf 1) all=($all -n)
  48. if(~ $flagl 1) { all=($all -l); post=fixlong }
  49. if(~ $flagi 1) { all=($all -q); post2=qid2inode }
  50. if(~ $flagp 1) all=($all -F)
  51. if(~ $flagr 1) all=($all -r)
  52. if(~ $flags 1) all=($all -s)
  53. if(~ $flagt 1) all=($all -t)
  54. if(~ $flagu 1) all=($all -u)
  55. # ignore -1
  56. /$cputype/bin/ls $all $* | $post | $post2