-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add support for bracketed paste #3871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -232,6 +232,23 @@ function __fish_config_interactive -d "Initializations that should be performed | |
| # Load key bindings | ||
| __fish_reload_key_bindings | ||
|
|
||
| if not set -q FISH_UNIT_TESTS_RUNNING | ||
| # Enable bracketed paste before every prompt (see __fish_shared_bindings for the bindings). | ||
| # Disable it for unit tests so we don't have to add the sequences to bind.expect | ||
| function __fish_enable_bracketed_paste --on-event fish_prompt | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a very fishy way to do this. Very cool. I was thinking we need to also emit the magic sequence to disable bracketed paste mode when exiting the shell, such as in response to a signal, but honestly that is such an unlikely scenario I think we should defer doing so until someone complains.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm complaining 😉 It's pretty weird to me that if I start a bash shell, type
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 4ff002b.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taking for 2.6.0. |
||
| printf "\e[?2004h" | ||
| end | ||
|
|
||
| # Disable BP before every command because that might not support it. | ||
| function __fish_disable_bracketed_paste --on-event fish_preexec | ||
| printf "\e[?2004l" | ||
| end | ||
|
|
||
| # Tell the terminal we support BP. Since we are in __f_c_i, the first fish_prompt | ||
| # has already fired. | ||
| __fish_enable_bracketed_paste | ||
| end | ||
|
|
||
| function __fish_winch_handler --on-signal WINCH -d "Repaint screen when window changes size" | ||
| commandline -f repaint | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,4 +105,41 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod | |
| # The [meta-e] and [meta-v] keystrokes invoke an external editor on the command buffer. | ||
| bind \ee edit_command_buffer | ||
| bind \ev edit_command_buffer | ||
|
|
||
| # Support for "bracketed paste" | ||
| # The way it works is that we acknowledge our support by printing | ||
| # \e\[?2004h | ||
| # then the terminal will "bracket" every paste in | ||
| # \e\[200~ and \e\[201~ | ||
| # Every character in between those two will be part of the paste and should not cause a binding to execute (like \n executing commands). | ||
| # | ||
| # 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? | ||
| # | ||
| # 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). | ||
| # | ||
| # See http://thejh.net/misc/website-terminal-copy-paste. The second case will not be caught in KDE konsole. | ||
| # Bind the starting sequence in every bind mode, even user-defined ones. | ||
| # HACK: We introspect `bind` here to list all modes. | ||
| # Re-running `bind` multiple times per mode is still faster than trying to make the list unique, | ||
| # even without calling `sort -u` or `uniq`, for the vi-bindings. | ||
| # TODO: This can be solved better once #3872 is implemented. | ||
| set -l allmodes default | ||
| set allmodes $allmodes (bind -a | string match -r -- '-M \w+' | string replace -- '-M ' '') | ||
| for mode in $allmodes | ||
| bind -M $mode -m paste \e\[200~ 'set -g __fish_last_bind_mode $fish_bind_mode' | ||
| end | ||
| # This sequence ends paste-mode and returns to the previous mode we have saved before. | ||
| bind -M paste \e\[201~ 'set fish_bind_mode $__fish_last_bind_mode; commandline -f force-repaint' | ||
| # In paste-mode, everything self-inserts except for the sequence to get out of it | ||
| bind -M paste "" self-insert | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this paste mode documented anywhere? I was looking to make a plugin similar to https://www.npmjs.com/package/hyperterm-paste with fish, and need this feature to do it.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @e-beach: That right there is basically the extent of our documentation on it. For those transformations, implementing it here seems difficult. You'll want to use something like
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right on. Thanks! |
||
| # 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 -M paste \r "commandline -i \n" | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL! It's nice to see another use for that var so soon after I added it.