1 ---------------------------------------------------------------------------
2 -- @author Julien Danjou <julien@danjou.info>
3 -- @copyright 2008 Julien Danjou
4 -- @release @AWESOME_VERSION@
5 ---------------------------------------------------------------------------
7 -- Grab environment we need
11 local loadstring
= loadstring
12 local loadfile
= loadfile
22 --- Utility module for awful
25 function deprecate(see
)
26 io
.stderr
:write("W: awful: function is deprecated")
28 io
.stderr
:write(", see " .. see
)
31 io
.stderr
:write(debug
.traceback())
34 --- Strip alpha part of color.
35 -- @param color The color.
36 -- @return The color without alpha channel.
37 function color_strip_alpha(color
)
38 if color
:len() == 9 then
39 color
= color
:sub(1, 7)
46 -- @param i An absolute index to fit into #t.
47 -- @return The object at new index.
49 while i
> t
do i
= i
- t
end
50 while i
< 1 do i
= i
+ t
end
54 --- Create a directory
55 -- @param dir The directory.
56 -- @return mkdir return code
58 return os
.execute("mkdir -p " .. dir
)
62 -- @param cmd The command.
63 -- @param screen The screen where to spawn window.
64 -- @return The awesome.spawn return value.
65 function spawn(cmd
, screen
)
66 if cmd
and cmd
~= "" then
67 return capi
.awesome
.spawn(cmd
.. "&", screen
or capi
.mouse
.screen
)
71 -- Read a program output and returns its output as a string.
72 -- @param cmd The command to run.
73 -- @return A string with the program output.
75 if cmd
and cmd
~= "" then
76 local f
= io
.popen(cmd
, 'r')
77 local s
= f
:read("*all")
84 -- @return The return value of Lua code.
86 return assert(loadstring("return " .. s
))()
89 --- Escape a string from XML char.
90 -- Useful to set raw text in textbox.
91 -- @param text Text to escape.
92 -- @return Escape text.
95 text
= text
:gsub("&", "&")
96 text
= text
:gsub("<", "<")
97 text
= text
:gsub(">", ">")
98 text
= text
:gsub("'", "'")
99 text
= text
:gsub("\"", """)
104 --- Unescape a string from entities.
105 -- @param text Text to unescape.
106 -- @return Unescaped text.
107 function unescape(text
)
109 text
= text
:gsub("&", "&")
110 text
= text
:gsub("<", "<")
111 text
= text
:gsub(">", ">")
112 text
= text
:gsub("'", "'")
113 text
= text
:gsub(""", "\"")
118 --- Check if a file is a Lua valid file.
119 -- This is done by loading the content and compiling it with loadfile().
120 -- @param path The file path.
121 -- @return A function if everything is alright, a string with the error
123 function checkfile(path
)
124 local f
, e
= loadfile(path
)
125 -- Return function if function, otherwise return error.
126 if f
then return f
end
130 --- Try to restart awesome.
131 -- It checks if the configuration file is valid, and then restart if it's ok.
132 -- If it's not ok, the error will be returned.
133 -- @return Never return if awesome restart, or return a string error.
135 local c
= checkfile(capi
.awesome
.conffile
)
137 if type(c
) ~= "function" then
141 capi
.awesome
.restart()
145 if d
== "config" then
146 local dir
= os
.getenv("XDG_CONFIG_HOME")
148 return dir
.. "/awesome"
150 return os
.getenv("HOME") .. "/.config/awesome"
151 elseif d
== "cache" then
152 local dir
= os
.getenv("XDG_CACHE_HOME")
154 return dir
.. "/awesome"
156 return os
.getenv("HOME").."/.cache/awesome"
159 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80