-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwdgen.sh
executable file
·54 lines (44 loc) · 1.08 KB
/
wdgen.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/bash
src="${1:-.}"
prefix=${2:-wd}
if [ ! -d "$src" ]; then
exit 1
fi
declare -A nodes
defwd() {
local key=${1%.*}
if [ $key == $1 ]; then
return 1
fi
if [ -z ${nodes[$key]} ]; then
nodes[$key]=1
defwd $key
if [ $? -eq 1 ]; then
local module=${key#.}
echo -e "local $module = require(\"$module\")"
fi
echo -en "$prefix.$key = {}\n\n"
fi
return 0
}
cat <<END
-- THIS FILE WAS AUTOGENERATED - DO NOT MODIFY --
---@class $prefix
---@operator call: wibox.widget.base
local $prefix = {}
END
for wd in $(find "$src" -name "*.lua" -exec grep -Pho '\b'$prefix'(\.\w+)+\b' {} + | sort | uniq); do
twd=${wd#$prefix.}
defwd $twd
cat <<END
---@param args $wd
---@return $wd
function $wd(args) args.layout = $twd; return args; end
END
done
if [ -z ${nodes[wibox]} ]; then
nodes[wibox]=1
echo "local wibox = require(\"wibox\")"
fi
echo "local base = wibox.widget.base"
echo "return setmetatable(wd, { __call = function(_, args) return base.make_widget_declarative(args) end })"