fzy-tmux: fix escaping#203
Open
phillipwood wants to merge 1 commit into
Open
Conversation
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.
Author
|
I'm not really sure why it is using |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.