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.


You can simply place code in a separate file and include it with


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")
|improve this answer|||||
  • 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 1: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().

|improve this answer|||||
  • 1
    Note 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 9 '13 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.