From 421ce13be694ec4cb0f0ccefa379b0b4e3459b8d Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Fri, 6 Dec 2024 12:24:02 +0100 Subject: [PATCH] Fix replacing completions spuriously quoting ~ Commit 29dc30711 (Insert some completions with quotes instead of backslashes, 2024-04-13) wrongly copmletes $ cat ~/space to $ cat '~/path with spaces' Today completions can be either replacing or appending. We never quote (but backslash-escape) appending completions (unless they "append" to an empty token). We always quote replacing completions. The assumption in this part of the code is that replacing completions can be quoted without changing meaning. This assumption is wrong for tildes. For the backslash-escaping code path, we take care of this edge case via a special DONT_ESCAPE_TILDES flag. However that flag does not take effect when using quotes for escaping. Fix that. Unfortunately, e97a4fab7 (Escape : and = in file completions, 2024-04-19) introduced a (hopefully temporary) code clone in escape_separators, which made added an extra step to debugging here. --- src/common.rs | 2 +- tests/checks/tmux-complete2.fish | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/checks/tmux-complete2.fish diff --git a/src/common.rs b/src/common.rs index 3d69408ab..213723ffb 100644 --- a/src/common.rs +++ b/src/common.rs @@ -196,7 +196,7 @@ fn escape_string_script(input: &wstr, flags: EscapeFlags) -> WString { ); let mut need_escape = false; - let mut need_complex_escape = false; + let mut need_complex_escape = no_tilde && input.char_at(0) == '~'; let mut double_quotes = 0; let mut single_quotes = 0; let mut dollars = 0; diff --git a/tests/checks/tmux-complete2.fish b/tests/checks/tmux-complete2.fish new file mode 100644 index 000000000..5ef0ea118 --- /dev/null +++ b/tests/checks/tmux-complete2.fish @@ -0,0 +1,13 @@ +#RUN: %fish %s +#REQUIRES: command -v tmux +#REQUIRES: uname -r | grep -qv Microsoft +# cautiously disable because tmux-complete.fish is disabled +#REQUIRES: test -z "$CI" + +isolated-tmux-start + +isolated-tmux send-keys 'touch ~/"path with spaces"' Enter C-l \ + 'cat ~/space' Tab +tmux-sleep +isolated-tmux capture-pane -p +# CHECK: prompt 1> cat ~/path\ with\ spaces