From d2f95d69fbf40d77b9b61b7e24989d607e3790a9 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 18 Apr 2015 16:24:57 +0900 Subject: [PATCH] [fzf-tmux] Fix #200 - Double-quote handling Related #199 --- bin/fzf-tmux | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/bin/fzf-tmux b/bin/fzf-tmux index 55ea5f7..fb00edb 100755 --- a/bin/fzf-tmux +++ b/bin/fzf-tmux @@ -89,19 +89,27 @@ fi set -e -# Build arguments to fzf -[ ${#args[@]} -gt 0 ] && fzf_args=$(printf '\\"%s\\" ' "${args[@]}"; echo '') - # Clean up named pipes on exit id=$RANDOM +argsf=/tmp/fzf-args-$id fifo1=/tmp/fzf-fifo1-$id fifo2=/tmp/fzf-fifo2-$id fifo3=/tmp/fzf-fifo3-$id cleanup() { - rm -f $fifo1 $fifo2 $fifo3 + rm -f $argsf $fifo1 $fifo2 $fifo3 } trap cleanup EXIT SIGINT SIGTERM +# Build arguments to fzf +touch $argsf +if [ ${#args[@]} -gt 0 ]; then + str="" + for arg in "${args[@]}"; do + str="$str \"${arg//\"/\\\"}\"" + done + cat <<< "$str" > $argsf +fi + fail() { >&2 echo "$1" exit 1 @@ -117,11 +125,11 @@ mkfifo $fifo2 mkfifo $fifo3 if [ -n "$term" -o -t 0 ]; then tmux set-window-option -q synchronize-panes off \;\ - split-window $opt "cd $(printf %q "$PWD");$envs"' sh -c "'$fzf' '"$fzf_args"' > '$fifo2'; echo \$? > '$fifo3' '"$close"'"' $swap + split-window $opt "cd $(printf %q "$PWD");$envs"' sh -c "'$fzf' $(cat '$argsf') > '$fifo2'; echo \$? > '$fifo3' '"$close"'"' $swap else mkfifo $fifo1 tmux set-window-option -q synchronize-panes off \;\ - split-window $opt "$envs"' sh -c "'$fzf' '"$fzf_args"' < '$fifo1' > '$fifo2'; echo \$? > '$fifo3' '"$close"'"' $swap + split-window $opt "$envs"' sh -c "'$fzf' $(cat '$argsf') < '$fifo1' > '$fifo2'; echo \$? > '$fifo3' '"$close"'"' $swap cat <&0 > $fifo1 & fi cat $fifo2