Commit Graph
17 Commits
Author SHA1 Message Date
Florian WaltherandClaude Opus 5.5 22ce8c00d4 add assignments name=value and unset
- name=value (one or more) without a command sets variables of the shell
- name=value before a command sets them only in its environment (for
  builtins only while they run)
- an assignment needs an unquoted name and =; the value is not split
  and not expanded as wildcard or brace pattern, ~ is expanded after =
  and :
- the status of an assignment is the one of its last $(...)
- new builtin unset

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 00:17:38 +02:00
Florian WaltherandClaude Opus 5.5 f79fb0b8d5 add control structures: if, for, while, until
- new parser (parser.go) for lists, pipelines, ! and if/elif/else/fi,
  for ... in ... do/done, while/until ... do/done; simple commands are
  kept as text and expanded when they run (in every iteration)
- break [n], continue [n] and the : builtin
- incomplete input (open control structure, trailing &&, |, quote or
  backslash) continues on the next line: prompt "> " in interactive
  shells, scripts and startup files read on
- Ctrl+C aborts the whole command line, including loops
- aliases are expanded at the start of every simple command, also inside
  control structures
- control structures in pipelines, with redirections or in the
  background are reported as not supported
- completion: commands after if, then, do etc.
- main_test.go reformatted with gofmt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 00:05:28 +02:00
Florian WaltherandClaude Opus 5.5 e49fe6fe11 add command substitution $(...)
- $(command) is replaced by the output of command, which runs in a
  subshell (gosh -c), so cd/set in it do not change the shell
- trailing newlines are removed; unquoted the output is split into words
  at blanks and newlines, "$(...)" stays one word; wildcards in the
  output are not expanded
- nested substitutions, quotes and operators inside are handled; the
  list, alias and brace scanners skip $(...) as a whole
- a command that consists only of a substitution has its exit status,
  Ctrl+C in a substitution aborts the command
- $((...)) is reported as not supported

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 23:52:09 +02:00
Florian WaltherandClaude Opus 5.5 041406a340 show the exit status of a failed command in the prompt
- user@host:dir [N] $ after a command failed with exit status N,
  the plain prompt again after a successful command
- the status is colored bold red by default, configurable with the new
  GOSH_COLORS key error

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 23:46:11 +02:00
Florian WaltherandClaude Opus 5.5 dae4087a94 add job control
- in an interactive shell every pipeline runs in its own process group
  and gets the terminal while it runs in the foreground
- Ctrl+Z stops the foreground job, command & starts a job in the
  background; finished and stopped jobs are reported before the prompt
- new builtins jobs, fg, bg and wait (wait also works without job
  control, e.g. in scripts, where background jobs read from /dev/null)
- terminal modes are saved and restored when a job stops or continues
- exit and Ctrl+D warn once if there are stopped jobs
- processes are waited for with wait4 (WUNTRACED) instead of exec.Cmd.Wait
- pty based test for job control (Linux)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 23:22:21 +02:00
Florian WaltherandClaude Opus 5.5 4b44cc6e72 add startup files and the source builtin
- login shells (-l or argv[0] starting with -) read /etc/gosh/profile
  and ~/.gosh_profile, interactive shells /etc/gosh/goshrc and ~/.goshrc;
  --noprofile and --norc skip them
- source file / . file runs a file in the current shell, nesting is
  limited to stop files that source themselves
- errors in startup files and scripts are reported with file and line
- ~ and the startup files use $HOME (like sh), the user database is
  only the fallback

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 23:08:23 +02:00
Florian WaltherandClaude Opus 5.5 1182d8d146 add wildcards (*, ?, [...])
- unquoted * ? and [...] (including [!...]) are expanded to the
  matching file names, sorted, per path component
- hidden files only match if the pattern starts with a dot, a trailing /
  only matches directories, a pattern without match is kept as is
- quoted or escaped characters and values of variables are never
  expanded
- redirections to a pattern must match exactly one file
- completion escapes * ? [ and $ in file names

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 20:44:58 +02:00
Florian WaltherandClaude Opus 5.5 c46903e3d2 add pipes and redirections
- tokenizer recognizes unquoted |, <, >, >>, N>, N>>, N>&M, N<&M,
  &> and &>>; only a word of unquoted digits is a file descriptor
- pipelines run concurrently, the status is the one of the last command,
  errors of earlier stages are printed
- redirections are applied left to right (fds 0-2), a redirection
  without a command creates/truncates the file
- pwd and help can be redirected and piped; cd, set, export, exit and
  quit are rejected in pipelines
- syntax errors have exit status 2
- completion: commands after |, ;, && and ||, files after redirections;
  operator characters are escaped in completed names

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 20:39:38 +02:00
Florian WaltherandClaude Opus 5.5 f5c14dff90 add command lists (;, &&, ||) and $?
- split input at unquoted ;, && and || and run the commands like sh;
  variables are expanded per command when it runs
- $? and ${?} expand to the exit status of the last command,
  exit/quit without argument use it
- syntax errors for missing commands around operators (status 2)
- "command not found" message instead of the raw exec error, no more
  "exit status N" message when a command fails

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 20:32:39 +02:00
Florian WaltherandClaude Opus 5.5 b602e17622 add non-interactive mode: -c, script files and commands from stdin
- gosh -c 'command' runs the command and exits, so gosh works as login
  shell for ssh host command, scp and rsync
- gosh script runs a script file, lines starting with # are skipped
- without a terminal, commands are read from stdin (byte by byte, so
  started commands can read the rest of stdin)
- the exit status is the one of the last command (127 not found,
  126 not executable, 128+n killed by signal n)
- -i forces interactive mode, -l/--login is accepted

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 19:45:00 +02:00
Florian WaltherandClaude Opus 5.5 f51680f83c show version with branch and commit in help and -version
- add -version flag (besides --version and -V)
- help output includes the version
- commit and branch are set via ldflags by goreleaser; plain go build
  falls back to the VCS revision embedded by Go

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 19:38:48 +02:00
Florian WaltherandClaude Opus 5.5 03e791cbcd connect stdin of external commands to the terminal
Without Stdin, commands read from /dev/null, so interactive programs
like 'sudo su -', vim or ssh got EOF right away.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 19:10:30 +02:00
Florian WaltherandClaude Opus 5.5 2b8f06ea6d make prompt colors configurable via GOSH_COLORS
- GOSH_COLORS='user=..:root=..:path=..' with ANSI SGR codes,
  empty value disables the color for that part
- only digits and ';' are accepted, invalid entries are ignored
- read before every prompt, so 'set GOSH_COLORS=...' takes effect immediately
- document in help and README, including example color schemes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 17:47:49 +02:00
Florian WaltherandClaude Opus 5.5 7afcecd053 add colored prompt
- user@host in bold green (bold red for root), directory in bold blue
- colors are disabled with NO_COLOR, TERM=dumb or when stdout is not a terminal
- parts are sanitized before adding the color codes
- only replace the home directory with ~ on a path boundary

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 17:31:09 +02:00
Florian Walther d5c3d03a21 fixing bugs, update README,Help; adding .gitignore 2026-10-03 16:51:55 +02:00
Florian Walther 847b6cd5c6 fixing auto-completion 2026-10-03 16:33:40 +02:00
Florian Walther 6b177e15b3 first commit 2026-09-23 20:30:20 +02:00