[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scheme shell (Was: who needs es..?)



| Didn't someone post something about the development of a scheme shell on
| this list?  Has anyone got a progress report on this?

Oh, I probably babled something to that effect at one time.  I know of
a few other people who've tinkered with that kind of thing, too.  In
terms of shell syntax, es probably can't be beat, but if you don't
mind S-expressions, scheme is ok.

Just for fun, here's an ls like thing that I never got around to
finishing:

#!/bin/scm -f
;;; $Id: sls,v 1.3 1993/03/06 22:44:32 schwartz Exp $

(define (mode-type mode)
  (case (logand #o170000 mode)
    ((#o040000) "d")
    ((#o020000) "c")
    ((#o060000) "b")
    ((#o100000) "-")
    ((#o120000) "l")
    ((#o140000) "s")
    ((#o010000) "p")
    (else "?")
  )
)

(define (mode-rwx mode)
  (string-append
    (if (zero? (logand #o4 mode)) "-" "r")
    (if (zero? (logand #o2 mode)) "-" "w")
    (if (zero? (logand #o1 mode)) "-" "x")
  )
)

(define (mode-string mode)
  (string-append
    (mode-type mode)
    (mode-rwx (ash mode -6))
    (mode-rwx (ash mode -3))
    (mode-rwx (ash mode -0))
  )
)
 
(define (uid-string uid)
  uid
)

(define (gid-string gid)
  gid
)

(define (date-string date)
  date
)

(define (path-string path)
  path
)

; (require 'format)

(define (ls-ld path)
  (let ( (st (unix:stat path)) )
    ; (format #f "~a ~d~t~a~t~a~t~d~t~d ~a ~%" 
    (list
         (mode-string (vector-ref st 2))
	 (vector-ref st 3)
	 (uid-string (vector-ref st 4))
	 (gid-string (vector-ref st 5))
	 (vector-ref st 7)
	 (date-string (vector-ref st 9))
         (path-string path)
    )
  )
)

(define (display-ls lst)
     (display-list
         (list-ref lst 0) " "
         (list-ref lst 1) "\t"
         (list-ref lst 2) "\t"
         (list-ref lst 3) "\t"
         (list-ref lst 4) "\t"
         (list-ref lst 5) " "
         (list-ref lst 6) "\n"
      )
)

(require 'sort)

(define (ls p)
    (define (prefix f) (string-append p "/" f))
    (for-each display-ls
	(map ls-ld 
	    (map prefix 
	        (sort! (map car (unix:directory p)) string<?)
	    )
        )
    )
)

(if (zero? (length *argv*))
  (ls ".")
  (for-each ls *argv*)
)