mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-01-01 11:12:16 +00:00
refactor: replace ghostty wrapper with proper CLI actions for terminfo cache management
- Add +list-ssh-cache and +clear-ssh-cache CLI actions - Remove ghostty() wrapper functions from all shell integrations - Improve variable naming in shell scripts for readability Addresses @00-kat's feedback about CLI discoverability and naming consistency. The new CLI actions follow established Ghostty patterns and are discoverable via `ghostty --help`, while maintaining clean separation of concerns between shell logic and cache management.
This commit is contained in:
71
src/cli/ssh_cache.zig
Normal file
71
src/cli/ssh_cache.zig
Normal file
@@ -0,0 +1,71 @@
|
||||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const Child = std.process.Child;
|
||||
|
||||
/// Get the path to the shared cache script
|
||||
fn getCacheScriptPath(alloc: Allocator) ![]u8 {
|
||||
// Use GHOSTTY_RESOURCES_DIR if available, otherwise assume relative path
|
||||
const resources_dir = std.process.getEnvVarOwned(alloc, "GHOSTTY_RESOURCES_DIR") catch {
|
||||
// Fallback: assume we're running from build directory
|
||||
return try alloc.dupe(u8, "src/shell-integration/shared/ghostty-ssh-cache");
|
||||
};
|
||||
defer alloc.free(resources_dir);
|
||||
|
||||
return try std.fs.path.join(alloc, &[_][]const u8{ resources_dir, "shell-integration", "shared", "ghostty-ssh-cache" });
|
||||
}
|
||||
|
||||
/// List cached hosts by calling the external script
|
||||
pub fn listCachedHosts(alloc: Allocator, writer: anytype) !void {
|
||||
const script_path = try getCacheScriptPath(alloc);
|
||||
defer alloc.free(script_path);
|
||||
|
||||
var child = Child.init(&[_][]const u8{ script_path, "list" }, alloc);
|
||||
child.stdout_behavior = .Pipe;
|
||||
child.stderr_behavior = .Pipe;
|
||||
|
||||
try child.spawn();
|
||||
|
||||
const stdout = try child.stdout.?.readToEndAlloc(alloc, std.math.maxInt(usize));
|
||||
defer alloc.free(stdout);
|
||||
|
||||
const stderr = try child.stderr.?.readToEndAlloc(alloc, std.math.maxInt(usize));
|
||||
defer alloc.free(stderr);
|
||||
|
||||
_ = try child.wait();
|
||||
|
||||
// Output the results regardless of exit code
|
||||
try writer.writeAll(stdout);
|
||||
if (stderr.len > 0) {
|
||||
try writer.writeAll(stderr);
|
||||
}
|
||||
|
||||
// Script handles its own success/error messaging, so we don't need to check exit code
|
||||
}
|
||||
|
||||
/// Clear cache by calling the external script
|
||||
pub fn clearCache(alloc: Allocator, writer: anytype) !void {
|
||||
const script_path = try getCacheScriptPath(alloc);
|
||||
defer alloc.free(script_path);
|
||||
|
||||
var child = Child.init(&[_][]const u8{ script_path, "clear" }, alloc);
|
||||
child.stdout_behavior = .Pipe;
|
||||
child.stderr_behavior = .Pipe;
|
||||
|
||||
try child.spawn();
|
||||
|
||||
const stdout = try child.stdout.?.readToEndAlloc(alloc, std.math.maxInt(usize));
|
||||
defer alloc.free(stdout);
|
||||
|
||||
const stderr = try child.stderr.?.readToEndAlloc(alloc, std.math.maxInt(usize));
|
||||
defer alloc.free(stderr);
|
||||
|
||||
_ = try child.wait();
|
||||
|
||||
// Output the results regardless of exit code
|
||||
try writer.writeAll(stdout);
|
||||
if (stderr.len > 0) {
|
||||
try writer.writeAll(stderr);
|
||||
}
|
||||
|
||||
// Script handles its own success/error messaging, so we don't need to check exit code
|
||||
}
|
||||
Reference in New Issue
Block a user