Ubuntu 14.04 – broken bracketed paste mode in Gnome Terminal

After upgrade to Ubuntu 14.04 LTS (Trusty Tahr) from 13.10 I found out very annoying issue while copy-pasting commands into gnome terminal. Each command pasted from clipboard has characters 0~ in the beginning and 1~ at the end of the text, so it looks like:

$ 0~ls -la1~

This happens only after I go to subshell from Midnight Commander and back a few times using Ctrl+o key.

First time I thought it’s a MC bug but after a bit of googling I discovered that the problem is caused by a bug in bracketed paste mode implementation in VTE library. VTE library is used in most GTK based terminal emulators such as Gnome terminal, XFCE terminal etc. so this problem affects all of them. There is already a patch for development version of libvte (v0.36) but it’s not clear whether this fix will be backported to libvte v0.34 used in Trusty or Ubuntu team will upgrade libvte to at least v0.36 in LTS. Until resolved, you can disable bracketed paste mode manually once this issue appears like Conrad Irwin suggested in his great blog post. Just enter following command in terminal:

$ printf "\e[?2004l"

and issue should go away. I have tried to add this command into ~/.bashrc in order to disable bracketed paste mode when terminal is opened but this seems to not work. You can re-enable bracketed paste mode anytime using similar command:

printf "\e[?2004h"

Bracketed paste mode is generally a good idea. Its main purpose is to inform shell or applications running in shell that text has been pasted from clipboard and not typed manually. This could improve security since when you paste command with newline character (\n) at the end, bash (and most shells too) executes that command immediately. You can find some examples of malicious commands here.

Edit 10/2015: Seems like this issue is finally resolved in Ubuntu. VTE patch has been backported to libvte v0.34 used in Trusty. After upgrade I am no longer able to reproduce this issue.