2005-05-23 10:52:03 -04:00
|
|
|
(define (standard-command-plugin-completer command args)
|
|
|
|
#f)
|
|
|
|
|
2005-05-27 13:01:14 -04:00
|
|
|
(define (contains-glob-enumerator? arg)
|
|
|
|
(if-match
|
|
|
|
(regexp-search
|
2005-05-28 05:43:10 -04:00
|
|
|
(rx (: (submatch (* any)) ("{[") (* any) (submatch (* any)) ("]}")))
|
2005-05-27 13:01:14 -04:00
|
|
|
arg)
|
|
|
|
(whole-arg submatch-before submatch-after)
|
|
|
|
(not (or (string-suffix? "\\" submatch-before)
|
|
|
|
(string-suffix? "\\" submatch-after)))
|
|
|
|
#f))
|
|
|
|
|
|
|
|
(define (contains-glob-wildcard? arg)
|
|
|
|
(if-match
|
|
|
|
(regexp-search (rx (: (submatch (* any)) ("*?"))) arg)
|
|
|
|
(whole-arg submatch-before)
|
|
|
|
(not (string-suffix? "\\" submatch-before))
|
|
|
|
#f))
|
|
|
|
|
|
|
|
(define (contains-glob-expression? arg)
|
|
|
|
(or (contains-glob-wildcard? arg)
|
|
|
|
(contains-glob-enumerator? arg)))
|
|
|
|
|
|
|
|
(define (glob-argument arg)
|
|
|
|
(let ((files (glob arg)))
|
|
|
|
(if (null? files)
|
|
|
|
(error "no files match this glob expression" arg (cwd))
|
|
|
|
files)))
|
|
|
|
|
|
|
|
(define (expand-command-argument arg)
|
|
|
|
(let ((expanded (expand-file-name arg)))
|
|
|
|
(cond
|
|
|
|
((contains-glob-expression? arg)
|
|
|
|
(glob-argument expanded))
|
|
|
|
(else (list expanded)))))
|
|
|
|
|
|
|
|
(define (expand-argument-list args)
|
|
|
|
(fold-right
|
|
|
|
(lambda (arg expanded)
|
|
|
|
(append (expand-command-argument arg) expanded))
|
|
|
|
'() args))
|
|
|
|
|
2005-05-23 10:52:03 -04:00
|
|
|
(define (standard-command-plugin-evaluater command args)
|
2005-05-27 12:02:39 -04:00
|
|
|
(def-prog-mode)
|
|
|
|
(endwin)
|
2005-05-27 13:01:14 -04:00
|
|
|
(newline)
|
|
|
|
(let ((status (run (,command ,@(expand-argument-list args)))))
|
|
|
|
(newline)
|
2005-05-27 12:02:39 -04:00
|
|
|
(display "Press any key to return to scsh-nuit...")
|
|
|
|
(wait-for-key)
|
|
|
|
status))
|
2005-05-23 10:52:03 -04:00
|
|
|
|
|
|
|
(define standard-command-plugin
|
|
|
|
(make-command-plugin #f
|
|
|
|
standard-command-plugin-completer
|
|
|
|
standard-command-plugin-evaluater))
|
2005-05-23 12:03:26 -04:00
|
|
|
|
|
|
|
;; some common commands
|
|
|
|
|
|
|
|
(define no-completer (lambda args #f))
|
|
|
|
|
|
|
|
(register-plugin!
|
2005-05-27 17:32:21 -04:00
|
|
|
(make-command-plugin
|
|
|
|
"ls"
|
|
|
|
no-completer
|
|
|
|
(lambda (command args)
|
|
|
|
(if (null? args)
|
|
|
|
(directory-files (cwd))
|
|
|
|
(let ((arg (file-name->fs-object
|
|
|
|
(expand-file-name (car args) (cwd)))))
|
|
|
|
(if (file-info-directory? (fs-object-info arg))
|
|
|
|
(directory-files (fs-object-complete-path arg))
|
|
|
|
arg))))))
|
2005-05-23 12:03:26 -04:00
|
|
|
|
2005-05-27 12:02:39 -04:00
|
|
|
(register-plugin!
|
|
|
|
(make-command-plugin "ps"
|
|
|
|
no-completer
|
|
|
|
(lambda (command args)
|
|
|
|
(pps))))
|
|
|
|
|
2005-05-23 12:03:26 -04:00
|
|
|
(register-plugin!
|
|
|
|
(make-command-plugin "pwd"
|
|
|
|
no-completer
|
|
|
|
(lambda (command args)
|
|
|
|
(cwd))))
|
|
|
|
|
|
|
|
(register-plugin!
|
|
|
|
(make-command-plugin "cd"
|
|
|
|
no-completer
|
|
|
|
(lambda (command args)
|
2005-05-26 13:39:20 -04:00
|
|
|
(chdir (resolve-file-name (if (null? args)
|
|
|
|
"~"
|
|
|
|
(car args))))
|
|
|
|
(cwd))))
|
2005-05-23 12:03:26 -04:00
|
|
|
|
|
|
|
(register-plugin!
|
|
|
|
(make-command-plugin "setenv"
|
|
|
|
no-completer
|
|
|
|
(lambda (command args)
|
|
|
|
(setenv (car args) (cadr args)))))
|
|
|
|
|
|
|
|
(register-plugin!
|
|
|
|
(make-command-plugin "getenv"
|
|
|
|
no-completer
|
|
|
|
(lambda (command args)
|
|
|
|
(getenv (car args)))))
|
|
|
|
|
|
|
|
(register-plugin!
|
|
|
|
(make-command-plugin "printenv"
|
|
|
|
no-completer
|
|
|
|
(lambda (command args)
|
|
|
|
(env->alist))))
|
|
|
|
|
2005-05-26 13:39:20 -04:00
|
|
|
(register-plugin!
|
|
|
|
(make-command-plugin "exit"
|
|
|
|
no-completer
|
|
|
|
(lambda (command args)
|
2005-06-04 07:22:44 -04:00
|
|
|
(clear)
|
2005-05-26 13:39:20 -04:00
|
|
|
(exit (if (null? args)
|
|
|
|
0
|
2005-06-04 07:22:44 -04:00
|
|
|
(string->number (car args)))))))
|
|
|
|
|
|
|
|
(register-plugin!
|
|
|
|
(make-command-plugin "jobs"
|
2005-06-07 14:24:05 -04:00
|
|
|
(lambda (command prefix args arg-pos)
|
|
|
|
'("running" "ready" "output" "waiting-for-input"))
|
2005-06-04 07:22:44 -04:00
|
|
|
(lambda (command args)
|
2005-06-07 14:24:05 -04:00
|
|
|
(append-map
|
|
|
|
(lambda (arg)
|
|
|
|
;; #### warn if argument is unknown
|
|
|
|
(cond
|
|
|
|
((assoc arg
|
|
|
|
`(("running" . ,running-jobs)
|
|
|
|
("ready" . ,ready-jobs)
|
|
|
|
("output" . ,jobs-with-new-output)
|
|
|
|
("input" . ,jobs-waiting-for-input)))
|
|
|
|
=> (lambda (p)
|
|
|
|
((cdr p))))))
|
|
|
|
(delete-duplicates args)))))
|
2005-06-14 07:20:30 -04:00
|
|
|
|
|
|
|
(register-plugin!
|
|
|
|
(make-command-plugin
|
|
|
|
"ftp"
|
|
|
|
(lambda (command prefix args args-pos)
|
|
|
|
(cond
|
|
|
|
((getenv "FTPHOSTS")
|
|
|
|
=> string-tokenize)
|
|
|
|
(else
|
|
|
|
'("ftp.gnu.org" "ftp.x.org"))))
|
|
|
|
(lambda (command args)
|
|
|
|
(run (,command ,@args)))))
|
|
|
|
|