-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.d
88 lines (79 loc) · 2.81 KB
/
app.d
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
import std.stdio;
import std.getopt;
import std.process;
import desktopfile.file;
import isfreedesktop;
@safe string currentLocale() nothrow
{
try {
return environment.get("LC_CTYPE", environment.get("LC_ALL", environment.get("LANG")));
}
catch(Exception e) {
return null;
}
}
void main(string[] args)
{
if (args.length < 3) {
writefln("Usage: %s <read|exec|link|start|write> <desktop-file> <optional arguments>", args[0]);
return;
}
string command = args[1];
string inFile = args[2];
string locale = currentLocale();
if (command == "read") {
auto df = new DesktopFile(inFile);
writefln("Name: %s. Localized: %s", df.displayName(), df.localizedDisplayName(locale));
writefln("GenericName: %s. Localized: %s", df.genericName(), df.localizedGenericName(locale));
writefln("Comment: %s. Localized: %s", df.comment(), df.localizedComment(locale));
writeln("Type: ", df.value("Type"));
writeln("Icon: ", df.iconName());
static if (isFreedesktop) {
writeln("Desktop ID: ", df.id());
}
writefln("Actions: %(%s %)", df.actions());
writefln("Categories: %(%s %)", df.categories());
writefln("MimeTypes: %(%s %)", df.mimeTypes());
if (df.type() == DesktopFile.Type.Application) {
writeln("Exec: ", df.execString());
writeln("In terminal: ", df.terminal());
writeln("Trusted: ", isTrusted(df.fileName));
}
if (df.type() == DesktopFile.Type.Link) {
writeln("URL: ", df.url());
}
} else if (command == "exec") {
auto df = new DesktopFile(inFile);
string action;
getopt(args, "action", "Action to run", &action);
if (action.length) {
auto desktopAction = df.action(action);
if (desktopAction is null) {
stderr.writefln("No such action %s", action);
} else {
desktopAction.start();
}
} else {
string[] urls = args[3..$];
writeln("Exec:", df.expandExecString(urls, locale));
df.startApplication(urls, locale);
}
} else if (command == "link") {
auto df = new DesktopFile(inFile);
writeln("Link:", df.url());
df.startLink();
} else if (command == "start") {
auto df = new DesktopFile(inFile);
df.start();
} else if (command == "write") {
auto df = new DesktopFile(inFile, DesktopFile.ReadOptions.preserveComments);
if (args.length > 3) {
string outFile = args[3];
df.saveToFile(outFile);
} else {
writeln(df.saveToString());
}
} else {
stderr.writefln("unknown command '%s'", command);
}
}