laktak / extrakto

extrakto for tmux - quickly select, copy/insert/complete text without a mouse
MIT License
878 stars 45 forks source link

xclip error on Enter (xclip) #77

Closed rpuntaie closed 3 years ago

rpuntaie commented 3 years ago

Testing your plugin I found a problem when wanting to add the text to the cipboard (xclip). A separate test shows

echo "tst" | xclip -i -selection clipboard
Error: Can't open display: (null)

Maybe this can be handled within extracto.

laktak commented 3 years ago

Thank you for your bug report but I don't really understand your request. xclip does not work on your system? Can you provide more details and why you think this is related to extrakto?

rpuntaie commented 3 years ago

The "this" link above I interpret as "this is a general xclip problem, which has workarounds". So I though you might be interested in those workarounds for extracto.

One could resort to xsel, if xclip returns an error. Currently an error message informs that xclip returned an error code, but not what the reason was (Can't open display: (null) is not shown). Showing the reason would be useless, because the user cannot change how xclip is called. Or is there a way to change the call? Is there possibly even a way to use xsel? (Sorry for asking without looking into the code myself.) Anyway, that would be also an option: allow those to work around themselves via a configuration.

laktak commented 3 years ago

Well, the suggested fix on stackoverflow (to run it in the background) is already implemented with the @extrakto_clip_tool_run option set to bg by default.

https://github.com/laktak/extrakto/blob/master/scripts/extrakto.sh#L85

You can use whatever clip tool you want (including OSC52) - see @extrakto_clip_tool.

rpuntaie commented 3 years ago

This issue occurs only with tmux to ssh. A local tmux works fine.

According to this medium post "When you SSH to remote machine, and start tmux sessions there, you cannot make use of pbcopy, xclip or xsel, ...". His workaround using OSC52 in yank.sh did not work over tmux to ssh. Overrides did also not help.

laktak commented 3 years ago

OK, it would have been helpful to mention ssh in the beginning.

Please take a look at this wiki: https://github.com/laktak/extrakto/wiki/Remote-Copy-via-OSC52

rpuntaie commented 3 years ago

I had placed this 52-osc perl script in ~/.local/lib/urxvt, but the tilde in these lines were the problem. Xresources does not allow a tilde.

urxvt*perl-lib: ~/.local/lib/urxvt
URxvt.perl-ext-common: default,url-select,selection,vim-scrollback,52-osc

With the full path

urxvt*perl-lib: /home/roland/.local/lib/urxvt

and after

xrdb -merge ~/.local/etc/X11/Xresources

echo hello | osc52 worked.

This needs to be on the server and on the client PC. The whole chain of terminals needs to support OSC-52. In my case urxvt-tmux-ssh-urxvt. alacritty works out of the box.

But extracto with [Enter] did still not work.

I tried

https://github.com/samoshkin/tmux-config/blob/95efd543846a27cd2127496b74fd4f4da94f4a31/tmux/yank.sh

set -g @extrakto_clip_tool "yank.sh"

This worked.

I checked the relevant difference and changed osc52 to:

#!/bin/bash
esc="\033]52;c;$(base64 | tr -d '\r\n' )\a"
esc="\033Ptmux;\033$esc\033\\"
# resolve target terminal to send escape sequence
# if we are on remote machine, send directly to SSH_TTY to transport escape sequence
# to terminal on local machine, so data lands in clipboard on our local machine
pane_active_tty=$(tmux list-panes -F "#{pane_active} #{pane_tty}" | awk '$1=="1" { print $2 }')
target_tty="${SSH_TTY:-$pane_active_tty}"
printf "$esc" > "$target_tty"

This worka with urxvt-tmux-ssh-alacritty. It does not work with urxvt-tmux-ssh-urxvt.

laktak commented 3 years ago

Thanks for the information but it looks more like a problem with your setup than with extrakto.

The osc52 file should just work if you have a recent (e.g. 3.1/3.2) version of tmux both on the server and on the local machine.