I've just moved to Awesome WM from OpenBox. I like that it's very extensible, customizable and I have huge control about window layout. I like structured and organized things and I'd like to separate that huge .config/awesome/rc.lua configuration into multiple files.
- 55,929
- 26
- 146
- 227
- 4,014
- 4
- 33
- 48
2 Answers
You can simply place code in a separate file and include it with
dofile("somefile.lua")
Note: The working directory is $HOME. To specify a file relative to rc.lua you can use
dofile(awful.util.getdir("config") .. "/" .. "somefile.lua")
If it's more than just some code and it might be used by others as well, it might make sense to create a lua module which can be included with
somemodule = require("somemodule")
- 33,188
- 10
- 112
- 146
-
It works at 50%, I have to specify full path instead of relative path – kravemir Oct 28 '12 at 21:32
-
@Miro fixed, see update. – Marco Oct 28 '12 at 22:17
-
On Ubuntu, Awesome's require function looks automatically in .config/awesome/, so you can make a require of any file you put there. – wdev Dec 22 '13 at 01:35
To move code into a different file, you create a module and require the module in the rc.lua.
To create a module, you simply call module (name [, ···]) in the script that has the code you pulled out of the original script. Lua reference - module.
To use the module you created, you just call require (modname). Lua reference - require.
There is an excellent tutorial on the Lua wiki that explains this with examples. And if you want to see how module() really works, there is an article on Play With Lua that starts by writing an implementation of module().
- 45,338
- 25
- 134
- 145
-
1Note that starting with awesome-3.5 the lua version was updated to 5.2, where the `module()` function is deprecated. Therefore the module must be assigned to a variable, like `modname = require ("modname")` – crater2150 Jan 09 '13 at 12:01