Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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. But I'm still newbie to Awesome and I've never used lua before.

share|improve this question

2 Answers 2

up vote 10 down vote accepted

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")
share|improve this answer
    
It works at 50%, I have to specify full path instead of relative path –  Miro 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().

share|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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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