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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
.\" generated with Ronn-NG/v0.9.1
.TH "TERMINAL\-MEDIA\-LAUNCHER\-CONFIG" 5
.SH "NAME"
terminal-media-launcher-config - terminal-media-launcher configuration file
.SH SYNOPSIS
~/.config/terminal-media-launcher/config.lua (or ~/.terminal-media-launcher/config.lua)
.SH DESCRIPTION
Starting in version 0\.2, Terminal Media Launcher is configured via a lua \fIhttps://www\.lua\.org/\fR script\. This project assumes the configuration will adhere to lua 5\.1, but is written to be as agnostic as possbile\. The general format of the configuration is outlined below:
.P
.nf
.BI "Groups = { "
.BI " { "
.BI " name = <string>, "
.BI " Launcher = <string>, "
.BI " Flags = <string>,
.BI " Entries = { "
.BI " { "
.BI " name = <string>, "
.BI " path = <string> "
.BI " }, "
.BI " ... "
.BI " } "
.BI " }, "
.BI " ... "
.BI "}"
.SH COMMANDS
.SS "Creating a Group"
The config must contain at least one valid group\. Groups are to be inserted in the \fBGroups\fR global variable\. \fBGroups\fR is an array of tables\. Each group is a table containing the following keys:
.IP "Mandatory keys:"
.IP "\[ci]" 4
\fBname\fR \fIstring\fR \- a name for the group
.IP "\[ci]" 4
\fBEntries\fR \fItable\fR \- an array of tables\. Each table represents an entry\.
.IP "" 0
.IP "Optional keys:"
.IP "\[ci]" 4
\fBLauncher\fR \fIstring\fR \- the path for a program that launches the entries of this group\. If not set, it assumes the entries in this group are executables (and have no launching program)
.IP "\[ci]" 4
\fBFlags\fR \fIstring\fR \- flags to pass to the launching program\. If not set, no flags are passed
.IP "" 0
.IP "" 0
.P
Here is a helper function you can use in your config to add a group
.P
\fB
.EX
local function addGroup(name, launcher, flags)
assert(type(name) == "string")
-- create Groups table if needed
if Groups == nil then
Groups = {}
end
local new_group = {}
new_group.name = name
new_group.Entries = {}
if launcher ~= nil then
new_group.Launcher = launcher
end
if flags ~= nil then
new_group.Flags = flags
end
table.insert(Groups, new_group)
return new_group
end
\fR
.SS "Adding Entries"
For a group to be valid, it must contain at least one valid entry\. Entries are to be inserted in the \fBEntries\fR key of a group table\. \fBEntries\fR is an array of tables\. Each entry is a table containing the following keys:
.IP "Mandatory keys:"
.IP "\[ci]" 4
\fBname\fR \fIstring\fR \- a name for the entry
.IP "" 0
.IP "Optional keys:"
.IP "\[ci]" 4
\fBpath\fR \fIstring\fR \- a path to the file associated with this entry\. If not set, the path is the same as the name
.IP "" 0
.IP "" 0
.P
Here is a helper function you can use in your config to add an entry to a group
.P
\fB
.EX
local function addEntry(parentGroup, name, path)
assert(type(parentGroup) == "table")
assert(type(parentGroup.Entries) == "table")
assert(type(name) == "string")
local new_entry = {}
new_entry.name = name
if path ~= nil then
new_entry.path = path
end
table.insert(parentGroup.Entries, new_entry)
return new_entry
end
\fR
.IP "" 0
.SS "Adding Entries using lfs module"
It is recommended to install the lua\-filesystem \fIhttps://github\.com/lunarmodules/luafilesystem\fR module and use it to add entries more efficiently\. This example can be used to descend into a directory and add files matching a \fBstring\.match\fR pattern to a group\.
\fB
.EX
local lfs = require "lfs"
local function addEntries(parentGroup, startDir, filePattern, recursive)
-- recursive arg is a boolean for whether or not to descend into subdirectories (false by default)
assert(type(parentGroup) == "table")
assert(type(parentGroup.Entries) == "table")
assert(type(startDir) == "string")
assert(type(filePattern) == "string")
for file in lfs.dir(startDir) do
local fullFilePath = startDir .. "/" .. file
if file ~= "." and file ~= ".." then
-- descend into subdirectory if recursive is set to true
if lfs.attributes(fullFilePath).mode == "directory" and recursive == true then
addEntries(parentGroup, fullFilePath, filePattern, recursive)
elseif lfs.attributes(fullFilePath).mode == "file" then
if string.match(file, filePattern) then
table.insert(parentGroup.Entries, {
name = file,
path = fullFilePath
})
end
end
end
end
end
\fR
.SS "Settings"
Settings can be set via the \fBSettings\fR global variable\.
.P
.nf
.BI "Settings = {} "
.BI "Settings\.sort = <boolean>"
\fBsort\fR will sort entries of each group in alphabetical order (though not the list of groups)\. \fBsort\fR is true by default\.
.SH EXAMPLE
Here is an example \fBconfig\.lua\fR which creates a Music, Pictures, and, Videos group, and adds all the files from the user's Music, Pictures, and Videos home folders to each group\.
\fB
.EX
local lfs = require "lfs"
local function addGroup(name, launcher, flags)
assert(type(name) == "string")
-- create Groups table if needed
if Groups == nil then
Groups = {}
end
local new_group = {}
new_group.name = name
new_group.Entries = {}
if launcher ~= nil then
new_group.Launcher = launcher
end
if flags ~= nil then
new_group.Flags = flags
end
table.insert(Groups, new_group)
return new_group
end
local function addEntries(parentGroup, startDir, filePattern, recursive)
-- recursive arg is a boolean for whether or not to descend into subdirectories (false by default)
assert(type(parentGroup) == "table")
assert(type(parentGroup.Entries) == "table")
assert(type(startDir) == "string")
assert(type(filePattern) == "string")
for file in lfs.dir(startDir) do
local fullFilePath = startDir .. "/" .. file
if file ~= "." and file ~= ".." then
-- descend into subdirectory if recursive is set to true
if lfs.attributes(fullFilePath).mode == "directory" and recursive == true then
addEntries(parentGroup, fullFilePath, filePattern, recursive)
elseif lfs.attributes(fullFilePath).mode == "file" then
if string.match(file, filePattern) then
table.insert(parentGroup.Entries, {
name = file,
path = fullFilePath
})
end
end
end
end
end
local music = addGroup("Music", "xdg-open")
addEntries(music, os.getenv("HOME") .. "/Music", ".*", true)
local pictures = addGroup("Pictures", "xdg-open")
addEntries(pictures, os.getenv("HOME") .. "/Pictures", ".*", true)
local videos = addGroup("Videos", "xdg-open")
addEntries(videos, os.getenv("HOME") .. "/Videos", ".*", true)
\fR
.fi
.SH SEE ALSO
\fBterminal-media-launcher\fR(1)
|