Directories as commands, and a directory alone changes to it; bjoterm 0.2.1

As fish does: the first word completes directories too, and an interactive
line that is only a directory (with a /, or . or ..) changes to it. Tab
lists the candidates when it can add nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Linus Björnstam 2026-12-01 14:01:43 +01:00
parent 61d5a96eda
commit e697166927
6 changed files with 42 additions and 9 deletions

View file

@ -68,6 +68,9 @@
(let ((c (complete sh "prevd")))
(Tuple (record-ref c candidates) (record-ref c descriptions)))
(Tuple ["prevd "] ["go back in the directory history; also Alt-Left"]))
(expect "and directories" (complete sh "ab")
(Completion (prefix "ab") (candidates ["abd/"]) (descriptions ["directory"])))
(expect "ignoring case" (cands "AB") ["abd/"])
(expect "a first word with a / completes files" (cands "./ab") ["./abc.txt " "./abd/"])
(expect "a path ignoring case when nothing else matches" (cands "./ABC") ["./abc.txt "])
(expect "each part as the start of a name" (cands "ls ./a/in") ["./abd/inner "])

View file

@ -42,6 +42,8 @@
;; An empty commands directory: no package of user commands is written.
(ignore (directory-create (path-combine state "bjosh/commands")))
(ignore (file-write-text (path-combine state "bjosh/rc") "alias fromrc='echo set in rc'\n"))
(ignore (directory-create (path-combine state "tabs/alpha")))
(ignore (directory-create (path-combine state "tabs/apple")))
(def keys (string-join ["sleep 2.5"
"printf 'sleep 30\\r'" "sleep 1" "printf '\\032'" "sleep 0.5"
"printf 'jobs\\r'" "sleep 0.5"
@ -62,6 +64,8 @@
"printf 'echo after $?\\r'" "sleep 0.5"
"printf 'fromrc\\r'" "sleep 0.5"
"printf 'sleep 0.5 &\\r'" "sleep 0.3" "printf 'ec'" "sleep 1.5" "printf 'ho typed\\r'" "sleep 0.5"
"printf '/usr/\\r'" "sleep 0.3" "printf 'pwd\\r'" "sleep 0.3"
(str "printf 'ls " state "/tabs/a\\t'") "sleep 0.5" "printf '\\003'" "sleep 0.3"
"printf 'cd /tmp\\r'" "sleep 0.3"
"printf \"PROMPT='<\\\\W \\$(echo s)>\\\\$ '\\r\"" "sleep 0.5"
"printf 'exit\\r'" "sleep 1"]
@ -77,6 +81,9 @@
(expect-true "Ctrl-C ends a job, and the prompt starts a new line" (string-contains? out "^C\n"))
(expect-true "with status 130" (string-contains? out "status 130"))
(expect-true "Ctrl-Z at the prompt does not stop the shell" (string-contains? out "\nalive\n"))
(expect-true "a directory alone changes to it" (string-contains? out "pwd\n/usr\n"))
(expect-true "Tab lists the candidates when it can insert nothing"
(and (string-contains? out "tabs/alpha/") (string-contains? out "tabs/apple/")))
(expect-true "jobs in a pipe" (string-contains? out "jobs | g command\nsleep 30\n"))
(expect-true "history in a pipe, with this line last"
(string-contains? out "history | tl 1 | g line\nhistory | tl 1 | g line\n"))