Also replace $FILE and % in shortcut

Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
Sebastian Ramacher 2017-06-07 19:14:14 +02:00
parent b4c87e05aa
commit 5a106c56f4
3 changed files with 49 additions and 0 deletions

View file

@ -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);

View file

@ -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);
}

View file

@ -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