http://unbalanced-parentheses.nfshost.c ... fornewlisp
Code: Select all
#!/usr/bin/newlisp
; - nls- newLISP shell, put this script with executable permissions into
; the executable path on UNIX.
(define (help func-name)
  (if (find func-name "|+*-") (push "\\" func-name))
  (set 'html-text (join (find-all (format {<b>(syntax: \(%s.*?)</b>} func-name)    
    (read-file "/usr/share/doc/newlisp/newlisp_manual.html")) "\n"))
  (println (replace "<.*?>" html-text "" 0))
  "")
; set the prompt to the current path
(prompt-event (fn () (append (real-path) "> ")))
; handle some special commands, newLISP expressions and shell commands
(command-event (fn (s) 
  (if 
    ; get syntax help
    (starts-with s "help")
    (help (last (parse s " ")))
    ; restart newLISP
    (starts-with s "reset")
    (reset true) ; restart
    ; avoid X-windows beeing started on OS X
    (starts-with s "x")
    ""
    ; directory must be changed inside newLISP
    (starts-with s "cd") 
    (string " " (true? (change-dir (last (parse s " ")))))
    ; else handle as a shell command, start newLISP expressions
    ; with either a space or a parenthesis
    (starts-with s "[a-zA-Z]" 0)
    (append "!" s)
    true s)))
;; eof
http://www.newlisp.org/downloads/develo ... anual.html
The scriupt in action, with help:
Code: Select all
Users/lutz> help file
syntax: (file-info str_name [int-index])
syntax: (file? str-name)
/Users/lutz> (+ 1 2 3 4)
10
/Users/lutz> ls -ltr *.txt
-rw-r--r--  1 lutz  lutz  81786 Jan 28 14:43 wget.txt
-rw-r--r--  1 lutz  lutz    152 Mar 23 09:39 stats-log.txt
/Users/lutz>