Changeset 9770 for lang/scheme
- Timestamp:
- 04/18/08 23:36:02 (8 months ago)
- Location:
- lang/scheme/gauche-shell/trunk
- Files:
-
- 1 added
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/scheme/gauche-shell/trunk/shell.scm
r9601 r9770 7 7 8 8 (use srfi-1) 9 (use srfi-13) 9 10 (use file.util) 10 11 (use gauche.collection) 11 12 (use gauche.process) 12 (export pwd ls 13 $ command) 13 (use gauche.interactive) 14 (export pwd ls echo 15 $ command c 16 define-command define-commands 17 rehash 18 ) 14 19 15 16 17 (define pwd current-directory)18 20 (define-macro ($ arg) 19 21 `(sys-getenv 20 ,(cond 21 ((string? arg) arg) 22 ((symbol? arg) (symbol->string arg)) 23 ((number? arg) (number->string arg)) 24 (else (x->string arg))))) 22 ,(string-upcase 23 (cond 24 ((string? arg) arg) 25 ((symbol? arg) (symbol->string arg)) 26 ((number? arg) (number->string arg)) 27 (else (x->string arg)))))) 25 28 26 (define (ls . rest) 27 (remove #/^\.{1,2}$/ 28 (if (null? rest) 29 (directory-list (pwd)) 30 (apply directory-list rest)))) 29 (define-macro (define-command command) 30 `(define-macro (,command . args) 31 (cons 'command 32 (cons ',command 33 args)))) 34 (define-macro (define-commands . commands) 35 `(begin 36 ,@(map (lambda (command) 37 `(define-command ,command)) 38 commands))) 31 39 32 40 (define-macro (command com . args) 33 `(process-output->string-list 34 '(,(x->string com) 35 ,@(map x->string args)))) 41 (if (not (or (symbol? com) (string? com) (keyword? com))) 42 (error "Command name must be a symbol, a string, or a keyword.") 43 `(c (cons ,(x->string com) 44 (map x->string 45 (list ,@(map (lambda (arg) 46 (if (symbol? arg) 47 (symbol->string arg) 48 arg)) 49 args))))))) 50 51 (define (c command) 52 (process-output->string-list command :on-abnormal-exit :ignore)) 53 54 (define-macro (rehash) 55 (let* ((pathes (string-split ($ PATH) ":")) 56 (commands (map 57 string->symbol 58 (apply 59 append 60 (map (lambda (path) (c `(ls ,path))) 61 (filter file-exists? pathes)))))) 62 `(begin 63 ,@(map (lambda (command) 64 `(define-command ,command)) 65 commands) 66 (export ,@commands)))) 36 67 37 68 (provide "shell")
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)