From b43a14c5aa861b51ff1f24efa148e2689d9e4799 Mon Sep 17 00:00:00 2001
From: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Date: Thu, 8 Oct 2020 20:30:47 +0200
Subject: [PATCH 7/7] disable subshell cursor position translation for bash v5+
the changelog clearly states that the position is now returned as a
character offset.
amends ff0fc17a.
---
src/subshell/common.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/src/subshell/common.c b/src/subshell/common.c
index b9e04e8ea..0f54ec42a 100644
a
|
b
|
read_command_line_buffer (gboolean test_mode) |
518 | 518 | struct timeval subshell_prompt_timer = { 0, 0 }; |
519 | 519 | int command_buffer_length; |
520 | 520 | int command_buffer_char_length; |
| 521 | int bash_version; |
521 | 522 | int cursor_position; |
522 | 523 | int maxfdp; |
523 | 524 | int rc; |
524 | | char *end; |
525 | 525 | |
526 | 526 | if (!use_persistent_buffer) |
527 | 527 | return TRUE; |
… |
… |
read_command_line_buffer (gboolean test_mode) |
612 | 612 | return FALSE; |
613 | 613 | |
614 | 614 | subshell_cursor_buffer[bytes - 1] = '\0'; |
615 | | cursor_position = strtol (subshell_cursor_buffer, &end, 10); |
616 | | if (end == subshell_cursor_buffer) |
617 | | return FALSE; |
| 615 | if (mc_global.shell->type == SHELL_BASH) |
| 616 | { |
| 617 | if (sscanf (subshell_cursor_buffer, "%d:%d", &bash_version, &cursor_position) != 2) |
| 618 | return FALSE; |
| 619 | } |
| 620 | else |
| 621 | { |
| 622 | if (sscanf (subshell_cursor_buffer, "%d", &cursor_position) != 1) |
| 623 | return FALSE; |
| 624 | bash_version = 1000; |
| 625 | } |
618 | 626 | |
619 | 627 | if (test_mode) |
620 | 628 | return TRUE; |
… |
… |
read_command_line_buffer (gboolean test_mode) |
629 | 637 | input_assign_text (cmdline, ""); |
630 | 638 | input_insert (cmdline, subshell_command_buffer, FALSE); |
631 | 639 | |
632 | | if (mc_global.shell->type == SHELL_BASH) |
| 640 | if (bash_version < 5) /* implies SHELL_BASH */ |
633 | 641 | { |
634 | | /* We need to do this because bash gives the cursor position in a utf-8 string based |
| 642 | /* We need to do this because bash < v5 gives the cursor position in a utf-8 string based |
635 | 643 | * on the location in bytes, not in unicode characters. */ |
636 | 644 | char *curr = subshell_command_buffer; |
637 | 645 | char *stop = curr + cursor_position; |
… |
… |
init_subshell_precmd (char *precmd, size_t buff_size) |
1056 | 1064 | g_snprintf (precmd, buff_size, |
1057 | 1065 | " mc_print_command_buffer () { printf \"%%s\\\\n\" \"$READLINE_LINE\" >&%d; }\n" |
1058 | 1066 | " bind -x '\"\\e" SHELL_BUFFER_KEYBINDING "\":\"mc_print_command_buffer\"'\n" |
1059 | | " bind -x '\"\\e" SHELL_CURSOR_KEYBINDING "\":\"echo $READLINE_POINT>&%d\"'\n" |
| 1067 | " bind -x '\"\\e" SHELL_CURSOR_KEYBINDING "\":\"echo $BASH_VERSINFO:$READLINE_POINT >&%d\"'\n" |
1060 | 1068 | " PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND\n}'pwd>&%d;kill -STOP $$'\n" |
1061 | 1069 | "PS1='\\u@\\h:\\w\\$ '\n", |
1062 | 1070 | command_buffer_pipe[WRITE], command_buffer_pipe[WRITE], subshell_pipe[WRITE]); |