-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.vala
99 lines (89 loc) · 2.73 KB
/
options.vala
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
class Options {
public string[] terminal_command {
get;
private set;
default = {"/usr/bin/urxvt", "-pe", "-tabbed"};
}
public string[] default_command {
get;
private set;
default = {"/bin/sh"};
}
string[]? _first_command;
public string[] first_command {
get {
return (_first_command != null) ? _first_command : default_command;
}
}
public bool pause_paste {
get;
private set;
default = false;
}
public Options() {
string? shell = Environment.get_variable("SHELL");
if (shell == null) {
Posix.Passwd* pw = Posix.getpwuid(Posix.getuid());
if (pw != null) {
shell = pw->pw_shell;
}
}
if (shell != null && shell != "") {
default_command = {(!) shell};
}
}
public void load_options()
throws KeyFileError, ShellError
{
var filename = make_config_filename();
var keyfile = new KeyFile();
try {
keyfile.load_from_file(filename, KeyFileFlags.NONE);
}
catch (FileError e) {
// Probably doesn't exist.
return;
}
var group = "urxvt_frame";
if (keyfile.has_key(group, "terminal_command")) {
var v = keyfile.get_string(group, "terminal_command");
string[]? argv = null;
if (Shell.parse_argv(v, out argv)) {
terminal_command = argv;
}
}
if (keyfile.has_key(group, "default_command")) {
var v = keyfile.get_string(group, "default_command");
string[]? argv = null;
if (Shell.parse_argv(v, out argv)) {
default_command = argv;
}
}
if (keyfile.has_key(group, "pause_paste")) {
pause_paste = keyfile.get_boolean(group, "pause_paste");
}
}
string make_config_filename() {
var home_dir = Environment.get_home_dir();
var filename = Path.build_filename(home_dir,
".config/urxvt_frame/urxvt_frame.conf");
return filename;
}
public void parse_command_line_options(string[] argv)
throws OptionError
{
// We don't accept any command line arguments other than -e
// at the moment.
for (int i = 1; i < argv.length; i++) {
if (argv[i] == "-e") {
if (i == argv.length - 1) {
throw new OptionError.BAD_VALUE(
"option '-e' requires an argument");
}
_first_command = argv[i + 1 : argv.length];
return;
}
}
}
}
// vim: ft=cs ts=8 sts=4 sw=4 et