From 6d000e51014a2c34a510539ed9f4e8b9a0c8c059 Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Sat, 23 Sep 2017 00:35:26 +0100 Subject: Add exec command --- src/imv.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/imv.c b/src/imv.c index db2a9fb..da18058 100644 --- a/src/imv.c +++ b/src/imv.c @@ -106,6 +106,7 @@ void command_zoom(struct imv_list *args, void *data); void command_remove(struct imv_list *args, void *data); void command_fullscreen(struct imv_list *args, void *data); void command_overlay(struct imv_list *args, void *data); +void command_exec(struct imv_list *args, void *data); static bool setup_window(struct imv *imv); static void handle_event(struct imv *imv, SDL_Event *event); @@ -151,6 +152,7 @@ struct imv *imv_create(void) imv_command_register(imv->commands, "remove", &command_remove); imv_command_register(imv->commands, "fullscreen", &command_fullscreen); imv_command_register(imv->commands, "overlay", &command_overlay); + imv_command_register(imv->commands, "exec", &command_exec); imv_command_alias(imv->commands, "q", "quit"); imv_command_alias(imv->commands, "next", "select_rel 1"); @@ -1035,4 +1037,19 @@ void command_overlay(struct imv_list *args, void *data) imv->need_redraw = true; } +void command_exec(struct imv_list *args, void *data) +{ + (void)data; + char *cmd = calloc(4096, 1); + for(size_t i = 0; i < args->len; ++i) { + strcat(cmd, args->items[i]); + + if(i + 1 != args->len) { + strcat(cmd, " "); + } + } + system(cmd); + free(cmd); +} + /* vim:set ts=2 sts=2 sw=2 et: */ -- cgit v1.2.3