mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 05:43:11 +00:00
Bracketed paste: Strip leading spaces if they'd trigger histignore
Similar to the last commit, only for the in-terminal-paste stuff. Also cleans up the comments on bracketed paste a bit - nobody has stepped forward to report problems with old emacsen or windows, so there's no need for a TODO comment. See #4327.
This commit is contained in:
parent
ad0c8cfb83
commit
a5a643f854
1 changed files with 13 additions and 13 deletions
|
@ -110,7 +110,6 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod
|
|||
bind --preset $argv \ee edit_command_buffer
|
||||
bind --preset $argv \ev edit_command_buffer
|
||||
|
||||
|
||||
# Tmux' focus events.
|
||||
# Exclude paste mode because that should get _everything_ literally.
|
||||
for mode in (bind --list-modes | string match -v paste)
|
||||
|
@ -129,23 +128,17 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod
|
|||
#
|
||||
# We enable it after every command and disable it before (in __fish_config_interactive.fish)
|
||||
#
|
||||
# Support for this seems to be ubiquitous - emacs enables it unconditionally (!) since 25.1 (though it only supports it since then,
|
||||
# it seems to be the last term to gain support).
|
||||
# TODO: Should we disable this in older emacsen?
|
||||
# Support for this seems to be ubiquitous - emacs enables it unconditionally (!) since 25.1
|
||||
# (though it only supports it since then, it seems to be the last term to gain support).
|
||||
#
|
||||
# NOTE: This is more of a "security" measure than a proper feature.
|
||||
# The better way to paste remains the `fish_clipboard_paste` function (bound to \cv by default).
|
||||
# We don't disable highlighting here, so it will be redone after every character (which can be slow),
|
||||
# and it doesn't handle "paste-stop" sequences in the paste (which the terminal needs to strip, but KDE konsole doesn't).
|
||||
# and it doesn't handle "paste-stop" sequences in the paste (which the terminal needs to strip).
|
||||
#
|
||||
# See http://thejh.net/misc/website-terminal-copy-paste. The second case will not be caught in KDE konsole.
|
||||
# See http://thejh.net/misc/website-terminal-copy-paste.
|
||||
|
||||
# Bind the starting sequence in every bind mode, even user-defined ones.
|
||||
|
||||
# We usually just pass the text through as-is to facilitate pasting code,
|
||||
# but when the current token contains an unbalanced single-quote (`'`),
|
||||
# we escape all single-quotes and backslashes, effectively turning the paste
|
||||
# into one literal token, to facilitate pasting non-code (e.g. markdown or git commitishes)
|
||||
|
||||
# Exclude paste mode or there'll be an additional binding after switching between emacs and vi
|
||||
for mode in (bind --list-modes | string match -v paste)
|
||||
bind --preset -M $mode -m paste \e\[200~ '__fish_start_bracketed_paste'
|
||||
|
@ -155,10 +148,17 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod
|
|||
# In paste-mode, everything self-inserts except for the sequence to get out of it
|
||||
bind --preset -M paste "" self-insert
|
||||
# Without this, a \r will overwrite the other text, rendering it invisible - which makes the exercise kinda pointless.
|
||||
# TODO: Test this in windows (\r\n line endings)
|
||||
bind --preset -M paste \r "commandline -i \n"
|
||||
|
||||
# We usually just pass the text through as-is to facilitate pasting code,
|
||||
# but when the current token contains an unbalanced single-quote (`'`),
|
||||
# we escape all single-quotes and backslashes, effectively turning the paste
|
||||
# into one literal token, to facilitate pasting non-code (e.g. markdown or git commitishes)
|
||||
bind --preset -M paste "'" "__fish_commandline_insert_escaped \' \$__fish_paste_quoted"
|
||||
bind --preset -M paste \\ "__fish_commandline_insert_escaped \\\ \$__fish_paste_quoted"
|
||||
# Only insert spaces if we're either quoted or not at the beginning of the commandline
|
||||
# - this strips leading spaces if they would trigger histignore.
|
||||
bind --preset -M paste \ 'if set -q __fish_paste_quoted[1]; or string length -q -- (commandline -c); commandline -i " "; end'
|
||||
end
|
||||
|
||||
function __fish_commandline_insert_escaped --description 'Insert the first arg escaped if a second arg is given'
|
||||
|
|
Loading…
Reference in a new issue