1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
//! Fish completions.
const std = @import("std");
const Config = @import("../config/Config.zig");
const Action = @import("../cli.zig").ghostty.Action;
/// A fish completions configuration that contains all the available commands
/// and options.
pub const completions = comptimeGenerateCompletions();
fn comptimeGenerateCompletions() []const u8 {
comptime {
@setEvalBranchQuota(50000);
var counter: std.Io.Writer.Discarding = .init(&.{});
try writeCompletions(&counter.writer);
var buf: [counter.count]u8 = undefined;
var writer: std.Io.Writer = .fixed(&buf);
try writeCompletions(&writer);
const final = buf;
return final[0..writer.end];
}
}
fn writeCompletions(writer: *std.Io.Writer) !void {
{
try writer.writeAll("set -l commands \"");
var count: usize = 0;
for (@typeInfo(Action).@"enum".fields) |field| {
if (std.mem.eql(u8, "help", field.name)) continue;
if (std.mem.eql(u8, "version", field.name)) continue;
if (count > 0) try writer.writeAll(" ");
try writer.writeAll("+");
try writer.writeAll(field.name);
count += 1;
}
try writer.writeAll("\"\n");
}
try writer.writeAll("complete -c ghostty -f\n");
try writer.writeAll("complete -c ghostty -s e -l help -f\n");
try writer.writeAll("complete -c ghostty -n \"not __fish_seen_subcommand_from $commands\" -l version -f\n");
for (@typeInfo(Config).@"struct".fields) |field| {
if (field.name[0] == '_') continue;
try writer.writeAll("complete -c ghostty -n \"not __fish_seen_subcommand_from $commands\" -l ");
try writer.writeAll(field.name);
try writer.writeAll(if (field.type != bool) " -r" else " ");
if (std.mem.startsWith(u8, field.name, "font-family"))
try writer.writeAll(" -f -a \"(ghostty +list-fonts | grep '^[A-Z]')\"")
else if (std.mem.eql(u8, "theme", field.name))
try writer.writeAll(" -f -a \"(ghostty +list-themes | sed -E 's/^(.*) \\(.*\\$/\\1/')\"")
else if (std.mem.eql(u8, "working-directory", field.name))
try writer.writeAll(" -f -k -a \"(__fish_complete_directories)\"")
else {
try writer.writeAll(if (field.type != Config.RepeatablePath) " -f" else " -F");
switch (@typeInfo(field.type)) {
.bool => {},
.@"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("\"");
},
.@"struct" => |info| {
if (!@hasDecl(field.type, "parseCLI") and info.layout == .@"packed") {
try writer.writeAll(" -a \"");
for (info.fields, 0..) |f, i| {
if (i > 0) try writer.writeAll(" ");
try writer.writeAll(f.name);
try writer.writeAll(" no-");
try writer.writeAll(f.name);
}
try writer.writeAll("\"");
}
},
else => {},
}
}
try writer.writeAll("\n");
}
{
try writer.writeAll("complete -c ghostty -n \"string match -q -- '+*' (commandline -pt)\" -f -a \"");
var count: usize = 0;
for (@typeInfo(Action).@"enum".fields) |field| {
if (std.mem.eql(u8, "help", field.name)) continue;
if (std.mem.eql(u8, "version", field.name)) continue;
if (count > 0) try writer.writeAll(" ");
try writer.writeAll("+");
try writer.writeAll(field.name);
count += 1;
}
try writer.writeAll("\"\n");
}
for (@typeInfo(Action).@"enum".fields) |field| {
if (std.mem.eql(u8, "help", field.name)) continue;
if (std.mem.eql(u8, "version", field.name)) continue;
const options = @field(Action, field.name).options();
for (@typeInfo(options).@"struct".fields) |opt| {
if (opt.name[0] == '_') continue;
try writer.writeAll("complete -c ghostty -n \"__fish_seen_subcommand_from +" ++ field.name ++ "\" -l ");
try writer.writeAll(opt.name);
try writer.writeAll(if (opt.type != bool) " -r" else "");
// special case +validate_config --config-file
if (std.mem.eql(u8, "config-file", opt.name)) {
try writer.writeAll(" -F");
} else try writer.writeAll(" -f");
switch (@typeInfo(opt.type)) {
.bool => {},
.@"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("\"");
},
.optional => |optional| {
switch (@typeInfo(optional.child)) {
.@"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 => {},
}
},
else => {},
}
try writer.writeAll("\n");
}
}
}
|