summaryrefslogtreecommitdiff
path: root/src/Command.zig
AgeCommit message (Collapse)Author
2025-10-03Zig 0.15: zig build test Mitchell Hashimoto
2025-09-19build: Command.expandPath can go in its own dedicated os/path.zig fileMitchell Hashimoto
2025-07-03Handle `exec` failures more gracefullyMitchell Hashimoto
Fixes #7792 Our error handling for `exec` failing within the forked process never actually worked! It triggered all sorts of issues. We didn't catch this before because it used to be exceptionally hard to fail an exec because we used to wrap ALL commands in a `/bin/sh -c`. However, we now support direction execution, most notably when you do `ghostty -e <command>` but also via the `direct:` prefix on configured commands. This fixes up our exec failure handling by printing a useful error message and avoiding any errdefers in the child which was causing the double-close.
2025-06-21Add FreeBSD support-k
Following https://github.com/cryptocode/ghostty/commit/7aeadb06ee5c38c440ac86b975d713a8ccfa3e0b
2025-05-26style: use decl literalsQwerasd
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-04-10config: allow commands to specify whether they shell expand or notMitchell Hashimoto
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-03-12fix windowsMitchell Hashimoto
2025-03-12working on macosMitchell Hashimoto
2025-01-02Move resource limits to a dedicated struct, restore before preexecMitchell Hashimoto
2025-01-01core: if we change RLIMIT_NOFILE, reset it when executing commandsJeffrey C. Ollie
2024-12-27testing: point Command.zig at ~more universal external binariesAnund
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-27testing: move cleanup of execveZ into the test codeAnund
2024-12-27testing: handle execveZ failing during test executionAnund
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-11command: fix hostname test compatibilityKhang Nguyen Duy
hostname is not guaranteed on *nix as in the comment. For example, Arch does not have hostname by default.
2024-07-22Fix multiple deprecated names for zig lib/stdmultifred
2024-07-02command: if chdir fails for subprocess, ignore the errorMitchell Hashimoto
Fixes #1911
2024-06-08remove unused varMitchell Hashimoto
2024-06-08small stylistic tweaksMitchell Hashimoto
2024-06-08use consistent type for pidJeffrey C. Ollie
2024-06-07Use clone3 / CLONE_INTO_CGROUP on LinuxJeffrey C. Ollie
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-07os: std.ChildProcess -> std.process.ChildJon Parise
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-03-22update zigMitchell Hashimoto
2024-02-10command: io_mode removed for windowsMitchell Hashimoto
2024-01-13build: build produces a broken object file for iOSMitchell Hashimoto
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-03replace deprecated std.mem.tokenize with std.mem.tokenizeScalarJeffrey C. Ollie
2023-12-30termio/exec: detect exec failure and show an error messageMitchell Hashimoto
2023-11-30Update to latest master,Krzysztof Wolicki
update libxev dependency, change mach_glfw to an updated fork until upstream updates
2023-11-17change unmodified `var`s to `const`s in anticipation of zig changesKrzysztof Wolicki
2023-11-05command: stylistic changesMitchell Hashimoto
2023-11-05shuffle some source aroundMitchell Hashimoto
2023-11-05windows: add support for the glfw backend on Windowskcbanner
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-10-26command: allow relative paths in PATHMitchell Hashimoto
2023-10-25add tests for fuzzed results, clean up unimplemented osc warningNameless
2023-10-19Disable iconv on Windows by default (enabled via cli flag).Krzysztof Wolicki
Skip various tests not implemented on windows.
2023-09-15windows: use cross platform consts where availableWill Pragnell
2023-09-14windows: implement expandPathWill Pragnell
2023-09-14windows: initial support for zig build testJonathan Marler
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-08-31command: only spin on waitpid if it's non-blockingWill Pragnell
2023-08-30termio/exec: don't leak zombie subprocessesWill Pragnell
2023-07-09move TempDir to src/os and use the real tmpDirMitchell Hashimoto
2023-06-30Update Zig (#164)Mitchell Hashimoto
* 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-05-29update zig versionMitchell Hashimoto
2023-02-27update zig, src for loopsMitchell Hashimoto
2023-02-25Command/Pty work better with Flatpak but not 100% yetMitchell Hashimoto
2022-11-16fix tests for WNOHANG commitMitchell Hashimoto
2022-11-16waitpid should specify WNOHANGMitchell Hashimoto
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-01Command supports setting cwdMitchell Hashimoto
2022-11-01get rid of stage1 compatMitchell Hashimoto
2022-09-30fix tests so they pass on macMitchell Hashimoto
2022-09-23Fix a couple bugs in memory access (tests only)Mitchell Hashimoto