Phase 3: $(...), aliases, a start-up file, PROMPT, Done lines, >&2

- $(...) runs in a subshell. A word that is only an unquoted $(...) is
  one word per line. X=$(cmd) sets $? to its status.
- alias, unalias, and command NAME. An alias is one pipe.
- ~/.config/bjosh/rc runs before the first prompt.
- PROMPT, expanded as in double quotes, with \w \W \u \h \$ \e \n.
- "Done" lines are written above the input while the prompt waits.
- >&2, for programs and value commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Linus Björnstam 2026-12-01 09:50:15 +01:00
parent f54ceb35af
commit f8c4ad64bc
13 changed files with 680 additions and 128 deletions

View file

@ -33,7 +33,16 @@
((= user "bob") (Some "/home/bob"))
(else None)))
(def ex (Expander (lookup lookup) (home-of home-of)))
;; $(...): the words of its first command after the first, as lines,
;; without quotes, and two empty lines.
(: (-> (Vec Item) string))
(defun (substitute items)
(def pipe (record-ref (record-ref (vec-ref items 0) and-or) first))
(def words (vec-map (fun (w) (string-replace (word->string w) "\"" ""))
(record-ref (vec-ref pipe 0) words)))
(str (string-join (vec-drop words 1) "\n") "\n\n"))
(def ex (Expander (lookup lookup) (home-of home-of) (substitute substitute)))
;; The words of the first command of `text`, joined by "|".
(: (-> string string))
@ -56,6 +65,14 @@
(expect "~user" (words "cd ~bob/x") "cd|/home/bob/x")
(expect "a user that does not exist" (words "cd ~nobody") "cd|~nobody")
;; $(...). `substitute` returns the words after `echo`, one per line.
(expect "a $(...) word is one word per line" (words "x $(echo a b)") "x|a|b")
(expect "its empty lines are no words" (words "x $(echo '' a)") "x|a")
(expect "nothing is no word" (words "x $(echo) y") "x|y")
(expect "in a word it is text, without the last line breaks" (words "x p$(echo a b)q") "x|pa\nbq")
(expect "in double quotes it is one word" (words "x \"$(echo a b)\"") "x|a\nb")
(expect "it is not a glob" (words "x $(echo '*')") "x|*")
;; Globs, in a directory of our own.
(def dir (path-combine (temp-dir) (str "bjosh-expand-" (int->string process-id))))
(ignore (directory-create dir))