Add $F for ,sh commands.
This commit is contained in:
parent
3c1e624916
commit
261288c394
|
@ -147,8 +147,8 @@
|
||||||
(let ([ch (peek-char)])
|
(let ([ch (peek-char)])
|
||||||
(if (memq ch skip) (begin (read-char) (loop)) ch)))))
|
(if (memq ch skip) (begin (read-char) (loop)) ch)))))
|
||||||
|
|
||||||
(define (here-path)
|
(define (here-path [no-path eof])
|
||||||
(let ([x (here-source)]) (if (path? x) x eof)))
|
(let ([x (here-source)]) (if (path? x) x no-path)))
|
||||||
(define (here-mod-or-eof)
|
(define (here-mod-or-eof)
|
||||||
(let ([x (here-source)])
|
(let ([x (here-source)])
|
||||||
(if (not x)
|
(if (not x)
|
||||||
|
@ -285,7 +285,9 @@
|
||||||
(defcommand (shell sh ls cp mv rm md rd git svn) "<shell-command>"
|
(defcommand (shell sh ls cp mv rm md rd git svn) "<shell-command>"
|
||||||
"run a shell command"
|
"run a shell command"
|
||||||
["`sh' runs a shell command (via `system'), the aliases run a few useful"
|
["`sh' runs a shell command (via `system'), the aliases run a few useful"
|
||||||
"unix commands. (Note: `ls' has some default arguments set.)"]
|
"unix commands. (Note: `ls' has some default arguments set.)"
|
||||||
|
"If the REPL is inside some module's namespace, the command can use $F"
|
||||||
|
"which is set to the full path to this module's source file."]
|
||||||
(let* ([arg (getarg 'line)]
|
(let* ([arg (getarg 'line)]
|
||||||
[arg (if (equal? "" arg) #f arg)]
|
[arg (if (equal? "" arg) #f arg)]
|
||||||
[cmd (current-command)])
|
[cmd (current-command)])
|
||||||
|
@ -294,12 +296,15 @@
|
||||||
[(shell) (set! cmd 'sh)])
|
[(shell) (set! cmd 'sh)])
|
||||||
(let ([cmd (cond [(eq? 'sh cmd) #f]
|
(let ([cmd (cond [(eq? 'sh cmd) #f]
|
||||||
[(symbol? cmd) (symbol->string cmd)]
|
[(symbol? cmd) (symbol->string cmd)]
|
||||||
[else cmd])])
|
[else cmd])]
|
||||||
|
[here (here-path #f)])
|
||||||
|
(putenv "F" (if here (path->string here) ""))
|
||||||
(unless (system (cond [(and (not cmd) (not arg)) (getenv "SHELL")]
|
(unless (system (cond [(and (not cmd) (not arg)) (getenv "SHELL")]
|
||||||
[(not cmd) arg]
|
[(not cmd) arg]
|
||||||
[(not arg) cmd]
|
[(not arg) cmd]
|
||||||
[else (string-append cmd " " arg)]))
|
[else (string-append cmd " " arg)]))
|
||||||
(eprintf "(exit with an error status)\n")))))
|
(eprintf "(exit with an error status)\n"))
|
||||||
|
(when here (putenv "F" "")))))
|
||||||
|
|
||||||
(defcommand (edit e) "<file> ..."
|
(defcommand (edit e) "<file> ..."
|
||||||
"edit files in your $EDITOR"
|
"edit files in your $EDITOR"
|
||||||
|
|
|
@ -81,6 +81,10 @@ available.
|
||||||
Use @cmd[shell] (or @cmd[sh]) to run a generic shell command (via
|
Use @cmd[shell] (or @cmd[sh]) to run a generic shell command (via
|
||||||
@racket[system]). For convenience, a few synonyms are provided ---
|
@racket[system]). For convenience, a few synonyms are provided ---
|
||||||
they run the specified executables (still using @racket[system]).
|
they run the specified executables (still using @racket[system]).
|
||||||
|
|
||||||
|
When the REPL is in the context of a module with a known source file,
|
||||||
|
the shell command can use the @envvar{F} environment variable as the
|
||||||
|
path to the file. Otherwise, @envvar{F} is set to an empty string.
|
||||||
}
|
}
|
||||||
|
|
||||||
@defcmd[edit]{
|
@defcmd[edit]{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user