Skip to content

Commit

Permalink
fzf-tmux: fix underquoting variables
Browse files Browse the repository at this point in the history
  • Loading branch information
a1346054 committed Sep 3, 2022
1 parent 689bcc3 commit 9eb12bd
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions bin/fzf-tmux
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ done

if [[ -z "$TMUX" ]]; then
"$fzf" "${args[@]}"
exit $?
exit "$?"
fi

# --height option is not allowed. CTRL-Z is also disabled.
Expand All @@ -140,7 +140,7 @@ if [[ ! "$opt" =~ "-E" ]] && tmux list-panes -F '#F' | grep -q Z; then
zoomed_without_popup=1
original_window=$(tmux display-message -p "#{window_id}")
tmp_window=$(tmux new-window -d -P -F "#{window_id}" "bash -c 'while :; do for c in \\| / - '\\;' do sleep 0.2; printf \"\\r\$c fzf-tmux is running\\r\"; done; done'")
tmux swap-pane -t $tmp_window \; select-window -t $tmp_window
tmux swap-pane -t "$tmp_window" \; select-window -t "$tmp_window"
fi

set -e
Expand All @@ -153,7 +153,7 @@ fifo2="${TMPDIR:-/tmp}/fzf-fifo2-$id"
fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id"
tmux_win_opts=( $(tmux show-window-options remain-on-exit \; show-window-options synchronize-panes | sed '/ off/d; s/^/set-window-option /; s/$/ \\;/') )
cleanup() {
\rm -f $argsf $fifo1 $fifo2 $fifo3
\rm -f "$argsf" "$fifo1" "$fifo2" "$fifo3"

# Restore tmux window options
if [[ "${#tmux_win_opts[@]}" -gt 0 ]]; then
Expand All @@ -163,9 +163,9 @@ cleanup() {
# Remove temp window if we were zoomed without popup options
if [[ -n "$zoomed_without_popup" ]]; then
tmux display-message -p "#{window_id}" > /dev/null
tmux swap-pane -t $original_window \; \
select-window -t $original_window \; \
kill-window -t $tmp_window \; \
tmux swap-pane -t "$original_window" \; \
select-window -t "$original_window" \; \
kill-window -t "$tmp_window" \; \
resize-pane -Z
fi

Expand Down Expand Up @@ -194,36 +194,36 @@ echo "$envs;" > "$argsf"
opts=$(printf "%q " "${args[@]}")

pppid=$$
echo -n "trap 'kill -SIGUSR1 -$pppid' EXIT SIGINT SIGTERM;" >> $argsf
echo -n "trap 'kill -SIGUSR1 -$pppid' EXIT SIGINT SIGTERM;" >> "$argsf"
close="; trap - EXIT SIGINT SIGTERM $close"

export TMUX=$(cut -d , -f 1,2 <<< "$TMUX")
mkfifo -m o+w $fifo2
mkfifo -m o+w "$fifo2"
if [[ "$opt" =~ "-E" ]]; then
cat $fifo2 &
cat "$fifo2" &
if [[ -n "$term" ]] || [[ -t 0 ]]; then
cat <<< "\"$fzf\" $opts > $fifo2; out=\$? $close; exit \$out" >> $argsf
cat <<< "\"$fzf\" $opts > $fifo2; out=\$? $close; exit \$out" >> "$argsf"
else
mkfifo $fifo1
cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; out=\$? $close; exit \$out" >> $argsf
cat <&0 > $fifo1 &
mkfifo "$fifo1"
cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; out=\$? $close; exit \$out" >> "$argsf"
cat <&0 > "$fifo1" &
fi
tmux popup -d "$PWD" $opt "bash $argsf" > /dev/null 2>&1
exit $?
exit "$?"
fi
mkfifo -m o+w $fifo3
mkfifo -m o+w "$fifo3"
if [[ -n "$term" ]] || [[ -t 0 ]]; then
cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" >> $argsf
cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" >> "$argsf"
else
mkfifo $fifo1
cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" >> $argsf
cat <&0 > $fifo1 &
mkfifo "$fifo1"
cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" >> "$argsf"
cat <&0 > "$fifo1" &
fi
tmux set-window-option synchronize-panes off \;\
set-window-option remain-on-exit off \;\
split-window -c "$PWD" $opt "bash -c 'exec -a fzf bash $argsf'" $swap \
> /dev/null 2>&1 || { "$fzf" "${args[@]}"; exit $?; }
cat $fifo2
exit "$(cat $fifo3)"
> /dev/null 2>&1 || { "$fzf" "${args[@]}"; exit "$?"; }
cat "$fifo2"
exit "$(cat "$fifo3")"

0 comments on commit 9eb12bd

Please sign in to comment.