From 10ef0d9daf267cc01c13f3b2c063127e2058e3da Mon Sep 17 00:00:00 2001 From: Fabian Homborg <FHomborg@gmail.com> Date: Sat, 6 Mar 2021 08:40:07 +0100 Subject: [PATCH] Fix clipboard_paste nicer Instead of hacking in arbitrary characters to avoid splitting, just use `string collect`. This reverts commit e450190d50aecefd26f932f6868bb128ae817441. Fixes #7782, but nicer. --- share/functions/__fish_tokenizer_state.fish | 10 ++-------- share/functions/fish_clipboard_paste.fish | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/share/functions/__fish_tokenizer_state.fish b/share/functions/__fish_tokenizer_state.fish index af218b71a..42940f2d3 100644 --- a/share/functions/__fish_tokenizer_state.fish +++ b/share/functions/__fish_tokenizer_state.fish @@ -8,9 +8,7 @@ function __fish_tokenizer_state --description "Print the state of the tokenizer # - single-escaped - open \\ inside single-quotes # - double-escaped - open \\ inside double-quotes - # Don't expect one arg only, as (commandline -ct) may evaluate to multiple arguments since - # output is forcibly split on new lines (issue #7782). - argparse --min-args 1 i/initial-state= -- $argv + argparse --min-args 1 --max-args 1 i/initial-state= -- $argv or return 1 set -l state normal @@ -18,11 +16,7 @@ function __fish_tokenizer_state --description "Print the state of the tokenizer set str $_flag_initial_state end - # HACK: We care about quotes and don't care about new lines, joining multi-line arguments - # produced by (commandline -ct) on anything other than \n will corrupt the contents but will - # allow the following logic to work (including escape of subsequent character). This entire - # function should probably be implemented as part of the `commandline` builtin. - for char in (string split -- "" (string join -- \x1e $argv)) + for char in (string split -- "" $argv[1]) switch $char case "'" # single-quote switch $state diff --git a/share/functions/fish_clipboard_paste.fish b/share/functions/fish_clipboard_paste.fish index 3801c7eab..6cd12ae29 100644 --- a/share/functions/fish_clipboard_paste.fish +++ b/share/functions/fish_clipboard_paste.fish @@ -26,7 +26,7 @@ function fish_clipboard_paste # in order to turn it into a single literal token. # # This eases pasting non-code (e.g. markdown or git commitishes). - set -l quote_state (__fish_tokenizer_state -- (commandline -ct)) + set -l quote_state (__fish_tokenizer_state -- (commandline -ct | string collect)) if contains -- $quote_state single single-escaped if status test-feature regex-easyesc set data (string replace -ra "(['\\\])" '\\\\$1' -- $data)