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

@ -54,6 +54,17 @@
(expect "~ at the start" (parsed "cd ~/src ~bob") "cd ~/src ~bob ;")
(expect "~ elsewhere is text" (parsed "echo a~b") "echo a~b ;")
;; $(...).
(expect "$(...)" (parsed "echo $(ls -l)") "echo $(ls -l ;) ;")
(expect "$(...) in a word" (parsed "echo a$(b)c") "echo a$(b ;)c ;")
(expect "$(...) in double quotes" (parsed "echo \"x $(ls)\"") "echo \"x \"\"$(ls ;)\" ;")
(expect "a pipe and a list in $(...)" (parsed "echo $(a | b; c && d)") "echo $(a | b ; c && d ;) ;")
(expect "$(...) in $(...)" (parsed "echo $(echo $(ls))") "echo $(echo $(ls ;) ;) ;")
(expect "quotes in $(...)" (parsed "echo $(echo ')')") "echo $(echo \")\" ;) ;")
(expect "line breaks in $(...)" (parsed "echo $(\na\nb\n)") "echo $(a ; b ;) ;")
(expect "an empty $(...)" (parsed "echo $()") "echo $() ;")
(expect "$(...) in an assignment" (parsed "X=$(ls)") "X=$(ls ;) ;")
;; Operators.
(expect "a pipe" (parsed "ls | wc -l") "ls | wc -l ;")
(expect "a pipe without spaces" (parsed "ls|wc") "ls | wc ;")
@ -98,7 +109,9 @@
(expect "for" (parsed "for x in a; do ls; done") "error: `for` is not supported")
(expect "a quoted if is a word" (parsed "'if' x") "\"if\" x ;")
(expect "( )" (parsed "(ls)") "error: subshells ( ) are not supported")
(expect "$(...)" (parsed "echo $(ls)") "error: $(...) is not supported yet")
(expect "an open $(" (parsed "echo $(ls")
"error: Expecting: ')' to close $( / Unexpected: end of input")
(expect "a ) without (" (parsed "echo )") "error: ')' without '('")
(expect "`...`" (parsed "echo `ls`") "error: `...` is not supported")
(expect "here-documents" (parsed "cat <<EOF") "error: here-documents are not supported")
(expect "${NAME:-x}" (parsed "echo ${A:-x}")
@ -107,4 +120,15 @@
"error: only <, >, >>, 2>, 2>>, 2>&1 and >&2 are supported")
(expect "a number before a space is a word" (parsed "echo 3 >x") "echo 3 >x ;")
(expect "the column of an open quote" (error-column "echo 'abc") 10)
;; One pipe, for an alias.
(expect "one pipe" (match (parse-pipe "ls -l | wc") ((Ok cs) (vec-length cs)) ((Err _) 0)) 2)
(expect "a list is not one pipe" (parse-pipe "a; b") (Err "not one pipe: ;, &&, || and & are not allowed"))
(expect "&& is not one pipe" (parse-pipe "a && b") (Err "not one pipe: ;, &&, || and & are not allowed"))
(expect "& is not one pipe" (parse-pipe "a &") (Err "not one pipe: ;, &&, || and & are not allowed"))
(expect "nothing is no pipe" (parse-pipe " ") (Err "no command"))
;; Text as in double quotes, for the prompt.
(expect "text" (match (parse-text "a \"b\" $X $(c)") ((Ok ps) (word->string ps)) ((Err e) e))
"\"a \"\"\"\"\"b\"\"\"\"\" \"\"${X}\"\" \"\"$(c ;)\"")
0)