bindings: disallow executing an external command when in view mode

Otherwise the user could do something like

  ^R^X  sed -i 's/a/surprise!/g' name-of-current-file  <Enter>

and the file being viewed would be modified anyway.
master
Benno Schulenberg 2019-03-31 20:05:30 +02:00
parent b9581bd50a
commit 4399b734db
2 changed files with 3 additions and 3 deletions

View File

@ -1039,7 +1039,7 @@ void shortcut_init(void)
N_("No Conversion"), WITHORSANS(convert_gist), TOGETHER, NOVIEW); N_("No Conversion"), WITHORSANS(convert_gist), TOGETHER, NOVIEW);
/* Command execution is only available when not in restricted mode. */ /* Command execution is only available when not in restricted mode. */
if (!ISSET(RESTRICTED)) { if (!ISSET(RESTRICTED) && !ISSET(VIEW_MODE)) {
add_to_funcs(flip_execute, MINSERTFILE, add_to_funcs(flip_execute, MINSERTFILE,
N_("Execute Command"), WITHORSANS(execute_gist), TOGETHER, NOVIEW); N_("Execute Command"), WITHORSANS(execute_gist), TOGETHER, NOVIEW);
@ -1331,7 +1331,7 @@ void shortcut_init(void)
add_to_sclist(MWRITEFILE, "M-M", 0, mac_format_void, 0); add_to_sclist(MWRITEFILE, "M-M", 0, mac_format_void, 0);
/* Only when not in restricted mode, allow Appending, Prepending, /* Only when not in restricted mode, allow Appending, Prepending,
* making backups, and executing a command. */ * making backups, and executing a command. */
if (!ISSET(RESTRICTED)) { if (!ISSET(RESTRICTED) && !ISSET(VIEW_MODE)) {
add_to_sclist(MWRITEFILE, "M-A", 0, append_void, 0); add_to_sclist(MWRITEFILE, "M-A", 0, append_void, 0);
add_to_sclist(MWRITEFILE, "M-P", 0, prepend_void, 0); add_to_sclist(MWRITEFILE, "M-P", 0, prepend_void, 0);
add_to_sclist(MWRITEFILE, "M-B", 0, backup_file_void, 0); add_to_sclist(MWRITEFILE, "M-B", 0, backup_file_void, 0);

View File

@ -462,7 +462,7 @@ void parse_binding(char *ptr, bool dobind)
menu = menu & (is_universal(newsc->func) ? MMOST : mask); menu = menu & (is_universal(newsc->func) ? MMOST : mask);
if (!menu) { if (!menu) {
if (!ISSET(RESTRICTED)) if (!ISSET(RESTRICTED) && !ISSET(VIEW_MODE))
rcfile_error(N_("Function '%s' does not exist in menu '%s'"), rcfile_error(N_("Function '%s' does not exist in menu '%s'"),
funcptr, menuptr); funcptr, menuptr);
goto free_things; goto free_things;