17

In Ubuntu 21.04, when text is pasted into Gnome Terminal, the text is always highlighted.

  • It appears as if the text is selected, but it is only highlighted.
  • If you right-click on this highlighted text, the "Copy" option is actually disabled.
  • Clicking in the terminal or clicking on the highlighted text does not un-highlight the text.
  • The only way to un-highlight the pasted text is to type a key.
  • If you try to select the highlighted text by clicking and dragging the mouse pointer, the text color actually inverts, and the text looks like it is not selected, when it in fact is selected. enter image description here

This confusing behavior is not present in Ubuntu 20.04.

  • In Ubuntu 20.04, when text is pasted into Gnome Terminal, the text is not highlighted.
  • Then, selecting the text highlights it, as expected. enter image description here

How to revert this confusing behavior of Gnome Terminal in Ubuntu 21.04, so it behaves like Gnome Terminal in Ubuntu 20.04 ?

Enterprise
  • 12,002
  • 11
  • 60
  • 105
  • I would look through `~/.bashrc`: it contains a lot of definitions for customized behaviour (already pre-set by the Ubuntu release). There are code comments explaining what is what. Maybe you can spot something there? – Levente Apr 26 '21 at 21:55

4 Answers4

12

I also noticed this behavior after upgrade to 21.04. Don't think this as a bug: It is a new "default setting" in Bash 5.1.

First check:

$ bind -v | grep bracketed
set enable-bracketed-paste on

Then, try to disable (for the current session):

$ bind 'set enable-bracketed-paste off'
$ bind -v | grep bracketed
set enable-bracketed-paste off

And retry your findings in that terminal session. This is also explained in: https://stackoverflow.com/questions/35611134/bash-bracketed-paste-is-it-supported

I would suggest living with this new default setting of Bash, since it prevents the accidental middle-clicking or copy/pasting of multiple lines (consisting of possibly malicious commands) from the clipboard.

FedKad
  • 9,212
  • 7
  • 40
  • 79
  • From your linked post, does `.inputrc` have to reside in the user's home directory? Is there a way to make this "fix" global for all users and all terminal windows? – Enterprise May 16 '21 at 14:06
  • I just saw your [comment on Bug #1926256](https://bugs.launchpad.net/ubuntu/+source/mate-terminal/+bug/1926256/comments/11) about not disabling this globally. – Enterprise May 16 '21 at 14:31
  • Beginning with bash 5.2, the shell can be configured to use custom colors for the pasted text. See https://bugs.launchpad.net/ubuntu/+source/bash/+bug/1926256 comment 22. – egmont May 17 '23 at 13:01
3

This is a new "feature" in Bash. Should be reverted to previous defaults as soon as possible, IMO.

I'm seeing this bug in default MATE Terminal on fresh installation of 21.04 too,

screencast

so I have reported it to launchpad as bug 1926256 . Please mark yourself as affected by this bug and add a comment about GNOME Terminal use-case.

N0rbert
  • 97,162
  • 34
  • 239
  • 423
  • N0rbert, I thought this was a setting. It is disappointing that this is a bug, but good to know that it has been acknowledged and will be fixed. I also noticed the Ctrl+Shift+A issue, but thought it was a side-effect of this problem. Nevertheless, you read my mind. I will be sure to mark myself as impacted by both of the above bugs. – Enterprise Apr 27 '21 at 13:19
  • This is a completely wrong answer; I've explained why in the linked bugreport. – egmont May 13 '21 at 22:26
  • Someone changed the defaults. This matters, @egmont . – N0rbert May 14 '21 at 11:39
  • Indeed it matters, although it was obvious from OP's question. Your blaming the terminal, however, was incorrect. I see that now you've edited your answer to fix it, thanks for that! – egmont May 14 '21 at 19:34
  • N0rbert, I appreciate you taking the time to create the two bug reports. I've marked myself impacted; let's see where it goes. Also, the behavior in [Bug #1922276](https://bugs.launchpad.net/ubuntu/+source/mate-terminal/+bug/1922276) remains after applying the "fix" @FedonKadifeli suggested, so this may indeed be unrelated. – Enterprise May 16 '21 at 14:12
  • Beginning with bash 5.2, the shell can be configured to use custom colors for the pasted text. See https://bugs.launchpad.net/ubuntu/+source/bash/+bug/1926256 comment 22. – egmont May 17 '23 at 13:01
2

As suggested here, you can change the Gnome Terminal highlight color to something other than white, so it does not conflict with the "bracketed paste" feature of bash.

  1. Click on the header bar menu button in Gnome Terminal

    Click "Preferences"

    Under "Profile" in the left pane, select your profile (i.e. "Unnamed")

    Click the "Colors" tab

  2. Check-mark "Highlight Colors"

  3. Click the Background color box (the second box)

  4. Enter the hexadecimal value for the highlight color you want to use.

    You may want to chose one of the colors from the official Ubuntu Color Pallet:

    • Aubergine... #924D8B
    • Ubuntu Orange... #E95420
    • Light Orange... #F29879
  5. Click the Select button to apply your change.

After making this change:

  • The "bracketed paste" text will be highlighted in white, per the changes to bash.

    (See "AND THIS IS PASTED" text in the screenshot).

  • Text that you select using gnome-terminal will be your chosen color from step 4 above.

    (See "THIS IS SELECTED" text in the screenshot).

Changing Gnome Terminal Highlight Background Color

Enterprise
  • 12,002
  • 11
  • 60
  • 105
  • All this good, but it is not expected. Some developers change the defaults. It would be better if these smart developers will do this for us. Moreover the above is not universal solution - it will not work for MATE Terminal, Xfce Terminal and so on. – N0rbert May 17 '21 at 06:22
1

To get rid of this globally, add set enable-bracketed-paste off at the end of the /etc/inputrc.

Creating a .inputrc file in the home directory may cause some strange behavior, such your Home button stop working in terminal.

Lord_Dracon
  • 111
  • 2
  • Please do _not_ disable bracketed paste mode, do _not_ recommend to others to do it. Bracketed paste mode is an important security measure against accidental malicious pastes. In bash 5.1 you can just get used to the current weird behavior or change the terminal's highlight colors, as per another answer here. In bash 5.2 you can also configure the shell's bracketed paste colors, see e.g. https://bugs.launchpad.net/ubuntu/+source/bash/+bug/1926256 comment 22. – egmont May 17 '23 at 12:59
  • @egmont I only use the server version of Linux and mostly access it with PuTTY for several years, and I don't remember making an accidental copy-paste any "malicious" and/or "harmful" commands. In my case, this feature has been more of a nuisance than a help. Anyway, I'll leave the answer for anyone who wants to disable it because it took me a while to find a solution that worked. It's up to each individual to decide whether they will disable this feature or not, depending on their needs. – Lord_Dracon May 31 '23 at 21:45