Closed gregorias closed 6 years ago
this seems to fix the issue on my system :-)
Thank you for fixing this one. I just tried it on my system and it does the job. Do you know if there's a way to fix this one more elegantly... without invoking the command in a subshell? Can we change the command to have single quotes..?
@bruno- Essentially, you need an interpreter for $key_cmd
that will do all the expansions that a POSIX shell does. I'm not familiar with anything that can be more elegant than the shell itself.
Changing sh -c "tmux $key_cmd"
to sh -c 'tmux $key_cmd'
won't work. sh -c
needs to receive the script to run as it's argument, and the script is the value of key_cmd
.
@gregorias, what I meant was: can we get xclip -selection clipboard
to be inside single quotes instead of double quotes? I'm referring code snippets from the first post in this discussion.
If yes, would that help with proper evaluation.. meaning xclip -selection clipboard
would execute as a single command?
@bruno- We could get it into single quotes, I guess, but it would do nothing to alleviate the problem.
If you find my explanation in the first post unclear on why the change of quotes won't help, then the bash manpage's sections on parameter expansion and word splitting provide more details.
You can also try it out for yourself and think about what the following shell scripts would print:
S='A "B C" D'; for F in $S; do echo $F; done;
S="A 'B C' D"; for F in $S; do echo $F; done;
~Sadly "tmux $key_cmd"
will cause some expansion logic to apply before the string is passed to sh -c
, so this commit also doesn't solve the problem. #134 is due to remotion of \
instead of it being escaped as \\
.~
Expansion issue is actually on the read
command.
Do you know if there's a way to fix this one more elegantly... without invoking the command in a subshell?
eval "tmux $key_cmd"
The issue was caused by incorrect parameter expansion.
Copycat saves the old bindings inside /tmp/copycat_$(whoami)_recover_keys as they were provided on the command line, e.g.
When tmux-copycat restores the config it reads each line of that temporary file into
key_cmd
and runstmux $key_cmd
. Now, when the shell expands$key_cmd
it expands"xclip
,-selection
,clipboard"
into separate words.tmux $key_cmd
runs effectively as:Which is not what we want.
In order to fix this bug, this commit makes sure that a proper shell expansion happens by using
sh -c
.