Skip to content

Commit

Permalink
BUG: Filespecs are not properly quoted
Browse files Browse the repository at this point in the history
Filespec(s, on individual lines) need to be shell-quoted, as they are passed (through xargs) to the opener.
We need to use null-termination so that xargs doesn't do special handling of quotes. -I (implying -L 1) is _not_ enough! As our input is newline-delimited, use tr to translate to null separators, then feed to xargs -0.
For the editor (which cannot simply be launched but needs to use the actual terminal so that the editor will be launched inside and therefore visible inside the pane), it's even worse: The concluding CR is only appended once, not for each file. Files should not be edited separately, anyway, but passed as multiple argments to a single editor instance. Also, the editor call itself should disable name lookup (send-keys -l) so that filenames that resemble a Tmux key aren't accidentally translated into a keypress.

Inspired by tmux-plugins#38 (which provides a bad solution, though).
  • Loading branch information
inkarkat committed May 26, 2023
1 parent ed44653 commit 75c9630
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions open.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ is_cygwin() {

command_generator() {
local command_string="$1"
echo "{ cd \"\$(tmux display-message -p '#{pane_current_path}')\" && xargs -I {} $command_string \"{}\" >/dev/null; }"
echo "{ cd \"\$(tmux display-message -p '#{pane_current_path}')\" && tr '\\n' '\\0' | xargs -0I {} $command_string {} >/dev/null; }"
}

search_command_generator() {
Expand Down Expand Up @@ -81,7 +81,7 @@ generate_editor_command() {
editor=$(get_tmux_option "$open_editor_override" "$environment_editor")
# vim freezes terminal unless there's the '--' argument. Other editors seem
# to be fine with it (textmate [mate], light table [table]).
echo "xargs -I {} tmux send-keys '$editor -- \"{}\"'; tmux send-keys 'C-m'"
echo "tr '\\n' '\\0' | xargs -0I {} printf '%q\\n' {} | tmux send-keys -l \"$editor -- \$(tr '\\n' ' ')\"; tmux send-keys 'C-m'"
}

set_copy_mode_open_bindings() {
Expand Down

0 comments on commit 75c9630

Please sign in to comment.