Skip to content

fzy-tmux: fix escaping#203

Open
phillipwood wants to merge 1 commit into
jhawthorn:masterfrom
phillipwood:fzy-tmux-quoting
Open

fzy-tmux: fix escaping#203
phillipwood wants to merge 1 commit into
jhawthorn:masterfrom
phillipwood:fzy-tmux-quoting

Conversation

@phillipwood

Copy link
Copy Markdown

The exit code returned by fzy-tmux is the exit status of the "cut" command that's run before "tmux" rather than the exit status of "fzy". This is because "$?" is not escaped. To get the exit status of "fzy" we need to escape it twice, once to prevent parameter expansion inside the double quotes and again to prevent expansion by eval.

The arguments passed to fzy-tmux are expanded, then the expanded arguments are evaluated by "eval" and then the result of that is evaluated by the shell running inside tmux. Evaluating them multiple times can lead to surprising behavior as the argument values are subject to parameter expansion and command substitution. By escaping "$*" we prevent the arguments from being expanded before they are passed to "eval". Ideally we'd also prevent "eval" from expanding them as well so that they were evaluated only in the shell running inside tmux but there isn't a simple way to do that and adding one level of escaping does at least remove one level of unwanted expansion.

The exit code returned by fzy-tmux is the exit status of the "cut"
command that's run before "tmux" rather than the exit status of
"fzy". This is because "$?" is not escaped. To get the exit status of
"fzy" we need to escape it twice, once to prevent parameter expansion
inside the double quotes and again to prevent expansion by eval.

The arguments passed to fzy-tmux are expanded, then the expanded
arguments are evaluated by "eval" and then the result of that is
evaluated by the shell running inside tmux. Evaluating them multiple
times can lead to surprising behavior as the argument values are subject
to parameter expansion and command substitution. By escaping "$*" we
prevent the arguments from being expanded before they are passed to
"eval". Ideally we'd also prevent "eval" from expanding them as well
so that they were evaluated only in the shell running inside tmux but
there isn't a simple way to do that and adding one level of escaping
does at least remove one level of unwanted expansion.
@phillipwood

Copy link
Copy Markdown
Author

I'm not really sure why it is using eval in the first place so maybe we should remove that rather than escaping $*.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant