Added drun-print_command
This commit is contained in:
		@@ -38,6 +38,11 @@ If true spaces will not be treated as part of the executable name but rather as
 | 
			
		||||
.B show_all=\fIBOOL\fR
 | 
			
		||||
If true shows all the entries in path, this will show entries that have the same executable name, for example /bin/bash and /usr/bin/bash will be shown separately as bash instead of having one bash entry for the first one encountered, default is true.
 | 
			
		||||
 | 
			
		||||
.SH DRUN CONFIG OPTIONS
 | 
			
		||||
.TP
 | 
			
		||||
.B print_command=\fIBOOL\fR
 | 
			
		||||
If true the command used to launch the desktop file will be printed to stdout instead of invoking it, default is false.
 | 
			
		||||
 | 
			
		||||
.SH DRUN
 | 
			
		||||
When images are enabled drun mode will pull icon themes however being a GTK app it's possible you'll need to run gtk\-update\-icon\-cache to get them to apply.
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										30
									
								
								modes/drun.c
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								modes/drun.c
									
									
									
									
									
								
							@@ -19,6 +19,8 @@
 | 
			
		||||
 | 
			
		||||
#include <gio/gdesktopappinfo.h>
 | 
			
		||||
 | 
			
		||||
static const char* arg_names[] = {"print_command"};
 | 
			
		||||
 | 
			
		||||
static struct mode* mode;
 | 
			
		||||
 | 
			
		||||
struct node {
 | 
			
		||||
@@ -28,6 +30,8 @@ struct node {
 | 
			
		||||
 | 
			
		||||
static struct wl_list widgets;
 | 
			
		||||
 | 
			
		||||
static bool print_command;
 | 
			
		||||
 | 
			
		||||
static char* get_text(char* file, char* action) {
 | 
			
		||||
	GDesktopAppInfo* info = g_desktop_app_info_new_from_filename(file);
 | 
			
		||||
	if(info == NULL || g_desktop_app_info_get_is_hidden(info) || g_desktop_app_info_get_nodisplay(info)) {
 | 
			
		||||
@@ -226,9 +230,10 @@ static void insert_dir(char* app_dir, struct map* cached, struct map* entries) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wofi_drun_init(struct mode* this, struct map* config) {
 | 
			
		||||
	(void) config;
 | 
			
		||||
	mode = this;
 | 
			
		||||
 | 
			
		||||
	print_command = strcmp(config_get(config, "print_command", "false"), "true") == 0;
 | 
			
		||||
 | 
			
		||||
	struct map* cached = map_init();
 | 
			
		||||
	struct map* entries = map_init();
 | 
			
		||||
	struct wl_list* cache = wofi_read_cache(mode);
 | 
			
		||||
@@ -329,18 +334,35 @@ void wofi_drun_exec(const gchar* cmd) {
 | 
			
		||||
	GDesktopAppInfo* info = g_desktop_app_info_new_from_filename(cmd);
 | 
			
		||||
	if(G_IS_DESKTOP_APP_INFO(info)) {
 | 
			
		||||
		wofi_write_cache(mode, cmd);
 | 
			
		||||
		g_app_info_launch_uris_async(G_APP_INFO(info), NULL, NULL, NULL, launch_done, (gchar*) cmd);
 | 
			
		||||
		if(print_command) {
 | 
			
		||||
			printf("%s\n", g_app_info_get_commandline(G_APP_INFO(info)));
 | 
			
		||||
			exit(0);
 | 
			
		||||
		} else {
 | 
			
		||||
			g_app_info_launch_uris_async(G_APP_INFO(info), NULL, NULL, NULL, launch_done, (gchar*) cmd);
 | 
			
		||||
		}
 | 
			
		||||
	} else if(strrchr(cmd, ' ') != NULL) {
 | 
			
		||||
		char* space = strrchr(cmd, ' ');
 | 
			
		||||
		*space = 0;
 | 
			
		||||
		wofi_write_cache(mode, cmd);
 | 
			
		||||
		info = g_desktop_app_info_new_from_filename(cmd);
 | 
			
		||||
		char* action = space + 1;
 | 
			
		||||
		g_desktop_app_info_launch_action(info, action, NULL);
 | 
			
		||||
		utils_sleep_millis(500);
 | 
			
		||||
		if(print_command) {
 | 
			
		||||
			printf("%s\n", g_app_info_get_commandline(G_APP_INFO(info)));
 | 
			
		||||
		} else {
 | 
			
		||||
			g_desktop_app_info_launch_action(info, action, NULL);
 | 
			
		||||
			utils_sleep_millis(500);
 | 
			
		||||
		}
 | 
			
		||||
		exit(0);
 | 
			
		||||
	} else {
 | 
			
		||||
		fprintf(stderr, "%s cannot be executed\n", cmd);
 | 
			
		||||
		exit(1);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char** wofi_drun_get_arg_names(void) {
 | 
			
		||||
	return arg_names;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
size_t wofi_drun_get_arg_count(void) {
 | 
			
		||||
	return sizeof(arg_names) / sizeof(char*);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user