Remove trailing new line from 'clipboard' to prevent execution on the terminal?

Pureferret

Is there some way to run whatever you copy to the 'clipboard' through some sort of filter? Ideally to strip out the trailing newline from something you copy, so that it doesn't auto-run in the terminal?

This is what it looks like when I copy the test in question, and I sometimes forget this is a new line.
enter image description here

Gilles 'SO- stop being evil'

Good modern terminals support bracketed paste: when you use the terminal's paste command, it sends special escape sequences around the clipboard content. If your shell supports bracketed paste, it'll paste the clipboard content including any control characters as-is, and in particular a trailing newline will not trigger the execution of the command.

Zsh ≥5.1 supports bracketed paste and has it on by default. Older versions can be taught. Bash ≥4.4 supports bracketed paste if you add set enable-bracketed-paste on to ~/.inputrc.

If your terminal or shell doesn't support bracketed paste, you could define a shell function that pastes without the trailing newline.

In zsh, the following command recalls the content of the clipboard, minus trailing newlines, and brings it up for editing (even if there are multiple lines):

print -z -- "`xsel -b`"

In bash, you can push the content of the clipboard minus trailing newlines to the history stack. After this, press Up to bring up the command for editing.

history -s -- "`xsel -b`"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Prevent line numbers from being copied to clipboard

From Dev

How can I prevent javascript from copying a line break to clipboard?

From Dev

Remove trailing spaces from each line in a string in ruby

From Dev

C - Unable to read from a file that has no trailing new line in it

From Dev

Prevent words from cutting off into a new line

From Dev

How to prevent Div from creating a new line

From Dev

Prevent words from cutting off into a new line

From Dev

perl remove trailing line not working

From Dev

Prevent action from execution

From Dev

Remove new line \n reading from CSV

From Dev

How to remove new line from the string in awk?

From Dev

remove new line from array in perl

From Dev

Remove Trailing Slash From the URL

From Dev

Remove trailing '/' from rails string

From Dev

Remove trailing whitespaces from CSV

From Dev

remove trailing zeros from output

From Dev

How to remove title bar from terminal on the new Ubuntu 20.04?

From Dev

New terminal window (duplicate session) from Putty command line?

From Dev

Remove trailing line on the last item of Timeline boostrap

From Dev

Remove extra new line from cygwin command line

From Dev

Prevent H1 tag from breaking to new line

From Dev

SwiftUI - Prevent users from adding New Line (\n) in TextEditor

From Dev

CSS prevent span from moving down to new line

From Dev

How to Prevent TD from ending up on a new line?

From Dev

How to remove the leading and trailing space from each line of a file using shell script?

From Dev

Copying to the clipboard in PowerShell without a new line

From Dev

Trim text / delete trailing spaces from clipboard with AHK

From Dev

Output is missing a trailing new line character

From Dev

Prevent vim from clearing the clipboard on exit

Related Related

  1. 1

    Prevent line numbers from being copied to clipboard

  2. 2

    How can I prevent javascript from copying a line break to clipboard?

  3. 3

    Remove trailing spaces from each line in a string in ruby

  4. 4

    C - Unable to read from a file that has no trailing new line in it

  5. 5

    Prevent words from cutting off into a new line

  6. 6

    How to prevent Div from creating a new line

  7. 7

    Prevent words from cutting off into a new line

  8. 8

    perl remove trailing line not working

  9. 9

    Prevent action from execution

  10. 10

    Remove new line \n reading from CSV

  11. 11

    How to remove new line from the string in awk?

  12. 12

    remove new line from array in perl

  13. 13

    Remove Trailing Slash From the URL

  14. 14

    Remove trailing '/' from rails string

  15. 15

    Remove trailing whitespaces from CSV

  16. 16

    remove trailing zeros from output

  17. 17

    How to remove title bar from terminal on the new Ubuntu 20.04?

  18. 18

    New terminal window (duplicate session) from Putty command line?

  19. 19

    Remove trailing line on the last item of Timeline boostrap

  20. 20

    Remove extra new line from cygwin command line

  21. 21

    Prevent H1 tag from breaking to new line

  22. 22

    SwiftUI - Prevent users from adding New Line (\n) in TextEditor

  23. 23

    CSS prevent span from moving down to new line

  24. 24

    How to Prevent TD from ending up on a new line?

  25. 25

    How to remove the leading and trailing space from each line of a file using shell script?

  26. 26

    Copying to the clipboard in PowerShell without a new line

  27. 27

    Trim text / delete trailing spaces from clipboard with AHK

  28. 28

    Output is missing a trailing new line character

  29. 29

    Prevent vim from clearing the clipboard on exit

HotTag

Archive