-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb
executable file
·218 lines (189 loc) · 7.24 KB
/
web
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/ruby
require 'yaml'
class BrowserChooser
STYLES = {
fx: ->(profile, env, bin, arg, conf) {
exec(env, bin, "-P", profile, *arg)
},
chr: ->(profile, env, bin, arg, conf) {
profile = File.join(conf[:profile_dir], profile)
exec(env, bin, "--user-data-dir=#{profile}", *arg)
},
epp: ->(profile, env, bin, arg, conf) {
profile = File.join(conf[:profile_dir], profile)
exec(env, bin, "--profile=#{profile}", *arg)
},
flk: ->(profile, env, bin, arg, conf) {
exec(env, bin, "-p", profile, *arg)
},
myb: ->(profile, env, bin, arg, conf) {
profile = File.join(conf[:profile_dir], profile)
exec(env, bin, "--basedir=#{profile}", *arg)
},
wvf: ->(profile, env, bin, arg, conf) {
profile = "//profile/#{profile}"
exec(env, bin, "//target/0", profile, *arg)
},
}
############ Bind browser name to style proc ############
BROWSERS = {
"fx" => {bin: "firefox", proc: STYLES[:fx]},
"fxbeta" => {bin: "firefox-beta", proc: STYLES[:fx]},
"fxdev" => {bin: "firefox-developer-edition", proc: STYLES[:fx]},
"wfx" => {bin: "waterfox", proc: STYLES[:fx]},
"pm" => {bin: "palemoon", proc: STYLES[:fx]},
"smk" => {bin: "seamonkey", proc: STYLES[:fx]},
"wolf" => {bin: "librewolf", proc: STYLES[:fx]},
"cachy" => {bin: "cachy-browser", proc: STYLES[:fx]},
"ict" => {bin: "ictcat", proc: STYLES[:fx]},
"flk" => {bin: "falkon", proc: STYLES[:flk]},
"ch" => {bin: "chromium", proc: STYLES[:chr]},
"chdev" => {bin: "chromium-developer", proc: STYLES[:chr]},
"gch" => {bin: "google-chrome-stable", proc: STYLES[:chr]},
"gchbeta" => {bin: "google-chrome-beta", proc: STYLES[:chr]},
"gchdev" => {bin: "google-chrome-developer", proc: STYLES[:chr]},
"op" => {bin: "opera", proc: STYLES[:chr]},
"opbeta" => {bin: "opera-beta", proc: STYLES[:chr]},
"opdev" => {bin: "opera-developer", proc: STYLES[:chr]},
"viv" => {bin: "vivaldi-stable", proc: STYLES[:chr]},
"vivsnap" => {bin: "vivaldi-snapshot", proc: STYLES[:chr]},
"edg" => {bin: "microsoft-edge-stable", proc: STYLES[:chr]},
"edgbeta" => {bin: "microsoft-edge-beta", proc: STYLES[:chr]},
"edgdev" => {bin: "microsoft-edge-dev", proc: STYLES[:chr]},
"br" => {bin: "brave", proc: STYLES[:chr]},
"sj" => {bin: "flashpeak-slimjet", proc: STYLES[:chr]},
"sri" => {bin: "srware-iron", proc: STYLES[:chr]},
"ott" => {bin: "otter-browser", proc: STYLES[:epp]},
"epp" => {bin: "epiphany", proc: STYLES[:epp]},
"myb" => {bin: "mybrowse", proc: STYLES[:myb]},
"wvf" => {bin: "weaver", proc: STYLES[:wvf]},
"lfx1" => {bin: "firefox", proc: STYLES[:fx]},
"lfx2" => {bin: "firefox", proc: STYLES[:fx]},
"lfx3" => {bin: "firefox", proc: STYLES[:fx]},
"lfx4" => {bin: "firefox", proc: STYLES[:fx]},
"lfx5" => {bin: "firefox", proc: STYLES[:fx]},
"lch1" => {bin: "chromium", proc: STYLES[:chr]},
"lch2" => {bin: "chromium", proc: STYLES[:chr]},
"lch3" => {bin: "chromium", proc: STYLES[:chr]},
"lch4" => {bin: "chromium", proc: STYLES[:chr]},
"lch5" => {bin: "chromium", proc: STYLES[:chr]},
}
########################################################
##### Browser name aliases #####
BROWSERS["firefox"] = BROWSERS["fx"]
BROWSERS["seamonkey"] = BROWSERS["smk"]
BROWSERS["pmoon"] = BROWSERS["pm"]
BROWSERS["palemoon"] = BROWSERS["pm"]
BROWSERS["icecat"] = BROWSERS["ict"]
BROWSERS["falkon"] = BROWSERS["flk"]
BROWSERS["chi"] = BROWSERS["ch"]
BROWSERS["chr"] = BROWSERS["ch"]
BROWSERS["chromium"] = BROWSERS["ch"]
BROWSERS["chrome"] = BROWSERS["gch"]
BROWSERS["opera"] = BROWSERS["op"]
BROWSERS["vivaldi"] = BROWSERS["viv"]
BROWSERS["edge"] = BROWSERS["edg"]
BROWSERS["brave"] = BROWSERS["br"]
BROWSERS["epiphany"] = BROWSERS["epp"]
BROWSERS["slimjet"] = BROWSERS["sj"]
BROWSERS["iron"] = BROWSERS["sri"]
BROWSERS["srware"] = BROWSERS["sri"]
BROWSERS["otter"] = BROWSERS["ott"]
BROWSERS["mybrowse"] = BROWSERS["myb"]
BROWSERS["weaver"] = BROWSERS["wvf"]
##################################
# Ask your profile if not given.
def profile_dialog
selected_profile = nil
profile = nil
case @config["Dialog"]
when "yad"
IO.popen(["yad", "--list", "--title=Select Browser Profile", "--width=400", "--height=500", "--column=Profile", *@profiles.keys], "r") do |io|
selected_profile = io.read
end
profile = selected_profile&.strip&.delete_suffix("|")
if ! @profiles[profile] || @profiles[profile] == "-"
profile = (@config["Default"] && @profiles[@config["Default"]]) or exit 0
end
when "kdialog"
IO.popen(["kdialog", "--title=Select Browser Profile", "--menu", "Profile", *@profiles.keys.map {|i| [i, i] }.flatten], "r") do |io|
selected_profile = io.read
end
profile = selected_profile&.strip
if ! @profiles[profile] || @profiles[profile] == "-"
profile = (@config["Default"] && @profiles[@config["Default"]]) or exit 0
end
else
IO.popen(["zenity", "--list", "--title=Select Browser Profile", "--width=400", "--height=800", "--column=Profile", *@profiles.keys], "r") do |io|
selected_profile = io.read
end
profile = selected_profile&.strip
if ! @profiles[profile] || @profiles[profile] == "-"
profile = (@config["Default"] && @profiles[@config["Default"]]) or exit 0
end
end
@specified_profile = profile
end
def initialize
load_config
# Update web browser binary path.
@browsers = BROWSERS.clone
@config["Override"]&.each do |k, v|
@browsers[k] && @browsers[k][:bin] = v
end
# regist each profile.
(@profiles = @config["Profiles"]) or err "No Profiles found."
@profiles.each do |k, profile|
unless profile["type"] && BROWSERS[profile["type"]]
err "Profile #{k} is wrong."
end
end
@config[:profile_dir] = @config["PathBase"] || "#{ENV["XDG_CONFIG_HOME"] || "#{ENV["HOME"]}/.config}"}/reasonset/browsers"
# set profile
@specified_profile = ARGV.shift
invoke_browser
end
def load_config
@config = YAML.load(File.read("#{ENV["HOME"]}/.config/reasonset/browserprofiles.yaml")) rescue err("config file not found or parse error.")
unless Hash === @config
err "Your config is not a Hash."
end
end
def invoke_browser
if !@specified_profile || @specified_profile == "-"
profile_dialog
end
unless @profiles[@specified_profile]
err "Profile #{@specified_profile} is not exist."
end
unless @browsers[@profiles[@specified_profile]["type"]]
err "Type #{@browsers[@profiles[@specified_profile]["type"]]} is not defined."
end
fork do
params = @profiles[@specified_profile]
arg = ARGV
if params["opts"]
arg = params["opts"] + ARGV
end
if params["url"]
arg.push params["url"]
end
@browsers[params["type"]][:proc].call(
(params["pstr"] || @specified_profile),
(params["env"] || {}),
@browsers[params["type"]][:bin],
arg,
@config)
end
end
private
def err(msg)
if STDERR.isatty
abort msg
else
system("notify-send", "--icon=browser", "--expire-time=5000", msg)
exit false
end
end
end
BrowserChooser.new