Skip to content

Commit ee3d8d0

Browse files
committed
Add --terminal-prefix option
1 parent c2d46a1 commit ee3d8d0

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

Diff for: .github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
run: |
5757
pacman-key --init
5858
pacman -Syu --noconfirm
59-
pacman -S --noconfirm meson gcc clang pkgconf glib2
59+
pacman -S --noconfirm meson gcc clang pkgconf glib2 scdoc
6060
6161
- name: Install FreeBSD dependencies
6262
if: matrix.name == 'FreeBSD'

Diff for: data/labwc-menu-generator.1.scd

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ in directory-schema rather than parsing .menu and .directory files.
3636
*-p, --pipemenu*
3737
Output in pipemenu format
3838

39+
*-t, --terminal-prefix <command>*
40+
Specify prefix for Terminal=true entries, for example 'foot' or
41+
'xterm -e'
42+
3943
# AUTHORS
4044

4145
The Labwc Team - https://github.com/labwc/labwc-menu-generator
@@ -48,4 +52,4 @@ https://github.com/labwc/labwc-menu-generator/issues/
4852

4953
# SEE ALSO
5054

51-
labwc(1), labwc-menu(5), labwc-actions(5)
55+
labwc(1), labwc-menu(5), labwc-actions(5)

Diff for: main.c

+25-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static bool no_footer;
2121
static bool no_header;
2222
static bool pipemenu;
2323
static bool show_desktop_filename;
24+
static char *terminal_prefix;
2425

2526
static const struct option long_options[] = {
2627
{"bare", no_argument, NULL, 'b'},
@@ -29,6 +30,7 @@ static const struct option long_options[] = {
2930
{"ignore", required_argument, NULL, 'i'},
3031
{"no-duplicates", no_argument, NULL, 'n'},
3132
{"pipemenu", no_argument, NULL, 'p'},
33+
{"terminal-prefix", required_argument, NULL, 't'},
3234
{0, 0, 0, 0}
3335
};
3436

@@ -39,7 +41,8 @@ static const char labwc_menu_generator_usage[] =
3941
" -h, --help Show help message and quit\n"
4042
" -i, --ignore <file> Specify file listing .desktop files to ignore\n"
4143
" -n, --no-duplicates Limit desktop entries to one directory only\n"
42-
" -p, --pipemenu Output in pipemenu format\n";
44+
" -p, --pipemenu Output in pipemenu format\n"
45+
" -t, --terminal-prefix Specify prefix for Terminal=true entries\n";
4346

4447
static void
4548
usage(void)
@@ -69,14 +72,29 @@ print_app_to_buffer(struct app *app, GString *submenu)
6972
g_string_append_printf(submenu, " <!-- %s -->\n", app->filename);
7073
}
7174

72-
/* TODO: handle app->terminal */
75+
/*
76+
* For Terminal=true entries we prefix the command if the user has
77+
* specified a --terminal-prefix value. Typical values would be 'foot',
78+
* 'alacritty -e' or 'xterm -e'. Many terminals use the -e option, but
79+
* not all.
80+
*/
81+
gchar *command = app->terminal && terminal_prefix ?
82+
g_strdup_printf("%s '%s'", terminal_prefix, app->exec) :
83+
g_strdup_printf("%s", app->exec);
84+
if (!command) {
85+
fprintf(stderr, "fatal: cannot allocate");
86+
exit(EXIT_FAILURE);
87+
}
88+
7389
g_string_append_printf(submenu,
7490
" <item label=\"%s\" icon=\"%s\">\n",
7591
app->name_localized ? app->name_localized : app->name, app->icon);
7692
g_string_append_printf(submenu,
7793
" <action name=\"Execute\"><command>%s</command></action>\n",
78-
app->exec);
94+
command);
7995
g_string_append_printf(submenu, " </item>\n");
96+
97+
g_free(command);
8098
}
8199

82100
static bool
@@ -294,7 +312,7 @@ main(int argc, char **argv)
294312
int c;
295313
while (1) {
296314
int index = 0;
297-
c = getopt_long(argc, argv, "bdhi:np", long_options, &index);
315+
c = getopt_long(argc, argv, "bdhi:npt:", long_options, &index);
298316
if (c == -1) {
299317
break;
300318
}
@@ -315,6 +333,9 @@ main(int argc, char **argv)
315333
case 'p':
316334
pipemenu = true;
317335
break;
336+
case 't':
337+
terminal_prefix = optarg;
338+
break;
318339
case 'h':
319340
default:
320341
usage();

0 commit comments

Comments
 (0)