mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
refactor(shell-integration): refactor to make cases alphabetical
also refactors elvish file to evade unobvious returns and tries to fix some build errors
This commit is contained in:
@ -847,7 +847,7 @@ keybind: Keybinds = .{},
|
|||||||
///
|
///
|
||||||
/// * `detect` - Detect the shell based on the filename.
|
/// * `detect` - Detect the shell based on the filename.
|
||||||
///
|
///
|
||||||
/// * `bash`, `fish`, `zsh` - Use this specific shell injection scheme.
|
/// * `bash`, `elvish`, `fish`, `zsh` - Use this specific shell injection scheme.
|
||||||
///
|
///
|
||||||
/// The default value is `detect`.
|
/// The default value is `detect`.
|
||||||
@"shell-integration": ShellIntegration = .detect,
|
@"shell-integration": ShellIntegration = .detect,
|
||||||
@ -3412,9 +3412,9 @@ pub const ShellIntegration = enum {
|
|||||||
none,
|
none,
|
||||||
detect,
|
detect,
|
||||||
bash,
|
bash,
|
||||||
|
elvish,
|
||||||
fish,
|
fish,
|
||||||
zsh,
|
zsh,
|
||||||
elvish,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Shell integration features
|
/// Shell integration features
|
||||||
|
@ -1024,6 +1024,7 @@ const Subprocess = struct {
|
|||||||
.none => break :shell .{ null, default_shell_command },
|
.none => break :shell .{ null, default_shell_command },
|
||||||
.detect => null,
|
.detect => null,
|
||||||
.bash => .bash,
|
.bash => .bash,
|
||||||
|
.elvish => .elvish,
|
||||||
.fish => .fish,
|
.fish => .fish,
|
||||||
.zsh => .zsh,
|
.zsh => .zsh,
|
||||||
};
|
};
|
||||||
|
@ -10,9 +10,9 @@ const log = std.log.scoped(.shell_integration);
|
|||||||
/// Shell types we support
|
/// Shell types we support
|
||||||
pub const Shell = enum {
|
pub const Shell = enum {
|
||||||
bash,
|
bash,
|
||||||
|
elvish,
|
||||||
fish,
|
fish,
|
||||||
zsh,
|
zsh,
|
||||||
elvish,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The result of setting up a shell integration.
|
/// The result of setting up a shell integration.
|
||||||
@ -46,9 +46,9 @@ pub fn setup(
|
|||||||
) !?ShellIntegration {
|
) !?ShellIntegration {
|
||||||
const exe = if (force_shell) |shell| switch (shell) {
|
const exe = if (force_shell) |shell| switch (shell) {
|
||||||
.bash => "bash",
|
.bash => "bash",
|
||||||
|
.elvish => "elvish",
|
||||||
.fish => "fish",
|
.fish => "fish",
|
||||||
.zsh => "zsh",
|
.zsh => "zsh",
|
||||||
.elvish => "elvish",
|
|
||||||
} else exe: {
|
} else exe: {
|
||||||
// The command can include arguments. Look for the first space
|
// The command can include arguments. Look for the first space
|
||||||
// and use the basename of the first part as the command's exe.
|
// and use the basename of the first part as the command's exe.
|
||||||
@ -70,18 +70,18 @@ pub fn setup(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (std.mem.eql(u8, "fish", exe)) {
|
if (std.mem.eql(u8, "elvish", exe)) {
|
||||||
try setupFish(alloc_arena, resource_dir, env);
|
try setupXdgDataDirs(alloc_arena, resource_dir, env);
|
||||||
break :shell .{
|
break :shell .{
|
||||||
.shell = .fish,
|
.shell = .elvish,
|
||||||
.command = command,
|
.command = command,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (std.mem.eql(u8, "elvish", exe)) {
|
if (std.mem.eql(u8, "fish", exe)) {
|
||||||
try setupElvish(alloc_arena, resource_dir, env);
|
try setupXdgDataDirs(alloc_arena, resource_dir, env);
|
||||||
break :shell .{
|
break :shell .{
|
||||||
.shell = .elvish,
|
.shell = .fish,
|
||||||
.command = command,
|
.command = command,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -415,11 +415,14 @@ test "bash: preserve ENV" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Setup the fish automatic shell integration. This works by
|
/// Setup automatic shell integration for shells that include
|
||||||
/// modify XDG_DATA_DIRS to include the resource directory.
|
/// their modules from paths in `XDG_DATA_DIRS` env variable.
|
||||||
/// Fish will automatically load configuration in XDG_DATA_DIRS
|
///
|
||||||
/// "fish/vendor_conf.d/*.fish".
|
/// Path of shell-integration dir is prepended to `XDG_DATA_DIRS`.
|
||||||
fn setupFish(
|
/// It is also saved in `GHOSTTY_INTEGRATION_DIR` variable so that
|
||||||
|
/// the shell can refer to it and safely remove this directory
|
||||||
|
/// from `XDG_DATA_DIRS` when integration is complete.
|
||||||
|
fn setupXdgDataDirs(
|
||||||
alloc_arena: Allocator,
|
alloc_arena: Allocator,
|
||||||
resource_dir: []const u8,
|
resource_dir: []const u8,
|
||||||
env: *EnvMap,
|
env: *EnvMap,
|
||||||
@ -436,7 +439,7 @@ fn setupFish(
|
|||||||
// Set an env var so we can remove this from XDG_DATA_DIRS later.
|
// Set an env var so we can remove this from XDG_DATA_DIRS later.
|
||||||
// This happens in the shell integration config itself. We do this
|
// This happens in the shell integration config itself. We do this
|
||||||
// so that our modifications don't interfere with other commands.
|
// so that our modifications don't interfere with other commands.
|
||||||
try env.put("GHOSTTY_FISH_XDG_DIR", integ_dir);
|
try env.put("GHOSTTY_INTEGRATION_DIR", integ_dir);
|
||||||
|
|
||||||
if (env.get("XDG_DATA_DIRS")) |old| {
|
if (env.get("XDG_DATA_DIRS")) |old| {
|
||||||
// We have an old value, We need to prepend our value to it.
|
// We have an old value, We need to prepend our value to it.
|
||||||
@ -462,18 +465,6 @@ fn setupFish(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Setup the Elvish automatic shell integration.
|
|
||||||
/// This reuses integration primitives of Fish, as Elvish also
|
|
||||||
/// loads config in XDG_DATA_DIRS (except it imports
|
|
||||||
/// "./elvish/lib/*.elv" files).
|
|
||||||
fn setupElvish(
|
|
||||||
alloc_arena: Allocator,
|
|
||||||
resource_dir: []const u8,
|
|
||||||
env: *EnvMap,
|
|
||||||
) !void {
|
|
||||||
try setupFish(alloc_arena, resource_dir, env);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Setup the zsh automatic shell integration. This works by setting
|
/// Setup the zsh automatic shell integration. This works by setting
|
||||||
/// ZDOTDIR to our resources dir so that zsh will load our config. This
|
/// ZDOTDIR to our resources dir so that zsh will load our config. This
|
||||||
/// config then loads the true user config.
|
/// config then loads the true user config.
|
||||||
|
Reference in New Issue
Block a user