-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathmdfind.ts
100 lines (97 loc) · 2.6 KB
/
mdfind.ts
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
const smartFolderGenerator: Fig.Generator = {
// `mdfind -s` only accepts smart folders in ~/Library/Saved\ Searches/
custom: async (_, executeCommand, context) => {
const { stdout } = await executeCommand({
command: "ls",
args: [
"-1A",
`${context.environmentVariables["HOME"]}/Library/Saved Searches/`,
],
});
return stdout
.split("\n")
.filter((file) => file.endsWith("savedSearch"))
.map((path) => {
const components = path.split("/");
const filename = components[components.length - 1];
return {
name: filename.substring(0, filename.indexOf(".")), // .savedSearch automatically added to the query, so remove it
displayName: filename,
icon: "fig://" + path,
description: "Smart folder",
};
});
},
trigger: "/",
};
const completionSpec: Fig.Spec = {
name: "mdfind",
description: "Finds files matching a given query",
parserDirectives: {
flagsArePosixNoncompliant: true,
},
options: [
{
name: ["--help", "-h"],
description: "Show help for mdfind",
},
{
name: "-0",
description: "Prints an ASCII NUL character after each result path",
},
{
name: "-live",
description:
"Provide live-updates to the number of files matching the query",
},
{
name: "-count",
description:
"Output the total number of matches, instead of the path to the matching items",
},
{
name: "-onlyin",
description: "Limit the scope of the search to <dir>",
args: {
name: "dir",
description: "Directory",
template: "folders",
},
},
{
name: "-name",
description: "Search for matching file names to <filename> only",
args: {
name: "filename",
},
},
{
name: "-reprint",
description: "Reprint results on live update",
},
{
name: "-s",
description:
"Show contents of smart folder ~/Library/Saved Searches/<folder>.savedSearch",
args: {
name: "folder",
description: "Smart folder in ~/Library/Saved Searches",
generators: smartFolderGenerator,
},
},
{
name: "-literal",
description:
"Force the provided query string to be taken as a literal query string, without interpretation",
},
{
name: "-interpret",
description:
"Force the provided query string to be interpreted as if it had been typed into the Spotlight menu",
},
],
args: {
name: "query",
},
};
export default completionSpec;