Bracketed paste in the CLI messes up pasting to shell

cli
(Charl) #1

Because the cockroachdb CLI turns bracketed paste on, it messes with any copy and pasting outside the CLI in the same bash session.

All pasted strings appear in the shell surrounded by 0~…1~ (e.g. 0~LOOK_AT_THE_START_AND_END1~). This really wreaks havoc when you’re dealing with copied text that you cannot see when providing input (like passwords).

The only way to fix this is to run printf “\e[?2004l” in the current term.

Is there some way to turn this off or at the very least find a way for the setting to not leak into the environment that the CLI was run from?

0 Likes

(Ron Arévalo) #2

Hey @charl,

I wasn’t able to reproduce this on my end, can you provide the steps you took that led to this behaviour?

Thanks,

Ron

0 Likes

(Charl) #3

Hi Ron,

Sure.

Form Ubuntu 16.04;

Copy n paste some string as a control:

charl@odalpha:/tmp$ echo "TEXT_TO_COPY"
TEXT_TO_COPY
charl@odalpha:/tmp$ # TEXT_TO_COPY

Log into cockroachdb CLI:

charl@odalpha:/tmp$ cockroach sql --certs-dir=/home/charl/.cockroach-certs/certs
# Welcome to the cockroach SQL interface.
# All statements must be terminated by a semicolon.
# To exit: CTRL + D.
#
# Server version: CockroachDB CCL v2.1.2 (x86_64-unknown-linux-gnu, built 2018/12/10 20:15:47, go1.10.3) (same version as client)
# Cluster ID: ffa26d39-17ef-4068-bf1d-f46668158234
#
# Enter \? for a brief introduction.
#
root@:26257/defaultdb>

Background/exit the CLI proc and try the copy n paste again:

charl@odalpha:/tmp$ # 0~TEXT_TO_COPY1~

I used the mouse to select the TEXT_TO_COPY from my terminal and pasted is back to the terminal using the keyboard.

Reset the bracketed paste for the current session and paste again:

charl@odalpha:/tmp$ printf "\e[?2004l"
charl@odalpha:/tmp$
charl@odalpha:/tmp$ # TEXT_TO_COPY

I added the hash (#) in front of each of the pastes to the terminal to avoid bash errors.

I am running Ubuntu 16.04 on OS X via VMWare Fusion. I access the environment using ssh via iTerm2. Access to our production clusters are also via iTerm2/ssh from OS X where we see the same issue.

This issue is not limited to me but everyone on my team that use the cockroachdb CLI.

Is there any other data I can provide for you to help trace this issue?

Ciao,
Charl

0 Likes

(Ron Arévalo) #4

Hey @charl

Thanks for the steps, however I wasn’t able to reproduce this error on my end. Also, this does not appear to be an issue with CRDB, but rather an issue with Ubuntu itself.

I found this stack exchange post about the same issue.

It also appears that there are a few options for workarounds besides the printf "\e[?2004l" method you mentioned.

Thanks,

Ron

0 Likes

(Raphael 'kena' Poss) #5

@charl,

I wasn’t able to repro either, however I have a hunch (looking at the code) that cockroach sql indeed does not disable bracketed paste when you suspend it via Ctrl+Z. (It does when you terminate the process normally).

However your problem is very hard to reproduce, because most shells (including zsh) and tools like screen or tmux will “clean up” the bracketed paste state when the process controlling the terminal detaches.

So two things:

  • you can alleviate your situation by using such tools / shells.
  • if you want us to work on this, you’ll need to give many more specifics about the particular combination of shell and terminal emulation ($TERM) that we can use to reproduce and test.
0 Likes

(Charl) #6

Hi,

Here’s more info on the environment:

charl@odalpha:~$ echo $TERM
xterm-256color
charl@odalpha:~$ echo $SHELL
/bin/bash
charl@odalpha:~$ dpkg -l '*bash*'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                                           Version                              Architecture                         Description
+++-==============================================================-====================================-====================================-=================================================================================================================================
ii  bash                                                           4.3-14ubuntu1.2                      amd64                                GNU Bourne Again SHell
ii  bash-completion                                                1:2.1-4.2ubuntu1.1                   all                                  programmable completion for the bash shell

Let me know if you need anything else.

I have retested and I can confirm that this seems to be related to backgrounding (suspending) the CLI process and not when you exit the CLI.

0 Likes

(Raphael 'kena' Poss) #7

Hi Charl,

thanks for your instructions. However I am still not able to repro. I did this:

  1. xterm -e bash to start a xterm
  2. in the xterm session, export TERM=xterm-256color
  3. run cockroach demo
  4. suspend with Ctrl+Z
  5. try to paste in the bash shell

The pasting succeeds, suggesting that bracketed paste was reinitialized successfully.

Here are my version details:

ii  bash                                         4.4.18-2ubuntu3                               amd64        GNU Bourne Again SHell
ii  xterm                                        330-1ubuntu3                                  amd64        X terminal emulator

Can you provide more details again?

0 Likes

(Charl) #8

While this appears to be a Ubuntu-wide issue at our office I appreciate all the effort and time you’ve put into this.

Our internal workaround is to not background (Control-Z) the cockroachdb CLI tool.

Let’s just close this for now.

0 Likes

(Raphael 'kena' Poss) #9

Is it possible that the issue happens when you suspend the shell while it is running a query?

0 Likes