@@ -21,6 +21,7 @@ static bool no_footer;
2121static bool no_header ;
2222static bool pipemenu ;
2323static bool show_desktop_filename ;
24+ static char * terminal_prefix ;
2425
2526static 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
4447static void
4548usage (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
82100static 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