mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-17 17:26:09 +03:00
zsh integration
This commit is contained in:
@ -19,12 +19,10 @@
|
|||||||
# we quote everything that can be quoted. Some aliases will still break us
|
# we quote everything that can be quoted. Some aliases will still break us
|
||||||
# though.
|
# though.
|
||||||
|
|
||||||
# Don't use [[ -v ... ]] because it doesn't work in zsh < 5.4.
|
# Restore the original ZDOTDIR value.
|
||||||
if [[ -n "${GHOSTTY_ORIG_ZDOTDIR+X}" ]]; then
|
if [[ -n "${GHOSTTY_ZSH_ZDOTDIR+X}" ]]; then
|
||||||
# Normally ZDOTDIR shouldn't be exported but it was in the environment
|
'builtin' 'export' ZDOTDIR="$GHOSTTY_ZSH_ZDOTDIR"
|
||||||
# of Ghostty, so we export it.
|
'builtin' 'unset' 'GHOSTTY_ZSH_ZDOTDIR'
|
||||||
'builtin' 'export' ZDOTDIR="$GHOSTTY_ORIG_ZDOTDIR"
|
|
||||||
'builtin' 'unset' 'GHOSTTY_ORIG_ZDOTDIR'
|
|
||||||
else
|
else
|
||||||
'builtin' 'unset' 'ZDOTDIR'
|
'builtin' 'unset' 'ZDOTDIR'
|
||||||
fi
|
fi
|
||||||
|
@ -6,6 +6,7 @@ const log = std.log.scoped(.shell_integration);
|
|||||||
/// Shell types we support
|
/// Shell types we support
|
||||||
pub const Shell = enum {
|
pub const Shell = enum {
|
||||||
fish,
|
fish,
|
||||||
|
zsh,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Setup the command execution environment for automatic
|
/// Setup the command execution environment for automatic
|
||||||
@ -23,6 +24,11 @@ pub fn setup(
|
|||||||
return .fish;
|
return .fish;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (std.mem.eql(u8, "zsh", exe)) {
|
||||||
|
try setupZsh(resource_dir, env);
|
||||||
|
return .zsh;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,3 +75,25 @@ fn setupFish(
|
|||||||
try env.put("XDG_DATA_DIRS", integ_dir);
|
try env.put("XDG_DATA_DIRS", integ_dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Setup the zsh automatic shell integration. This works by setting
|
||||||
|
/// ZDOTDIR to our resources dir so that zsh will load our config. This
|
||||||
|
/// config then loads the true user config.
|
||||||
|
fn setupZsh(
|
||||||
|
resource_dir: []const u8,
|
||||||
|
env: *EnvMap,
|
||||||
|
) !void {
|
||||||
|
// Preserve the old zdotdir value so we can recover it.
|
||||||
|
if (env.get("ZDOTDIR")) |old| {
|
||||||
|
try env.put("GHOSTTY_ZSH_ZDOTDIR", old);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set our new ZDOTDIR
|
||||||
|
var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||||
|
const integ_dir = try std.fmt.bufPrint(
|
||||||
|
&path_buf,
|
||||||
|
"{s}/shell-integration/zsh",
|
||||||
|
.{resource_dir},
|
||||||
|
);
|
||||||
|
try env.put("ZDOTDIR", integ_dir);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user