mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-07-28 03:26:28 +00:00
shell-integration: initial nushell shell integration (#10274)
Nushell <https://www.nushell.sh/> is a modern interactive shell that provides many shell features out-of-the-box, like `title` support. Our shell integration therefore focuses on Ghostty-specific features like `sudo`. We use Nushell's module system to provide a `ghostty` module containing our shell integration features. This module is automatically loaded from $XDG_DATA_DIRS/nushell/vendor/autoload/ when `nushell` shell integration is enabled. Exported module functions need to be explicitly "used" before they're available to the interactive shell environment. We do that automatically by adding `--execute "use ghostty *"` to the `nu` command line. This imports all available functions, and individual shell features are runtime-guarded by the script code (using $GHOSTTY_SHELL_FEATURES). We can consider further refining this later. When automatic shell integration is disabled, users can still manually source and enable the shell integration module: source $GHOSTTY_RESOURCES_DIR/shell-integration/nushell/vendor/autoload/ghostty.nu use ghostty * This initial work implements our TERMINFO-aware `sudo` wrapper (via the `sudo` shell feature). Support for additional features, like `ssh-env` and `ssh-terminfo`, will follow (#9604).
This commit is contained in:
@@ -76,6 +76,24 @@ allowing us to automatically integrate with the shell. For details
|
||||
on the Fish startup process, see the
|
||||
[Fish documentation](https://fishshell.com/docs/current/language.html).
|
||||
|
||||
### Nushell
|
||||
|
||||
For [Nushell](https://www.nushell.sh/), Ghostty prepends to the
|
||||
`XDG_DATA_DIRS` directory, making the `ghostty` module available through
|
||||
Nushell's vendor autoload mechanism. Ghostty then automatically imports
|
||||
the module using the `-e "use ghostty *"` flag when starting Nushell.
|
||||
|
||||
Nushell provides many shell features itself, such as `title` and `cursor`,
|
||||
so our integration focuses on Ghostty-specific features like `sudo`.
|
||||
|
||||
The shell integration is automatically enabled when running Nushell in Ghostty,
|
||||
but you can also load it manually is shell integration is disabled:
|
||||
|
||||
```nushell
|
||||
source $GHOSTTY_RESOURCES_DIR/shell-integration/nushell/vendor/autoload/ghostty.nu
|
||||
use ghostty *
|
||||
```
|
||||
|
||||
### Zsh
|
||||
|
||||
Automatic [Zsh](https://www.zsh.org/) integration works by temporarily setting
|
||||
|
||||
35
src/shell-integration/nushell/vendor/autoload/ghostty.nu
vendored
Normal file
35
src/shell-integration/nushell/vendor/autoload/ghostty.nu
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# Ghostty shell integration
|
||||
export module ghostty {
|
||||
def has_feature [feature: string] {
|
||||
$feature in ($env.GHOSTTY_SHELL_FEATURES | default "" | split row ',')
|
||||
}
|
||||
|
||||
# Wrap `sudo` to preserve Ghostty's TERMINFO environment variable
|
||||
export def --wrapped sudo [
|
||||
...args # Arguments to pass to `sudo`
|
||||
] {
|
||||
mut sudo_args = $args
|
||||
|
||||
if (has_feature "sudo") {
|
||||
# Extract just the sudo options (before the command)
|
||||
let sudo_options = ($args | take until {|arg|
|
||||
not (($arg | str starts-with "-") or ($arg | str contains "="))
|
||||
})
|
||||
|
||||
# Prepend TERMINFO preservation flag if not using sudoedit
|
||||
if (not ("-e" in $sudo_options or "--edit" in $sudo_options)) {
|
||||
$sudo_args = ($args | prepend "--preserve-env=TERMINFO")
|
||||
}
|
||||
}
|
||||
|
||||
^sudo ...$sudo_args
|
||||
}
|
||||
}
|
||||
|
||||
# Clean up XDG_DATA_DIRS by removing GHOSTTY_SHELL_INTEGRATION_XDG_DIR
|
||||
if 'GHOSTTY_SHELL_INTEGRATION_XDG_DIR' in $env {
|
||||
if 'XDG_DATA_DIRS' in $env {
|
||||
$env.XDG_DATA_DIRS = ($env.XDG_DATA_DIRS | str replace $"($env.GHOSTTY_SHELL_INTEGRATION_XDG_DIR):" "")
|
||||
}
|
||||
hide-env GHOSTTY_SHELL_INTEGRATION_XDG_DIR
|
||||
}
|
||||
Reference in New Issue
Block a user