Commit 5a106c56 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Also replace $FILE and % in shortcut

Signed-off-by: Sebastian Ramacher's avatarSebastian Ramacher <sebastian+dev@ramacher.at>
parent b4c87e05
......@@ -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);
......
......@@ -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);
}
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment