Skip to content

Commit

Permalink
Ticket #4521: really escape fish shell history.
Browse files Browse the repository at this point in the 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 <[email protected]>
  • Loading branch information
htower authored and aborodin committed Feb 11, 2024
1 parent a58e0a1 commit ae45534
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/subshell/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ae45534

Please sign in to comment.