summaryrefslogtreecommitdiff
path: root/awesomerc/rc-choose.lua
blob: c30f52ca9bc55ffe9c16800d39102fe10bd6ac3f (plain)
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
-- Choose which RC to run based on what Awesome is running
-- and also whether or not that RC crashed last time

local rcgroup = "unknown"

if awesome.release == "Smack" then
   rcgroup = "3.4.9"
else
   if string.match(awesome.version, "%-g[0-9a-f]+$") then
      rcgroup = "git"
   end
end

-- For now, if we detect we're running 3.4.9 release then
-- we force ourselves to choose to run the /etc/ RC file
if rcgroup == "3.4.9" then
   return assert(loadfile("/etc/xdg/awesome/rc.lua"))()
end

-- If we're running the GIT version then we have to
-- consider where to find the default RC
local defaultrc = "/usr/local/etc/xdg/awesome/rc.lua"
local tracebackfilename = os.getenv("HOME") .. "/.config/awesome/rc-git-traceback.txt"

-- If we find that we have a traceback then we run
-- the default RC and then ensure we spawn an editor with it in.
local tracebackfh = io.open(tracebackfilename, "r")
if tracebackfh then
   tracebackfh:close()
   assert(loadfile(defaultrc))()
   require("awful").util.spawn("gnome-open " .. tracebackfilename, false)
   return
end

-- Otherwise we're going to try and run the main RC and failing that
-- we're going to store the traceback and restart awesome.

local function try_run_rc()
   local homec = os.getenv("HOME") .. "/.resources/awesomerc/rc-" .. rcgroup
   package.path = package.path .. ";" .. homec .. "/?.lua;" .. homec .. "/?/init.lua"
   require("rc-" .. rcgroup)
   -- TODO: Perform various sanity checks such as there being at least one tag
   -- on each screen.  For now, this'll do.
end

local ok, traceback = xpcall(try_run_rc, debug.traceback)

if not ok then
   tracebackfh = io.open(tracebackfilename, "w")
   tracebackfh:write(traceback)
   tracebackfh:close()
   awesome.restart()
end

-- Either we were OK, or bad crud happened, either way, let awesome try
-- and fall back however it might.