60 Commits

Author SHA1 Message Date
-k
e09657e263 Add FreeBSD support
Following 7aeadb06ee
2025-06-21 14:11:50 -07:00
Qwerasd
2384bd69cc style: use decl literals
This commit changes a LOT of areas of the code to use decl literals
instead of redundantly referring to the type.

These changes were mostly driven by some regex searches and then manual
adjustment on a case-by-case basis.

I almost certainly missed quite a few places where decl literals could
be used, but this is a good first step in converting things, and other
instances can be addressed when they're discovered.

I tested GLFW+Metal and building the framework on macOS and tested a GTK
build on Linux, so I'm 99% sure I didn't introduce any syntax errors or
other problems with this. (fingers crossed)
2025-05-26 21:50:14 -06:00
Mitchell Hashimoto
722d41a359 config: allow commands to specify whether they shell expand or not
This introduces a syntax for `command` and `initial-command` that allows
the user to specify whether it should be run via `/bin/sh -c` or not.
The syntax is a prefix `direct:` or `shell:` prior to the command,
with no prefix implying a default behavior as documented.

Previously, we unconditionally ran commands via `/bin/sh -c`, primarily
to avoid having to do any shell expansion ourselves. We also leaned on
it as a crutch for PATH-expansion but this is an easy problem compared
to shell expansion.

For the principle of least surprise, this worked well for configurations
specified via the config file, and is still the default. However, these
configurations are also set via the `-e` special flag to the CLI, and it
is very much not the principle of least surprise to have the command run via
`/bin/sh -c` in that scenario since a shell has already expanded all the
arguments and given them to us in a nice separated format. But we had no
way to toggle this behavior.

This commit introduces the ability to do this, and changes the defaults
so that `-e` doesn't shell expand. Further, we also do PATH lookups
ourselves for the non-shell expanded case because thats easy (using
execvpe style extensions but implemented as part of the Zig stdlib). We don't
do path expansion (e.g. `~/`) because thats a shell expansion.

So to be clear, there are no two polar opposite behavioes here with
clear semantics:

  1. Direct commands are passed to `execvpe` directly, space separated.
     This will not handle quoted strings, environment variables, path
     expansion (e.g. `~/`), command expansion (e.g. `$()`), etc.

  2. Shell commands are passed to `/bin/sh -c` and will be shell expanded
     as per the shell's rules. This will handle everything that `sh`
     supports.

In doing this work, I also stumbled upon a variety of smaller
improvements that could be made:

  - A number of allocations have been removed from the startup path that
    only existed to add a null terminator to various strings. We now
    have null terminators from the beginning since we are almost always
    on a system that's going to need it anyways.

  - For bash shell integration, we no longer wrap the new bash command
    in a shell since we've formed a full parsed command line.

  - The process of creating the command to execute by termio is now unit
    tested, so we can test the various complex cases particularly on
    macOS of wrapping commands in the login command.

  - `xdg-terminal-exec` on Linux uses the `direct:` method by default
    since it is also assumed to be executed via a shell environment.
2025-04-10 13:15:14 -07:00
Mitchell Hashimoto
fc21444f2d fix windows 2025-03-12 16:29:17 -07:00
Mitchell Hashimoto
7e9be00924 working on macos 2025-03-12 10:15:14 -07:00
Mitchell Hashimoto
8e47d0267b Move resource limits to a dedicated struct, restore before preexec 2025-01-02 15:05:10 -08:00
Jeffrey C. Ollie
9ea0aa4934 core: if we change RLIMIT_NOFILE, reset it when executing commands 2025-01-01 14:31:15 -06:00
Anund
600eea08cd testing: point Command.zig at ~more universal external binaries
The `Command.zig` tests reach outside the local source tree and look for
files on the host os machine. This introduces some portability issues
for the tests.

The nix build sandbox doesn't include `/usr/bin/env` making it error out
when `zig build test` runs `Command.zig` tests as part of a `nix build`.
Current ci and local development relies on `nix develop` sharing a host os
file system that includes `/usr/bin/env`.

Turns out `/tmp` and `/bin/sh` are available in the build sandbox in
nix so we swap these in to enable nixpkg builds to include testing
ghostty as part of any update cycle.
2024-12-27 17:07:24 +11:00
Anund
b2cb80dfbb testing: move cleanup of execveZ into the test code 2024-12-27 11:08:45 +11:00
Anund
184db2654c testing: handle execveZ failing during test execution
Duplicating a test process via fork does unexepected things.
zig build test will hang
A test binary created via -Demit-test-exe will run 2 copies of the test suite
2024-12-27 11:08:44 +11:00
Khang Nguyen Duy
cb5848c7b7 command: fix hostname test compatibility
hostname is not guaranteed on *nix as in the comment.
For example, Arch does not have hostname by default.
2024-12-11 16:54:28 +07:00
multifred
72c672adb7 Fix multiple deprecated names for zig lib/std 2024-07-22 00:07:17 +02:00
Mitchell Hashimoto
9baf4d143d command: if chdir fails for subprocess, ignore the error
Fixes #1911
2024-07-02 09:47:50 -07:00
Mitchell Hashimoto
6ae6e3ba11 remove unused var 2024-06-08 19:08:05 -07:00
Mitchell Hashimoto
8f9cdff1f5 small stylistic tweaks 2024-06-08 19:07:10 -07:00
Jeffrey C. Ollie
af9efd4d93 use consistent type for pid 2024-06-08 07:43:44 -06:00
Jeffrey C. Ollie
e6f97c28f8 Use clone3 / CLONE_INTO_CGROUP on Linux
Use clone3 / CLONE_INTO_CGROUP to have the Linux kernel create the process in the
correct cgroup rather than move the process into the cgroup after it is created.
2024-06-07 23:48:03 -06:00
Jon Parise
b1e1d8c3eb os: std.ChildProcess -> std.process.Child
std.ChildProcess was deprecated in favor of std.process.Child a few
releases back, and the old name is removed in Zig 0.13.0.
2024-06-07 12:36:30 -04:00
Mitchell Hashimoto
b7bf59d772 update zig 2024-03-22 11:15:26 -07:00
Mitchell Hashimoto
8456e9d7f7 command: io_mode removed for windows 2024-02-10 16:58:45 -08:00
Mitchell Hashimoto
3360a008cd build: build produces a broken object file for iOS
This gets `zig build -Dtarget=aarch64-ios` working. By "working" I mean
it produces an object file without compiler errors. However, the object
file certainly isn't useful since it uses a number of features that will
not work in the iOS sandbox.

This is just an experiment more than anything to see how hard it would be to
get libghostty working within iOS to render a terminal. Note iOS doesn't
support ptys so this wouldn't be a true on-device terminal. The
challenge right now is to just get a terminal rendering (not usable).
2024-01-13 21:38:58 -08:00
Jeffrey C. Ollie
f4292bccfc replace deprecated std.mem.tokenize with std.mem.tokenizeScalar 2024-01-03 10:22:33 -06:00
Mitchell Hashimoto
2ed75d47b5 termio/exec: detect exec failure and show an error message 2023-12-30 15:07:23 -08:00
Krzysztof Wolicki
0750698b62 Update to latest master,
update libxev dependency,
change mach_glfw to an updated fork until upstream updates
2023-11-30 21:41:33 +01:00
Krzysztof Wolicki
44a48f62f1 change unmodified vars to consts in anticipation of zig changes 2023-11-17 15:46:46 +01:00
Mitchell Hashimoto
1a846597b1 command: stylistic changes 2023-11-05 18:03:22 -08:00
Mitchell Hashimoto
7594bbd621 shuffle some source around 2023-11-05 15:27:46 -08:00
kcbanner
232df8de8f windows: add support for the glfw backend on Windows
Changes:
- Add WindowsPty, which uses the ConPTY API to create a pseudo console
- Pty now selects between PosixPty and WindowsPty
- Windows support in Command, including the ability to launch a process with a pseudo console
- Enable Command tests on windows
- Add some environment variable abstractions to handle the missing libc APIs on Windows
- Windows version of ReadThread
2023-11-05 23:15:49 +00:00
Mitchell Hashimoto
b049cb7d21 command: allow relative paths in PATH 2023-10-26 09:30:11 -07:00
Nameless
49f1866f28 add tests for fuzzed results, clean up unimplemented osc warning 2023-10-25 11:44:16 -05:00
Krzysztof Wolicki
3936b471a8 Disable iconv on Windows by default (enabled via cli flag).
Skip various tests not implemented on windows.
2023-10-19 09:39:20 +02:00
Will Pragnell
8f2ab46e1e windows: use cross platform consts where available 2023-09-15 16:01:33 -07:00
Will Pragnell
d700fb6fc7 windows: implement expandPath 2023-09-14 20:48:09 -07:00
Jonathan Marler
a2e881ff4e windows: initial support for zig build test
Makes progress getting "zig build test" to work on windows.  Mostly
fixed issues around build configuration and added some branches throughout
the Zig code to return/throw errors for unimplemented parts.

I also added an initial implementation for getting the home dir.
2023-09-14 03:15:40 -06:00
Will Pragnell
2e54ad2cce command: only spin on waitpid if it's non-blocking 2023-08-31 07:51:50 -07:00
Will Pragnell
aa9e12dac2 termio/exec: don't leak zombie subprocesses 2023-08-30 21:37:38 -07:00
Mitchell Hashimoto
9a0d131b5b move TempDir to src/os and use the real tmpDir 2023-07-09 12:14:05 -07:00
Mitchell Hashimoto
314f9287b1 Update Zig (#164)
* update zig

* pkg/fontconfig: clean up @as

* pkg/freetype,harfbuzz: clean up @as

* pkg/imgui: clean up @as

* pkg/macos: clean up @as

* pkg/pixman,utf8proc: clean up @as

* clean up @as

* lots more @as cleanup

* undo flatpak changes

* clean up @as
2023-06-30 12:15:31 -07:00
Mitchell Hashimoto
7116ce0806 update zig version 2023-05-29 08:24:12 -07:00
Mitchell Hashimoto
ce86c64b42 update zig, src for loops 2023-02-27 21:46:42 -08:00
Mitchell Hashimoto
ec956debb7 Command/Pty work better with Flatpak but not 100% yet 2023-02-25 21:19:57 -08:00
Mitchell Hashimoto
465b4df6ea fix tests for WNOHANG commit 2022-11-16 21:04:31 -08:00
Mitchell Hashimoto
d567a976b4 waitpid should specify WNOHANG
If the child process our terminal is executing behaves poorly and
doesn't waitpid all of its own children, then we can hang the full
terminal. This is not ideal, so specify WNOHANG.
2022-11-16 20:54:17 -08:00
Mitchell Hashimoto
63fab367fe Command supports setting cwd 2022-11-01 17:51:50 -07:00
Mitchell Hashimoto
c7db5b96d6 get rid of stage1 compat 2022-11-01 14:10:35 -07:00
Mitchell Hashimoto
a3d9dad726 fix tests so they pass on mac 2022-09-30 13:24:54 -07:00
Mitchell Hashimoto
a1d238e385 Fix a couple bugs in memory access (tests only) 2022-09-23 12:51:50 -07:00
Mitchell Hashimoto
d16c672771 update Zig, fixed new invalid octal error 2022-08-19 08:58:27 -07:00
Mitchell Hashimoto
5c2edf4d2a Fix some stage2 compilation errors 2022-08-17 14:42:23 -07:00
Mitchell Hashimoto
5b47195e49 update zig 2022-05-17 12:05:56 -07:00