2005-05-23 10:52:03 -04:00
|
|
|
(define (standard-command-plugin-completer command args)
|
|
|
|
#f)
|
|
|
|
|
2005-05-27 13:01:14 -04:00
|
|
|
|
2005-08-10 14:03:59 -04:00
|
|
|
;; #####
|
|
|
|
;; it's a dumb idea to keep command and args separate, merge
|
|
|
|
;; this stuff
|
2005-05-23 10:52:03 -04:00
|
|
|
(define (standard-command-plugin-evaluater command args)
|
2005-08-10 14:03:59 -04:00
|
|
|
(let* ((parsed
|
|
|
|
(parse-command-line
|
|
|
|
(lex-command-line
|
|
|
|
(string-append command " "
|
|
|
|
(string-join args)))))
|
|
|
|
(expanded (expand-command-line parsed))
|
|
|
|
(s-expr (compile-command-line expanded)))
|
|
|
|
(debug-message "Compiled command " s-expr)
|
2006-04-06 09:25:03 -04:00
|
|
|
(eval-s-expr/command s-expr)))
|
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
|
|
|
|
|
2005-08-19 08:30:37 -04:00
|
|
|
(define no-completer #f)
|
2005-05-23 12:03:26 -04:00
|
|
|
|
2005-08-20 11:20:16 -04:00
|
|
|
(define just-run-in-foreground
|
|
|
|
(lambda (command args)
|
2006-04-06 12:26:53 -04:00
|
|
|
(run/fg* `(exec-epf (,command ,@(expand/glob-arguments args))))))
|
2005-08-20 11:20:16 -04:00
|
|
|
|
|
|
|
(define just-run-in-background
|
|
|
|
(lambda (command args)
|
2006-04-06 12:26:53 -04:00
|
|
|
(run/bg* `(exec-epf (,command ,@(expand/glob-arguments args))))))
|
2005-08-20 11:20:16 -04:00
|
|
|
|
2005-07-06 04:57:44 -04:00
|
|
|
;; Parse options for ls command using args-fold (SRFI 37)
|
|
|
|
;; We don't care for options that format the output.
|
|
|
|
|
|
|
|
(define defaults-ls-options
|
2006-04-07 03:36:04 -04:00
|
|
|
'((long . #f)
|
|
|
|
(dot-files? . #f)
|
2006-04-18 11:46:57 -04:00
|
|
|
(sort-by-mtime . #f)
|
|
|
|
(dont-sort . #f)
|
2005-09-12 11:34:36 -04:00
|
|
|
(reverse-sort . #f)))
|
2005-07-06 04:57:44 -04:00
|
|
|
|
|
|
|
(define (parse-ls-arguments args)
|
|
|
|
(let* ((on/off-option-processor
|
|
|
|
(lambda (name)
|
|
|
|
(lambda (option arg-name arg ops)
|
|
|
|
(cons (cons name #t) ops))))
|
|
|
|
(long-option
|
|
|
|
(option '(#\l) #f #f
|
|
|
|
(on/off-option-processor 'long)))
|
|
|
|
(dotfiles-option
|
|
|
|
(option '(#\a) #f #f
|
|
|
|
(on/off-option-processor 'dot-files?)))
|
|
|
|
(sort-mtime-option
|
|
|
|
(option '(#\t) #f #f
|
|
|
|
(on/off-option-processor 'sort-by-mtime)))
|
2006-04-18 11:46:57 -04:00
|
|
|
(dont-sort-option
|
|
|
|
(option '(#f) #f #f
|
|
|
|
(on/off-option-processor 'dont-sort)))
|
2005-07-06 04:57:44 -04:00
|
|
|
(reverse-sort-option
|
|
|
|
(option '(#\r) #f #f
|
|
|
|
(on/off-option-processor 'reverse-sort))))
|
|
|
|
(let ((given-args
|
|
|
|
(args-fold
|
|
|
|
args
|
|
|
|
(list long-option dotfiles-option
|
2006-04-18 11:46:57 -04:00
|
|
|
sort-mtime-option dont-sort-option reverse-sort-option)
|
2005-07-06 04:57:44 -04:00
|
|
|
(lambda (option name args operands)
|
|
|
|
(error "Unknown ls option" name))
|
|
|
|
cons '())))
|
2005-09-12 11:34:36 -04:00
|
|
|
(receive (options rest) (partition pair? given-args)
|
|
|
|
(values
|
|
|
|
(map (lambda (p)
|
|
|
|
(or (assoc (car p) options) p))
|
|
|
|
defaults-ls-options)
|
|
|
|
rest)))))
|
2005-07-06 04:57:44 -04:00
|
|
|
|
2005-05-23 12:03:26 -04:00
|
|
|
(register-plugin!
|
2005-05-27 17:32:21 -04:00
|
|
|
(make-command-plugin
|
|
|
|
"ls"
|
|
|
|
no-completer
|
|
|
|
(lambda (command args)
|
2005-09-12 11:34:36 -04:00
|
|
|
(debug-message "running ls plugin" command args)
|
2006-04-07 03:36:04 -04:00
|
|
|
(receive (options paths) (parse-ls-arguments args) ;; 'long is ignored
|
2005-09-12 11:34:36 -04:00
|
|
|
(let* ((set? (lambda (opt) (cdr (assoc opt options))))
|
|
|
|
(sort
|
|
|
|
(if (set? 'sort-by-mtime)
|
|
|
|
(lambda (lst)
|
|
|
|
(list-sort
|
|
|
|
(lambda (f g)
|
|
|
|
(< (file-info:mtime (fs-object-info f))
|
|
|
|
(file-info:mtime (fs-object-info g))))
|
|
|
|
lst))
|
2006-04-18 11:46:57 -04:00
|
|
|
|
|
|
|
(if (set? 'dont-sort)
|
|
|
|
(lambda (lst) lst)
|
|
|
|
(lambda (lst)
|
|
|
|
(list-sort
|
|
|
|
(lambda (f g)
|
|
|
|
(string<? (fs-object-name f) (fs-object-name g)))
|
|
|
|
lst)))))
|
2005-09-12 11:34:36 -04:00
|
|
|
(reverse
|
|
|
|
(if (set? 'reverse-sort)
|
|
|
|
reverse
|
2005-09-12 13:21:15 -04:00
|
|
|
(lambda (l) l)))
|
|
|
|
(paths (if (null? paths)
|
2006-04-06 12:26:53 -04:00
|
|
|
(list (file-name-as-directory (cwd)))
|
2006-04-18 11:46:57 -04:00
|
|
|
paths))
|
|
|
|
(dot-files? (set? 'dot-files?)))
|
2005-09-12 11:34:36 -04:00
|
|
|
(reverse
|
|
|
|
(sort
|
|
|
|
(apply
|
|
|
|
append
|
|
|
|
(map (lambda (path)
|
|
|
|
(if (file-directory? path)
|
2006-04-18 11:46:57 -04:00
|
|
|
(if dot-files?
|
|
|
|
(cons (file-name->fs-object ".")
|
|
|
|
(cons (file-name->fs-object "..")
|
|
|
|
(directory-files path dot-files?)))
|
|
|
|
(directory-files path dot-files?))
|
2005-09-12 11:34:36 -04:00
|
|
|
(list (file-name->fs-object path))))
|
2006-04-06 12:26:53 -04:00
|
|
|
(expand/glob-arguments paths))))))))))
|
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!
|
2005-08-20 11:20:16 -04:00
|
|
|
(make-command-plugin
|
|
|
|
"cd"
|
2006-04-18 11:46:57 -04:00
|
|
|
no-completer
|
2005-08-20 11:20:16 -04:00
|
|
|
(lambda (command args)
|
2006-04-06 12:26:53 -04:00
|
|
|
(let* ((exp-args (expand/glob-arguments args))
|
|
|
|
(arg (if (null? exp-args)
|
|
|
|
(getenv "HOME")
|
|
|
|
(if (null? (cdr exp-args))
|
|
|
|
(car exp-args)
|
|
|
|
(error "too many arguments to cd" exp-args)))))
|
|
|
|
(chdir arg)
|
|
|
|
(cwd)))))
|
2005-05-23 12:03:26 -04:00
|
|
|
|
|
|
|
(register-plugin!
|
|
|
|
(make-command-plugin "setenv"
|
|
|
|
no-completer
|
|
|
|
(lambda (command args)
|
2005-09-27 12:36:38 -04:00
|
|
|
(case (length args)
|
|
|
|
((0) (printenv))
|
|
|
|
((1) (getenv (car args)))
|
|
|
|
((2)
|
|
|
|
(setenv (car args) (cadr args))
|
|
|
|
0)
|
|
|
|
(else
|
|
|
|
(error "too many arguments to setenv" args))))))
|
2005-05-23 12:03:26 -04:00
|
|
|
|
|
|
|
(register-plugin!
|
|
|
|
(make-command-plugin "printenv"
|
2005-10-11 11:45:00 -04:00
|
|
|
(lambda (command to-complete)
|
|
|
|
(completions-for
|
|
|
|
(make-completion-set
|
|
|
|
(map car (env->alist)))
|
|
|
|
(or (to-complete-prefix to-complete) "")))
|
2005-05-23 12:03:26 -04:00
|
|
|
(lambda (command args)
|
2005-09-27 12:36:38 -04:00
|
|
|
(case (length args)
|
|
|
|
((0) (printenv))
|
|
|
|
((1) (getenv (car args)))
|
|
|
|
(else
|
|
|
|
(error "too many arguments to printenv"
|
|
|
|
args))))))
|
|
|
|
|
|
|
|
(define (printenv)
|
|
|
|
(env->alist))
|
2005-05-23 12:03:26 -04:00
|
|
|
|
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)))))))
|
|
|
|
|
2005-10-11 11:45:00 -04:00
|
|
|
(define jobs-completion-set
|
|
|
|
(make-completion-set
|
|
|
|
'("running" "ready" "stopped"
|
|
|
|
"output" "waiting-for-input")))
|
|
|
|
|
2005-06-04 07:22:44 -04:00
|
|
|
(register-plugin!
|
|
|
|
(make-command-plugin "jobs"
|
2005-10-11 11:44:53 -04:00
|
|
|
(lambda (command to-complete)
|
2005-10-11 11:45:00 -04:00
|
|
|
(completions-for
|
|
|
|
jobs-completion-set
|
2005-10-11 11:44:53 -04:00
|
|
|
(or (to-complete-prefix to-complete) "")))
|
2005-06-04 07:22:44 -04:00
|
|
|
(lambda (command args)
|
2005-07-06 04:57:44 -04:00
|
|
|
(let ((selectors
|
|
|
|
`(("running" . ,running-jobs)
|
|
|
|
("ready" . ,ready-jobs)
|
|
|
|
("stopped" . ,stopped-jobs)
|
|
|
|
("output" . ,jobs-with-new-output)
|
|
|
|
("input" . ,jobs-waiting-for-input))))
|
|
|
|
(append-map
|
|
|
|
(lambda (arg)
|
|
|
|
(cond
|
|
|
|
((assoc arg selectors)
|
|
|
|
=> (lambda (p)
|
|
|
|
((cdr p))))))
|
|
|
|
(if (null? args)
|
|
|
|
(map car selectors)
|
|
|
|
(delete-duplicates args)))))))
|
2005-06-14 07:20:30 -04:00
|
|
|
|
2005-08-20 11:20:16 -04:00
|
|
|
(register-plugin!
|
|
|
|
(make-command-plugin
|
|
|
|
"latex"
|
|
|
|
(make-completer-for-file-with-extension '(".tex"))
|
|
|
|
just-run-in-foreground))
|
|
|
|
|
|
|
|
(register-plugin!
|
|
|
|
(make-command-plugin
|
|
|
|
"xdvi"
|
|
|
|
(make-completer-for-file-with-extension '(".dvi"))
|
|
|
|
just-run-in-background))
|
|
|
|
|
2005-06-14 07:20:30 -04:00
|
|
|
(register-plugin!
|
|
|
|
(make-command-plugin
|
|
|
|
"ftp"
|
2005-08-18 05:23:59 -04:00
|
|
|
(let* ((hosts '("ftp.gnu.org" "ftp.x.org"))
|
|
|
|
(cs (make-completion-set hosts)))
|
|
|
|
(lambda (command to-complete)
|
|
|
|
(debug-message "ftp completer " command "," to-complete)
|
|
|
|
(completions-for cs (or (to-complete-prefix to-complete) ""))))
|
2005-08-20 12:09:48 -04:00
|
|
|
just-run-in-foreground))
|
2005-06-14 07:20:30 -04:00
|
|
|
|
2005-09-27 04:59:55 -04:00
|
|
|
(define (make-debug-plugin val buffer)
|
|
|
|
(lambda (message)
|
|
|
|
(case message
|
|
|
|
((paint)
|
|
|
|
(lambda (self win buffer have-focus?)
|
|
|
|
(let ((cols (+ 0 (result-buffer-num-cols buffer)))
|
|
|
|
(lines (+ 0 (result-buffer-num-lines buffer))))
|
|
|
|
(wmove win 0 0)
|
|
|
|
(waddstr win "A")
|
|
|
|
(wmove win 0 cols)
|
|
|
|
(waddstr win "B")
|
|
|
|
(wmove win lines cols)
|
|
|
|
(waddstr win "C")
|
|
|
|
(wmove win lines 0)
|
|
|
|
(waddstr win "D")
|
|
|
|
(wrefresh win))))
|
|
|
|
(else
|
|
|
|
(lambda (self . more)
|
|
|
|
self)))))
|
|
|
|
|
|
|
|
(register-plugin!
|
|
|
|
(make-view-plugin make-debug-plugin (lambda (v) (eq? v 'debug))))
|