sunaku / home

🏡 My $HOME directory (dot files & bin scripts)
https://sunaku.github.io/about.html#unix-shell-environment
139 stars 16 forks source link

Fix yank for copied text beginning with a dash #5

Closed JonathanWheeler closed 3 years ago

JonathanWheeler commented 3 years ago

As also noted here, fixes the following issue:

> tmux set-buffer "- foo"
tmux: unknown option --
sunaku commented 3 years ago

Hi, thanks for this PR! :+1: But unfortunately, this change ends up adding { curly braces } to the copied text on my system (tested under multiple shells: ZSH, BASH, DASH, and POSIX). :disappointed: Instead, we'll need to communicate this issue upstream to the tmux developers and ask them to support a special -- separator flag that can be used like this:

tmux set-buffer -- "- foo"
JonathanWheeler commented 3 years ago

That's interesting! It's working on my end. I wonder what the discrepancy is? I've tested it on macOS 10.15.7 + iTerm2 3.3.12 + zsh 5.7.1 (+ with and without vim 8.1), and on Ubuntu 20.04.1 + GNOME Terminal 3.36.2 + zsh 5.8 + tmux next-3.3 (tmux 3.2-rc2, I think) (+ with and without vim 8.1). I've left the #!/bin/sh shebang intact.

Nevertheless, your suggestion would be a more elegant solution.


... OK, I just noticed that I get the same curly brace result when I type tmux set-buffer {"- foo"} into the command line (both zsh & sh), but it's working for me when it's executed inside the script (sh) when copying some text beginning with -. I'm not sure why. (Or why it even works at all, lol.)

Did you test it by adding it to the script?

sunaku commented 3 years ago

I've tried this now by adding braces to a script, but still no luck:

$ echo 'tmux set-buffer {"- foo"}' > /tmp/with-braces
$ dash -eux /tmp/with-braces
+ tmux set-buffer {- foo}
$ tmux save-buffer - | od -ca
0000000   {   -       f   o   o   }
          {   -  sp   f   o   o   }
0000007
$ tmux delete-buffer
$ tmux save-buffer -
no buffers

And the same thing happens when the script is executed directly:

$ (echo '#!/bin/sh'; echo 'tmux set-buffer {"- foo"}') > /tmp/with-braces
$ chmod +x /tmp/with-braces
$ /tmp/with-braces
$ tmux save-buffer - | od -ca
0000000   {   -       f   o   o   }
          {   -  sp   f   o   o   }
0000007
$ tmux delete-buffer
$ tmux save-buffer -
no buffers

For completeness, here is the case of not adding braces to a script:

$ echo 'tmux set-buffer "- foo"' > /tmp/sans-braces
$ dash -eux /tmp/sans-braces
+ tmux set-buffer - foo
tmux: unknown option --
usage: set-buffer [-aw] [-b buffer-name] [-n new-buffer-name] [-t target-client] data
$ tmux save-buffer - | od -ca
no buffers
0000000

Unfortunately, I don't understand how or why it's even working on your system. :sweat_smile: So I'm closing this PR now, since I couldn't reproduce your results on my system (as shown in my experiments above). Nevertheless, thanks for your contribution. :+1: Cheers.