Ticket #4521: really escape fish shell history.

Some of the "service" commands generated by the mc "leak" into the fish
subshell history available to the user. An example to reproduce:

  *  set user shell to fish and start mc (SHELL=/usr/bin/fish mc)
  *  navigate to any directory
  *  press Ctrl+o
  *  press \u2191 button (UP, go back in history)
  *  observe " cd (printf '%b' ... " command

This commit avoids the " cd (printf '%b' ... " commands in the fish
history.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Anton Anikin 2024-02-04 18:36:45 +03:00 committed by Andrew Borodin
parent a58e0a1d61
commit ae4553442f
1 changed files with 19 additions and 3 deletions

View File

@ -1714,6 +1714,18 @@ do_subshell_chdir (const vfs_path_t * vpath, gboolean update_prompt)
return;
}
}
/* A quick and dirty fix for fish shell. For some reason, fish does not
* execute all the commands sent to it from Midnight Commander :(
* An example of such buggy behavior is presented in ticket #4521.
* TODO: Find the real cause and fix it "the right way" */
if (mc_global.shell->type == SHELL_FISH)
{
write_all (mc_global.tty.subshell_pty, "\n", 1);
subshell_state = RUNNING_COMMAND;
feed_subshell (QUIETLY, TRUE);
}
/* The initial space keeps this out of the command history (in bash
because we set "HISTCONTROL=ignorespace") */
write_all (mc_global.tty.subshell_pty, " cd ", 4);
@ -1778,12 +1790,16 @@ do_subshell_chdir (const vfs_path_t * vpath, gboolean update_prompt)
}
}
/* Really escape Zsh history */
if (mc_global.shell->type == SHELL_ZSH)
/* Really escape Zsh/Fish history */
if (mc_global.shell->type == SHELL_ZSH || mc_global.shell->type == SHELL_FISH)
{
/* Per Zsh documentation last command prefixed with space lingers in the internal history
* until the next command is entered before it vanishes. To make it vanish right away,
* type a space and press return. */
* type a space and press return.
*
* Fish shell now also provides the same behavior:
* https://github.com/fish-shell/fish-shell/commit/9fdc4f903b8b421b18389a0f290d72cc88c128bb
* */
write_all (mc_global.tty.subshell_pty, " \n", 2);
subshell_state = RUNNING_COMMAND;
feed_subshell (QUIETLY, TRUE);