[HN Gopher] Bracketed paste mode (2013)
       ___________________________________________________________________
        
       Bracketed paste mode (2013)
        
       Author : olalonde
       Score  : 37 points
       Date   : 2023-03-19 20:06 UTC (2 hours ago)
        
 (HTM) web link (cirw.in)
 (TXT) w3m dump (cirw.in)
        
       | tzs wrote:
       | > Update: Readline (as of v 7) and thus Bash (as of v4.4) now
       | have support for bracketed paste mode too! You can enable it by
       | adding set enable-bracketed-paste on to your ~/.inputrc.
       | 
       | And as of Readline 8.1 it is enabled by default. That broke the
       | Python REPL on at least Arch Linux, Fedora, and on Mac with
       | Homebrew, and assorted other things that didn't know about
       | bracketed paste mode and so didn't turn it off [1].
       | 
       | [1] https://bugs.python.org/issue42819
        
       | codetrotter wrote:
       | zsh is very nice like this
       | 
       | With bash when I pasted something with line breaks it would
       | execute it right away
       | 
       | With zsh pasted contents is highlighted and you have to press
       | enter to run it, even if there are line breaks in the pasted text
       | 
       | Not sure if that's the same mechanism at play as described in the
       | OP. But I love this about zsh
        
       | dang wrote:
       | Related:
       | 
       |  _Bracketed paste mode (2013)_ -
       | https://news.ycombinator.com/item?id=18329305 - Oct 2018 (22
       | comments)
       | 
       |  _Bracketed paste mode_ -
       | https://news.ycombinator.com/item?id=6359316 - Sept 2013 (1
       | comment)
        
       | benatkin wrote:
       | With ipython and Deno pasting a giant amount of content is quite
       | nice.
       | 
       | Deno:
       | 
       | press "`", press Ctrl-V or Command-V, press "`"
       | 
       | Now that is in _
       | 
       | With ipython:
       | 
       | press "'''", press Ctrl-V or Command-V, press "'''"
       | 
       | Now that is in _
       | 
       | In Deno this won't run something on Ctrl-V, until you press
       | enter, which shows it supports bracketed paste:
       | `test       here`; throw new Error('ran this code without
       | pressing enter');       `end`
       | 
       | In node that will run.
       | 
       | In ipython this won't run w/o pressing enter:
       | '''line       another       '''       raise RuntimeError('ran
       | this w/o pressing enter')       '''continued'''
       | 
       | In python it will, if you paste it somewhere, remove the leading
       | spaces that I added for HN, and copy and paste it again.
        
       | zmmmmm wrote:
       | wow, so after decades of using vim TIL finally how to solve one
       | its most irritating warts, how not to have to manually set / turn
       | off paste mode so that it won't auto-format pasted contents.
       | 
       | given that it's something like 10 lines of code [0] it seems
       | awfully silly that vim doesn't offer this built in.
       | 
       | [0] https://github.com/ConradIrwin/vim-bracketed-
       | paste/blob/mast...
        
       | XorNot wrote:
       | I feel like this is another entry in the "stop having invisible
       | modes" category of software.
       | 
       | No matter what the context, every OS, application and platform
       | has some obscure feature which can be activated by the right
       | random key combination, and provides no visual feedback or GUI
       | controls to de-activate (so you get to just mash the keyboard
       | till it hopefully turns off).
        
       | ytjohn wrote:
       | So that's what that is. I encounter that quite a bit when I try
       | to paste and get annoyed trying to figure out how those extra
       | characters got in there. I then would go and edit the start and
       | stop of the line to remove them. I never actually tried just
       | pressing enter for what looked like garbage at the start and end
       | of the string.
       | 
       | I've seen it as a frustrating annoyance. Now that I know what it
       | is, maybe I'll try hitting enter next time.
       | 
       | I think though, if a terminal (like iterm and windows terminal
       | preview) was just going to enable this by default, they should
       | have included some dialog the first time or two it happened.
       | Something to explain what was going on.
        
         | benatkin wrote:
         | It should do the opposite - find out when you run a program
         | that doesn't support it and very strongly recommend you to use
         | programs that support bracketed paste.
         | 
         | The mac now defaults to zsh which it seems to default to
         | supporting it.
        
           | saurik wrote:
           | bash also has had this feature for something like six or
           | seven years and it has been the default for almost two, so
           | this isn't a reason to use or be specifically excited about
           | zsh. (Of course, the ridiculously ancient copy of bash macOS
           | ships as part of their protest against Free Software does not
           | have this feature; we thereby need to be careful not to
           | attribute anything to "now uses zsh/clang/etc." that was
           | actually due to Apple holding us all back.)
        
             | [deleted]
        
             | benatkin wrote:
             | > ridiculously ancient copy of bash macOS ships as part of
             | their protest against Free Software does not have this
             | feature
             | 
             | Well, bash changed their license from GPLv2 to GPLv3. So it
             | is reasonable anyone who was using the old version would
             | reconsider.
             | 
             | > that was actually due to Apple holding us all back
             | 
             | I know Apple does this and that their policy also
             | unreasonably extends to GPLv2, but the GPLv3 really is
             | difficult even for people who only want to write open
             | source code unless they buy into everything GNU.
        
         | DHowett wrote:
         | Terminal emulators typically only enable it in response to a
         | request from an application. I'm not aware of one that enables
         | paste bracketing _by default_.
         | 
         | If some shell or other line editor turns it on and doesn't
         | actually support the bracketing sequences, or fails to turn it
         | off when leaving an interactive editing context, it might be
         | worth filing that as a bug on that shell or line editor.
        
       | hsbauauvhabzb wrote:
       | Thanks, I've occasionally come across this in foreign shells (my
       | main shell doesn't do it) and have long wondered what the cause
       | is!
        
       | leni536 wrote:
       | > safe-paste
       | 
       | I wonder how safe it actually is. Is it possible to escape from
       | the brackets if the clipboard itself contains terminal control
       | characters?
        
         | DHowett wrote:
         | Some terminal emulators[1] strip control characters (C0, C1 or
         | both) out of clipboard or paste buffer contents when paste
         | bracketing is enabled to avoid exactly this.
         | 
         | I believe[2] that xterm is not among them, which presents an
         | argument that those other terminal emulators are not xterm-
         | compatible :)
         | 
         | [1] Windows Terminal does for sure
         | 
         | [2] citation needed; I tested it a couple years ago and this is
         | practically an anecdote!
        
       ___________________________________________________________________
       (page generated 2023-03-19 23:00 UTC)