diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-08-16 18:09:06 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-11-01 10:04:03 (GMT) |
commit | 45451301f8b33626f6799061d2815c1d5080d3aa (patch) | |
tree | e4def724dc3594fd5515f0a258e5da0a4bdacaec /util/update_keys.lua | |
parent | 4d1d4466ca8803a233a19afb8e88e7d279f19512 (diff) | |
download | fluxbox_pavel-45451301f8b33626f6799061d2815c1d5080d3aa.zip fluxbox_pavel-45451301f8b33626f6799061d2815c1d5080d3aa.tar.bz2 |
fluxbox-update_configs: automatically update keys file
Diffstat (limited to 'util/update_keys.lua')
-rw-r--r-- | util/update_keys.lua | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/util/update_keys.lua b/util/update_keys.lua new file mode 100644 index 0000000..5edab2c --- /dev/null +++ b/util/update_keys.lua | |||
@@ -0,0 +1,48 @@ | |||
1 | local file = ...; | ||
2 | local keymodes = {}; | ||
3 | local failed = false; | ||
4 | |||
5 | local function process_line(line) | ||
6 | if string.match(line, '^%s*$') ~= nil then | ||
7 | return line; | ||
8 | end; | ||
9 | local comment = string.match(line, '^%s*[#!](.*)$'); | ||
10 | if comment ~= nil then | ||
11 | return '--' .. comment; | ||
12 | end; | ||
13 | |||
14 | local mode, key, cmd = string.match(line, '^%s*(%a%w*):%s*([^:]-)%s*:(.*)$'); | ||
15 | if key == nil then | ||
16 | key, cmd = string.match(line, '^%s*([^:]*):(.*)$'); | ||
17 | end; | ||
18 | |||
19 | if mode == nil or mode == 'default' then | ||
20 | mode = 'default_keymode'; | ||
21 | else | ||
22 | keymodes[mode] = true; | ||
23 | end; | ||
24 | |||
25 | if key ~= nil then | ||
26 | return string.format('%s[%q] = %q', mode, key, cmd); | ||
27 | else | ||
28 | failed = true; | ||
29 | return '-- FBCV16 ' .. line; | ||
30 | end; | ||
31 | end; | ||
32 | |||
33 | file = string.gsub(file, '[^\n]*', process_line); | ||
34 | |||
35 | local decls = ''; | ||
36 | for k, v in pairs(keymodes) do | ||
37 | decls = decls .. k .. ' = newKeyMode();\n'; | ||
38 | end; | ||
39 | |||
40 | if failed == true then | ||
41 | decls = [[ | ||
42 | --fluxbox-update_configs could not convert some of the lines into the new format. | ||
43 | --These lines are marked with FBCV16 and you will have to convert them yourself. | ||
44 | |||
45 | ]] .. decls; | ||
46 | end; | ||
47 | |||
48 | return decls .. '\n' .. file; | ||