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.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Oswald Buddenhagen 2020-10-08 17:29:33 +02:00 committed by Andrew Borodin
parent 86397c87c6
commit 77c910a818

View File

@ -1060,7 +1060,8 @@ init_subshell_precmd (char *precmd, size_t buff_size)
{
case SHELL_BASH:
g_snprintf (precmd, buff_size,
" bind -x '\"\\e" SHELL_BUFFER_KEYBINDING "\":\"echo $READLINE_LINE>&%d\"'\n"
" mc_print_command_buffer () { echo \"$READLINE_LINE\" >&%d; }\n"
" bind -x '\"\\e" SHELL_BUFFER_KEYBINDING "\":\"mc_print_command_buffer\"'\n"
" bind -x '\"\\e" SHELL_CURSOR_KEYBINDING "\":\"echo $READLINE_POINT>&%d\"'\n"
" PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND\n}'pwd>&%d;kill -STOP $$'\n"
"PS1='\\u@\\h:\\w\\$ '\n",
@ -1123,7 +1124,7 @@ init_subshell_precmd (char *precmd, size_t buff_size)
case SHELL_ZSH:
g_snprintf (precmd, buff_size,
" mc_print_command_buffer () { echo $BUFFER >&%d}\n"
" mc_print_command_buffer () { echo \"$BUFFER\"' >&%d}\n"
" zle -N mc_print_command_buffer\n"
" bindkey '^[" SHELL_BUFFER_KEYBINDING "' mc_print_command_buffer\n"
" mc_print_cursor_position () { echo $CURSOR >&%d}\n"
@ -1142,8 +1143,8 @@ init_subshell_precmd (char *precmd, size_t buff_size)
break;
case SHELL_FISH:
g_snprintf (precmd, buff_size,
" bind \\e" SHELL_BUFFER_KEYBINDING " 'echo (commandline)>&%d';"
"bind \\e" SHELL_CURSOR_KEYBINDING " 'echo (commandline -C)>&%d';"
" bind \\e" SHELL_BUFFER_KEYBINDING " 'commandline >&%d';"
"bind \\e" SHELL_CURSOR_KEYBINDING " 'commandline -C >&%d';"
"if not functions -q fish_prompt_mc;"
"functions -e fish_right_prompt;"
"functions -c fish_prompt fish_prompt_mc; end;"