Skip to content

Commit 9068fd4

Browse files
author
Peter Kosyh
committed
-mcmd
1 parent 5cfc71f commit 9068fd4

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ Options:
6363
* -lfile - write all input commands to file;
6464
* -cpCODEPAGE - Win only (1251 by default), use 65001 for UTF-8;
6565
* -a - autosave on exit and autoload on start (autosave file);
66-
* -x - execute lua script.
66+
* -x - execute lua script;
67+
* -m - enable multimedia output;
68+
* -mcmd - enable run cmd on multimedia (for ex. -m/usr/bin/xdg-open).
6769

6870
## Links
6971

main.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <errno.h>
2929
#include <unistd.h>
3030
#include <locale.h>
31+
#include <sys/wait.h>
3132
#ifdef _WIN32
3233
#include <windows.h>
3334
#endif
@@ -40,6 +41,7 @@ static int opt_lua = 0;
4041
static int opt_debug = 0;
4142
static int opt_width = WIDTH;
4243
static char *opt_autoload = NULL;
44+
static const char *mmedia_bin = NULL;
4345
static int opt_autosave = 1;
4446
static int opt_mmedia = 0;
4547
static int need_restart = 0;
@@ -217,6 +219,23 @@ static char *media_fn[] = {
217219
"instead.get_music"
218220
};
219221

222+
static void mmedia_run(const char *f)
223+
{
224+
pid_t pid;
225+
int status;
226+
if (!mmedia_bin || !mmedia_bin[0])
227+
return;
228+
pid = fork();
229+
if (pid == -1)
230+
return;
231+
else if (pid > 0) {
232+
waitpid(pid, &status, 0);
233+
} else {
234+
execl(mmedia_bin, mmedia_bin, f, NULL);
235+
exit(1);
236+
}
237+
}
238+
220239
static void mmedia(int t)
221240
{
222241
char *mm;
@@ -235,6 +254,7 @@ static void mmedia(int t)
235254
media[t] = mm;
236255
if (mm && *mm) { /* changed */
237256
printf("@ %s\n", mm);
257+
mmedia_run(mm);
238258
}
239259
}
240260
}
@@ -264,8 +284,9 @@ int main(int argc, const char **argv)
264284
opt_autosave = 1;
265285
} else if (!strcmp(argv[i], "-x")) {
266286
opt_lua = 1;
267-
} else if (!strcmp(argv[i], "-m")) {
287+
} else if (!strncmp(argv[i], "-m", 2)) {
268288
opt_mmedia = 1;
289+
mmedia_bin = argv[i] + 2;
269290
} else if (!strncmp(argv[i], "-d", 2)) {
270291
opt_debug = 1;
271292
reopen_stderr(argv[i] + 2);

0 commit comments

Comments
 (0)