The shell takes spaces off both ends of a line, not just the front

Tab completion leaves a space after the word it finished, which is right
when another word is coming. When nothing else was coming, that space
stayed on the end of the line and a command taking a file name looked
for one whose name ended in a space:

  load greet.sbx      loaded, starting at 5000
  load greet.sbx      no such file      (the same line, finished with Tab)

Which took most of the good out of completion, since finishing a name
and pressing Return is the whole of what it is for. The existing tab
tests all typed more characters after completing, so none of them ever
submitted a completed line.

lineTrim already took the leading spaces off for indented blocks, so the
trailing ones come off in the same place, on the whole line, rather than
at each of the dozen commands that take a name. Walking back needs no
guard against running off the front: by then the first character cannot
be a space, and a line that was nothing but spaces has already become an
empty one.

CONSEQUENCE WORTH SEEING: echo no longer prints a trailing space it was
given, which is why cosmosTabPath's recording moved. That is the
conventional behaviour and it means what echo is handed is what somebody
would have typed, but it is a real change and not only a bug fix.

cosmosTrim covers a line completed and run straight away, the same
trailing space typed by hand, spaces at both ends at once, and a line of
nothing but spaces, which still has to do nothing rather than fail.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
This commit is contained in:
Anachronaut
2026-09-05 12:23:28 -04:00
co-authored by Claude Opus 5
parent 8631a78229
commit 35c6708e46
7 changed files with 78 additions and 4 deletions
+2 -2
View File
@@ -9,9 +9,9 @@ I do not know: Sayzz
where am I
/Apps> cd /
> echo Apps/Secho Apps/Say.sbx 
Apps/Say.sbx
Apps/Say.sbx
> echo /Apps/Cecho /Apps/Copy.sbx 
/Apps/Copy.sbx
/Apps/Copy.sbx
> exit
halted
Execution halted.
+12
View File
@@ -0,0 +1,12 @@
CosmOS
> load greload greet.sbx 
loaded, starting at 5000
> load greet.sbx
loaded, starting at 5000
> load greet.sbx
loaded, starting at 5000
>
> exit
halted
Execution halted.
[exit 0]
+5
View File
@@ -0,0 +1,5 @@
load gre
load greet.sbx
load greet.sbx
exit
+17
View File
@@ -413,7 +413,24 @@ cosmosTab | CosmOS/Source/cosmos.asm | run | cosmosTab
# look to RUN something: where you are, /Apps on the disk you are on, and /Apps on drive 0.
# Offering what the shell would not find would be finishing a word into something that then
# does not work.
#
# The echoed lines here have no trailing space on them, and that is the line trimming rather
# than the completion: Tab still leaves a space after the word it finished, and the shell
# takes it off the end of the line before anything reads it. So what echo is given is what
# somebody would have typed. See cosmosTrim.
cosmosTabPath | CosmOS/Source/cosmos.asm | run | cosmosTabPath.in | - | disks/cosmos.img
# The spaces at the ends of a line, which the shell takes off both of now.
#
# The leading ones were always taken off, for indented blocks. The trailing ones were not,
# and Tab completion puts one there: it finishes a word and leaves a space, which is right
# when another word is coming and was fatal when one was not. "load greet.sbx" worked and
# the same line finished with Tab did not, because the shell looked for a file whose name
# ended in a space - which took most of the good out of completion.
#
# Four lines: completed with Tab and run straight away, the same trailing space typed by
# hand, spaces at both ends at once, and a line of nothing but spaces, which has to stay a
# line that does nothing rather than becoming one that fails.
cosmosTrim | CosmOS/Source/cosmos.asm | run | cosmosTrim.in | - | disks/cosmos.img
# Names for things, which is what makes a script able to compose a command rather than only
# to contain one. The expansion happens on every line the shell is about to run, typed or read
# from a file, so no command below has to know that variables exist.