[fzf-tmux] Fix #200 - Double-quote handling

Related #199
This commit is contained in:
Junegunn Choi 2015-04-18 16:24:57 +09:00
parent 1169cc8653
commit d2f95d69fb

View File

@ -89,19 +89,27 @@ fi
set -e set -e
# Build arguments to fzf
[ ${#args[@]} -gt 0 ] && fzf_args=$(printf '\\"%s\\" ' "${args[@]}"; echo '')
# Clean up named pipes on exit # Clean up named pipes on exit
id=$RANDOM id=$RANDOM
argsf=/tmp/fzf-args-$id
fifo1=/tmp/fzf-fifo1-$id fifo1=/tmp/fzf-fifo1-$id
fifo2=/tmp/fzf-fifo2-$id fifo2=/tmp/fzf-fifo2-$id
fifo3=/tmp/fzf-fifo3-$id fifo3=/tmp/fzf-fifo3-$id
cleanup() { cleanup() {
rm -f $fifo1 $fifo2 $fifo3 rm -f $argsf $fifo1 $fifo2 $fifo3
} }
trap cleanup EXIT SIGINT SIGTERM 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() { fail() {
>&2 echo "$1" >&2 echo "$1"
exit 1 exit 1
@ -117,11 +125,11 @@ mkfifo $fifo2
mkfifo $fifo3 mkfifo $fifo3
if [ -n "$term" -o -t 0 ]; then if [ -n "$term" -o -t 0 ]; then
tmux set-window-option -q synchronize-panes off \;\ 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 else
mkfifo $fifo1 mkfifo $fifo1
tmux set-window-option -q synchronize-panes off \;\ 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 & cat <&0 > $fifo1 &
fi fi
cat $fifo2 cat $fifo2