@@ -21,6 +21,7 @@ static bool no_footer;
21
21
static bool no_header ;
22
22
static bool pipemenu ;
23
23
static bool show_desktop_filename ;
24
+ static char * terminal_prefix ;
24
25
25
26
static const struct option long_options [] = {
26
27
{"bare" , no_argument , NULL , 'b' },
@@ -29,6 +30,7 @@ static const struct option long_options[] = {
29
30
{"ignore" , required_argument , NULL , 'i' },
30
31
{"no-duplicates" , no_argument , NULL , 'n' },
31
32
{"pipemenu" , no_argument , NULL , 'p' },
33
+ {"terminal-prefix" , required_argument , NULL , 't' },
32
34
{0 , 0 , 0 , 0 }
33
35
};
34
36
@@ -39,7 +41,8 @@ static const char labwc_menu_generator_usage[] =
39
41
" -h, --help Show help message and quit\n"
40
42
" -i, --ignore <file> Specify file listing .desktop files to ignore\n"
41
43
" -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" ;
43
46
44
47
static void
45
48
usage (void )
@@ -69,14 +72,29 @@ print_app_to_buffer(struct app *app, GString *submenu)
69
72
g_string_append_printf (submenu , " <!-- %s -->\n" , app -> filename );
70
73
}
71
74
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
+
73
89
g_string_append_printf (submenu ,
74
90
" <item label=\"%s\" icon=\"%s\">\n" ,
75
91
app -> name_localized ? app -> name_localized : app -> name , app -> icon );
76
92
g_string_append_printf (submenu ,
77
93
" <action name=\"Execute\"><command>%s</command></action>\n" ,
78
- app -> exec );
94
+ command );
79
95
g_string_append_printf (submenu , " </item>\n" );
96
+
97
+ g_free (command );
80
98
}
81
99
82
100
static bool
@@ -294,7 +312,7 @@ main(int argc, char **argv)
294
312
int c ;
295
313
while (1 ) {
296
314
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 );
298
316
if (c == -1 ) {
299
317
break ;
300
318
}
@@ -315,6 +333,9 @@ main(int argc, char **argv)
315
333
case 'p' :
316
334
pipemenu = true;
317
335
break ;
336
+ case 't' :
337
+ terminal_prefix = optarg ;
338
+ break ;
318
339
case 'h' :
319
340
default :
320
341
usage ();
0 commit comments