diff --git a/zathura/config.c b/zathura/config.c index 4cff53b..5eea251 100644 --- a/zathura/config.c +++ b/zathura/config.c @@ -467,6 +467,7 @@ config_load_default(zathura_t* zathura) girara_shortcut_mapping_add(gsession, "bisect", sc_bisect); girara_shortcut_mapping_add(gsession, "change_mode", sc_change_mode); girara_shortcut_mapping_add(gsession, "display_link", sc_display_link); + girara_shortcut_mapping_add(gsession, "exec", sc_exec); girara_shortcut_mapping_add(gsession, "focus_inputbar", sc_focus_inputbar); girara_shortcut_mapping_add(gsession, "follow", sc_follow); girara_shortcut_mapping_add(gsession, "goto", sc_goto); diff --git a/zathura/shortcuts.c b/zathura/shortcuts.c index 26da4fb..55e4e38 100644 --- a/zathura/shortcuts.c +++ b/zathura/shortcuts.c @@ -1419,3 +1419,40 @@ sc_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t* return false; } + +bool +sc_exec(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t) +{ + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + + if (argument == NULL || argument->data == NULL) { + return false; + } + + if (zathura->document != NULL) { + const char* path = zathura_document_get_path(zathura->document); + + girara_argument_t new_argument = *argument; + + char* r = girara_replace_substring(argument->data, "$FILE", path); + if (r == NULL) { + return false; + } + + char* s = girara_replace_substring(r, "%", path); + g_free(r); + + if (s == NULL) { + return false; + } + + new_argument.data = s; + const bool ret = girara_sc_exec(session, &new_argument, event, t); + g_free(s); + return ret; + } + + return girara_sc_exec(session, argument, event, t); +} diff --git a/zathura/shortcuts.h b/zathura/shortcuts.h index dc3c30f..195554a 100644 --- a/zathura/shortcuts.h +++ b/zathura/shortcuts.h @@ -281,4 +281,15 @@ bool sc_quit(girara_session_t* session, girara_argument_t* argument, girara_even */ bool sc_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); +/** + * Run external command. + * + * @param session The used girara session + * @param argument The used argument + * @param event Girara event + * @param t Number of executions + * @return true if no error occurred otherwise false + */ +bool sc_exec(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); + #endif // SHORTCUTS_H