Ticket #4126: 0004-prevent-word-splitting-of-the-subshell-command-buffe.patch

File 0004-prevent-word-splitting-of-the-subshell-command-buffe.patch, 2.8 KB (added by ossi, 4 years ago)
  • src/subshell/common.c

    From 7447bd9c9c8021bd0cac1128297bb056643d2480 Mon Sep 17 00:00:00 2001
    From: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
    Date: Thu, 8 Oct 2020 17:29:33 +0200
    Subject: [PATCH 4/7] prevent word-splitting of the subshell command buffer
    
    this avoids inadvertent whitespace normalization (compression and
    trimming), which is annoying and additionally invalidates the cursor
    position.
    
    for bash and zsh that meant quoting the variable expansion, while for
    fish it meant removing the pointless indirection through echo.
    for bash we had to introduce an indirection through a function, as there
    is apparently no way to get the quoting right inside the binding. zsh
    already had such an indirection - maybe for the same reason?
    
    amends ff0fc17a.
    ---
     src/subshell/common.c | 9 +++++----
     1 file changed, 5 insertions(+), 4 deletions(-)
    
    diff --git a/src/subshell/common.c b/src/subshell/common.c
    index 3e1a2f7ee..f9f6aca4e 100644
    a b init_subshell_precmd (char *precmd, size_t buff_size) 
    10541054    { 
    10551055    case SHELL_BASH: 
    10561056        g_snprintf (precmd, buff_size, 
    1057                     " bind -x '\"\\e" SHELL_BUFFER_KEYBINDING "\":\"echo $READLINE_LINE>&%d\"'\n" 
     1057                    " mc_print_command_buffer () { echo \"$READLINE_LINE\" >&%d; }\n" 
     1058                    " bind -x '\"\\e" SHELL_BUFFER_KEYBINDING "\":\"mc_print_command_buffer\"'\n" 
    10581059                    " bind -x '\"\\e" SHELL_CURSOR_KEYBINDING "\":\"echo $READLINE_POINT>&%d\"'\n" 
    10591060                    " PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND\n}'pwd>&%d;kill -STOP $$'\n" 
    10601061                    "PS1='\\u@\\h:\\w\\$ '\n", 
    init_subshell_precmd (char *precmd, size_t buff_size) 
    11171118 
    11181119    case SHELL_ZSH: 
    11191120        g_snprintf (precmd, buff_size, 
    1120                     " mc_print_command_buffer () { echo $BUFFER >&%d}\n" 
     1121                    " mc_print_command_buffer () { echo \"$BUFFER\"' >&%d}\n" 
    11211122                    " zle -N mc_print_command_buffer\n" 
    11221123                    " bindkey '^[" SHELL_BUFFER_KEYBINDING "' mc_print_command_buffer\n" 
    11231124                    " mc_print_cursor_position () { echo $CURSOR >&%d}\n" 
    init_subshell_precmd (char *precmd, size_t buff_size) 
    11361137        break; 
    11371138    case SHELL_FISH: 
    11381139        g_snprintf (precmd, buff_size, 
    1139                     " bind \\e" SHELL_BUFFER_KEYBINDING " 'echo (commandline)>&%d';" 
    1140                     "bind \\e" SHELL_CURSOR_KEYBINDING " 'echo (commandline -C)>&%d';" 
     1140                    " bind \\e" SHELL_BUFFER_KEYBINDING " 'commandline >&%d';" 
     1141                    "bind \\e" SHELL_CURSOR_KEYBINDING " 'commandline -C >&%d';" 
    11411142                    "if not functions -q fish_prompt_mc;" 
    11421143                    "functions -e fish_right_prompt;" 
    11431144                    "functions -c fish_prompt fish_prompt_mc; end;"