mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
fish: reuse Action options iteration code
This commit is contained in:
@ -2,9 +2,6 @@ const std = @import("std");
|
|||||||
|
|
||||||
const Config = @import("../config/Config.zig");
|
const Config = @import("../config/Config.zig");
|
||||||
const Action = @import("../cli/action.zig").Action;
|
const Action = @import("../cli/action.zig").Action;
|
||||||
const ListFontsOptions = @import("../cli/list_fonts.zig").Options;
|
|
||||||
const ShowConfigOptions = @import("../cli/show_config.zig").Options;
|
|
||||||
const ListKeybindsOptions = @import("../cli/list_keybinds.zig").Options;
|
|
||||||
|
|
||||||
/// A fish completions configuration that contains all the available commands
|
/// A fish completions configuration that contains all the available commands
|
||||||
/// and options.
|
/// and options.
|
||||||
@ -100,66 +97,35 @@ fn writeFishCompletions(writer: anytype) !void {
|
|||||||
try writer.writeAll("\"\n");
|
try writer.writeAll("\"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (@typeInfo(ListFontsOptions).Struct.fields) |field| {
|
for (@typeInfo(Action).Enum.fields) |field| {
|
||||||
if (field.name[0] == '_') continue;
|
if (std.mem.eql(u8, "help", field.name)) continue;
|
||||||
try writer.writeAll("complete -c ghostty -n \"__fish_seen_subcommand_from +list-fonts\" -l ");
|
if (std.mem.eql(u8, "version", field.name)) continue;
|
||||||
try writer.writeAll(field.name);
|
|
||||||
try writer.writeAll(if (field.type != bool) " -r" else " ");
|
|
||||||
try writer.writeAll(" -f");
|
|
||||||
switch (@typeInfo(field.type)) {
|
|
||||||
.Bool => try writer.writeAll(" -a \"true false\""),
|
|
||||||
.Enum => |info| {
|
|
||||||
try writer.writeAll(" -a \"");
|
|
||||||
for (info.fields, 0..) |f, i| {
|
|
||||||
if (i > 0) try writer.writeAll(" ");
|
|
||||||
try writer.writeAll(f.name);
|
|
||||||
}
|
|
||||||
try writer.writeAll("\"");
|
|
||||||
},
|
|
||||||
else => {},
|
|
||||||
}
|
|
||||||
try writer.writeAll("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (@typeInfo(ShowConfigOptions).Struct.fields) |field| {
|
const options = @field(Action, field.name).options();
|
||||||
if (field.name[0] == '_') continue;
|
for (@typeInfo(options).Struct.fields) |opt| {
|
||||||
try writer.writeAll("complete -c ghostty -n \"__fish_seen_subcommand_from +show-config\" -l ");
|
if (opt.name[0] == '_') continue;
|
||||||
try writer.writeAll(field.name);
|
try writer.writeAll("complete -c ghostty -n \"__fish_seen_subcommand_from +" ++ field.name ++ "\" -l ");
|
||||||
try writer.writeAll(if (field.type != bool) " -r" else " ");
|
try writer.writeAll(opt.name);
|
||||||
try writer.writeAll(" -f");
|
try writer.writeAll(if (opt.type != bool) " -r" else "");
|
||||||
switch (@typeInfo(field.type)) {
|
|
||||||
.Bool => try writer.writeAll(" -a \"true false\""),
|
|
||||||
.Enum => |info| {
|
|
||||||
try writer.writeAll(" -a \"");
|
|
||||||
for (info.fields, 0..) |f, i| {
|
|
||||||
if (i > 0) try writer.writeAll(" ");
|
|
||||||
try writer.writeAll(f.name);
|
|
||||||
}
|
|
||||||
try writer.writeAll("\"");
|
|
||||||
},
|
|
||||||
else => {},
|
|
||||||
}
|
|
||||||
try writer.writeAll("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (@typeInfo(ListKeybindsOptions).Struct.fields) |field| {
|
// special case +validate_config --config-file
|
||||||
if (field.name[0] == '_') continue;
|
if (std.mem.eql(u8, "config-file", opt.name)) {
|
||||||
try writer.writeAll("complete -c ghostty -n \"__fish_seen_subcommand_from +list-keybinds\" -l ");
|
try writer.writeAll(" -F");
|
||||||
try writer.writeAll(field.name);
|
} else try writer.writeAll(" -f");
|
||||||
try writer.writeAll(if (field.type != bool) " -r" else " ");
|
|
||||||
try writer.writeAll(" -f");
|
switch (@typeInfo(opt.type)) {
|
||||||
switch (@typeInfo(field.type)) {
|
.Bool => try writer.writeAll(" -a \"true false\""),
|
||||||
.Bool => try writer.writeAll(" -a \"true false\""),
|
.Enum => |info| {
|
||||||
.Enum => |info| {
|
try writer.writeAll(" -a \"");
|
||||||
try writer.writeAll(" -a \"");
|
for (info.opts, 0..) |f, i| {
|
||||||
for (info.fields, 0..) |f, i| {
|
if (i > 0) try writer.writeAll(" ");
|
||||||
if (i > 0) try writer.writeAll(" ");
|
try writer.writeAll(f.name);
|
||||||
try writer.writeAll(f.name);
|
}
|
||||||
}
|
try writer.writeAll("\"");
|
||||||
try writer.writeAll("\"");
|
},
|
||||||
},
|
else => {},
|
||||||
else => {},
|
}
|
||||||
|
try writer.writeAll("\n");
|
||||||
}
|
}
|
||||||
try writer.writeAll("\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user