-
Notifications
You must be signed in to change notification settings - Fork 49
feat(wrapperModules.ghostty): init #546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TrustworthyAdult
wants to merge
1
commit into
BirdeeHub:main
Choose a base branch
from
TrustworthyAdult:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+162
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| { | ||
| pkgs, | ||
| self, | ||
| tlib, | ||
| ... | ||
| }: | ||
| let | ||
| inherit (tlib) isFile fileContains test; | ||
| wrapper = self.wrappers.ghostty.wrap { | ||
| inherit pkgs; | ||
| settings = { | ||
| font-size = 14; | ||
| theme = "Catppuccin Mocha"; | ||
| window-decoration = false; | ||
| keybind = [ | ||
| "ctrl+a>-=new_split:down" | ||
| "ctrl+a>==new_split:right" | ||
| ]; | ||
| }; | ||
| }; | ||
| configFile = "${wrapper}/ghostty-config"; | ||
| in | ||
| test { wrapper = "ghostty"; } { | ||
| "ghostty wrapper binary should exist" = [ (isFile "${wrapper}/bin/ghostty") ]; | ||
|
|
||
| "ghostty wrapper should disable default config and point to generated file" = [ | ||
| (fileContains "${wrapper}/bin/ghostty" "--config-default-files=false") | ||
| (fileContains "${wrapper}/bin/ghostty" "--config-file=") | ||
| ]; | ||
|
|
||
| "ghostty wrapper should bypass config flags for +actions and --help" = [ | ||
| (fileContains "${wrapper}/bin/ghostty" "_ghostty_arg") | ||
| (fileContains "${wrapper}/bin/ghostty" "--help") | ||
| ]; | ||
|
|
||
| "ghostty config file should exist" = [ (isFile configFile) ]; | ||
|
|
||
| "ghostty settings should appear in generated config" = [ | ||
| (fileContains configFile "font-size = 14") | ||
| (fileContains configFile "theme = Catppuccin Mocha") | ||
| (fileContains configFile "window-decoration = false") | ||
| ]; | ||
|
|
||
| "ghostty list settings should serialize as duplicate keys" = [ | ||
| (fileContains configFile "keybind = ctrl\\+a>-=new_split:down") | ||
| (fileContains configFile "keybind = ctrl\\+a>==new_split:right") | ||
| ]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| { | ||
| config, | ||
| wlib, | ||
| lib, | ||
| pkgs, | ||
| ... | ||
| }: | ||
| let | ||
| toGhosttyConf = lib.generators.toKeyValue { | ||
| listsAsDuplicateKeys = true; | ||
| mkKeyValue = lib.generators.mkKeyValueDefault { | ||
| mkValueString = v: if builtins.isBool v then lib.boolToString v else toString v; | ||
| } " = "; | ||
| }; | ||
| in | ||
| { | ||
| imports = [ wlib.modules.default ]; | ||
|
|
||
| options.settings = lib.mkOption { | ||
| type = | ||
| let | ||
| atom = lib.types.oneOf [ | ||
| lib.types.bool | ||
| lib.types.float | ||
| lib.types.int | ||
| lib.types.str | ||
| ]; | ||
| in | ||
| lib.types.attrsOf (lib.types.either (lib.types.listOf atom) atom); | ||
| default = { }; | ||
| example = lib.literalExpression '' | ||
| { | ||
| font-size = 14; | ||
| theme = "Catppuccin Mocha"; | ||
| window-decoration = false; | ||
| keybind = [ | ||
| "ctrl+a>-=new_split:down" | ||
| "ctrl+a>==new_split:right" | ||
| ]; | ||
| } | ||
| ''; | ||
| description = '' | ||
| Ghostty configuration written to a generated config file. The wrapper | ||
| passes {option}`--config-default-files=false` and | ||
| {option}`--config-file=<generated>`, so the host config is never loaded | ||
| -- including when the wrapper is used ephemerally on a machine that has | ||
| its own Ghostty config. The host config path varies by platform: | ||
| {file}`~/.config/ghostty/config` on Linux, and | ||
| {file}`~/Library/Application Support/com.mitchellh.ghostty/config` on | ||
| macOS. | ||
| See <https://ghostty.org/docs/config/reference> for all available options. | ||
|
|
||
| Note: if you pass an additional {option}`--config-file` flag at runtime, | ||
| Ghostty will merge it on top of the generated config (later files take | ||
| precedence for conflicting keys). | ||
|
|
||
| Note: {command}`ghostty +show-config` and {command}`ghostty | ||
| +validate-config` bypass the generated config entirely (their option | ||
| parsers reject {option}`--config-file`), so they will show the host | ||
| config if one exists -- this affects both installed and ephemeral use. | ||
|
|
||
| On macOS, `ghostty-bin` is used by default, which is the pre-built | ||
| binary distribution [recommended for nix-darwin](https://ghostty.org/docs/install/binary) | ||
| by the Ghostty installation docs. | ||
| ''; | ||
| }; | ||
|
|
||
| config = { | ||
| package = lib.mkDefault (if pkgs.stdenv.isDarwin then pkgs.ghostty-bin else pkgs.ghostty); | ||
| constructFiles.ghosttyConfig = { | ||
| content = toGhosttyConf config.settings; | ||
| relPath = "${config.binName}-config"; | ||
| }; | ||
| addFlag = [ | ||
| "--config-default-files=false" | ||
| "--config-file=${config.constructFiles.ghosttyConfig.path}" | ||
| ]; | ||
| # Ghostty has no environment variable for specifying a config file, so CLI | ||
| # flags are the only option: --config-default-files=false prevents loading | ||
| # the host's ~/.config/ghostty/config (including on machines where one | ||
| # exists), and --config-file points at the generated one. | ||
| # | ||
| # However, Ghostty +actions and --help have their own minimal Options | ||
| # struct with no _diagnostics field. Any flag unrecognised by the action | ||
| # parser causes error.InvalidField and a silent exit with no output. | ||
| # argv0type detects these and execs Ghostty directly without injecting any | ||
| # flags. | ||
| # | ||
| # Consequence: +show-config and +validate-config will show the host's | ||
| # ~/.config/ghostty/config if present, not the generated config, because | ||
| # their option parsers also reject --config-file. This applies equally to | ||
| # installed and ephemeral use. | ||
| argv0type = | ||
| let | ||
| binPath = lib.escapeShellArg config.wrapperPaths.input; | ||
| in | ||
| cmd: '' | ||
| for _ghostty_arg in "$@"; do | ||
|
TrustworthyAdult marked this conversation as resolved.
|
||
| case "$_ghostty_arg" in | ||
| +*|--help) exec -a "$0" ${binPath} "$@";; | ||
| esac | ||
| done | ||
| exec -a "$0" ${cmd} | ||
| ''; | ||
| meta.description = "Ghostty terminal emulator"; | ||
| meta.maintainers = [ wlib.maintainers.trustworthyadult ]; | ||
| meta.platforms = lib.platforms.linux ++ lib.platforms.darwin; | ||
| }; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.