Aded extended commands and editor
This commit is contained in:
+5
-1
@@ -9,7 +9,7 @@
|
||||
|
||||
(provide pwd ls mkdir rmdir rm cp mv cat touch echo which
|
||||
head tail wc sort uniq cut tee tr basename dirname realpath readlink
|
||||
stat du df mktemp printenv env date help raco)
|
||||
stat du df mktemp printenv env date time edit help raco)
|
||||
|
||||
(define (make-command-procedure name)
|
||||
(λ args
|
||||
@@ -45,6 +45,8 @@
|
||||
(define printenv-command (make-command-procedure 'printenv))
|
||||
(define env-command (make-command-procedure 'env))
|
||||
(define date-command (make-command-procedure 'date))
|
||||
(define time-command (make-command-procedure 'time))
|
||||
(define edit-command (make-command-procedure 'edit))
|
||||
(define raco-command coreutils-raco)
|
||||
|
||||
(define (help-command . args)
|
||||
@@ -131,5 +133,7 @@
|
||||
(define-pipeline-alias printenv (make-coreutils-alias #'printenv-command))
|
||||
(define-pipeline-alias env (make-env-alias #'env-command))
|
||||
(define-pipeline-alias date (make-coreutils-alias #'date-command))
|
||||
(define-pipeline-alias time (make-coreutils-alias #'time-command))
|
||||
(define-pipeline-alias edit (make-coreutils-alias #'edit-command))
|
||||
(define-pipeline-alias help (make-coreutils-alias #'help-command))
|
||||
(define-pipeline-alias raco (make-coreutils-alias #'raco-command))
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
(require "coreutils.rkt"
|
||||
"extended.rkt"
|
||||
"racket-tools.rkt")
|
||||
"racket-tools.rkt"
|
||||
"editor.rkt")
|
||||
|
||||
(provide (struct-out coreutils-command)
|
||||
coreutils-commands
|
||||
@@ -42,6 +43,8 @@
|
||||
(coreutils-command 'printenv coreutils-printenv 'rash-coreutils-printenv)
|
||||
(coreutils-command 'env coreutils-env 'rash-coreutils-env)
|
||||
(coreutils-command 'date coreutils-date 'rash-coreutils-date)
|
||||
(coreutils-command 'time coreutils-time 'rash-coreutils-time)
|
||||
(coreutils-command 'edit coreutils-edit 'rash-coreutils-edit)
|
||||
(coreutils-command 'raco coreutils-raco 'rash-coreutils-raco)))
|
||||
|
||||
(define (find-coreutils-command name)
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
#lang racket/base
|
||||
|
||||
(require racket/format
|
||||
racket/path
|
||||
racket/string
|
||||
rackedit)
|
||||
|
||||
(provide coreutils-edit
|
||||
current-coreutils-editor)
|
||||
|
||||
(define current-coreutils-editor
|
||||
(make-parameter
|
||||
rkdt
|
||||
(λ (editor)
|
||||
(unless (procedure? editor)
|
||||
(raise-argument-error 'current-coreutils-editor "procedure?" editor))
|
||||
editor)))
|
||||
|
||||
(define (arg->path arg)
|
||||
(cond
|
||||
[(path? arg) arg]
|
||||
[(string? arg) (string->path arg)]
|
||||
[(symbol? arg) (string->path (symbol->string arg))]
|
||||
[else
|
||||
(raise-argument-error
|
||||
'edit
|
||||
"path, string, or symbol"
|
||||
arg)]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; goal : Open one file in the editor configured for rash-coreutils.
|
||||
; pre : args contains exactly one filename and optionally --wait.
|
||||
; post : The configured editor has been invoked once. With --wait, the
|
||||
; command does not return until the editor procedure returns.
|
||||
; result : (void).
|
||||
; internals:
|
||||
; current-coreutils-editor defaults to rackedit's rkdt procedure.
|
||||
; The --wait flag is translated to rkdt's #:wait? keyword.
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
(define (coreutils-edit . args)
|
||||
(define wait? #f)
|
||||
(define reversed-paths '())
|
||||
|
||||
(for ([arg (in-list args)])
|
||||
(define text (~a arg))
|
||||
(cond
|
||||
[(string=? text "--wait")
|
||||
(set! wait? #t)]
|
||||
[(string-prefix? text "-")
|
||||
(raise-arguments-error 'edit
|
||||
"unsupported option"
|
||||
"option" text)]
|
||||
[else
|
||||
(set! reversed-paths (cons (arg->path arg) reversed-paths))]))
|
||||
|
||||
(define paths (reverse reversed-paths))
|
||||
(unless (or (= (length paths) 1) (= (length paths) 0))
|
||||
(raise-arguments-error 'edit
|
||||
"expected exactly zero or one file"
|
||||
"arguments" args))
|
||||
|
||||
(if (null? paths)
|
||||
((current-coreutils-editor) #:wait? wait?)
|
||||
((current-coreutils-editor) (car paths) #:wait? wait?))
|
||||
|
||||
(void))
|
||||
+834
-140
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user