Skip to content

Commit 9725eac

Browse files
fzf-tmux: Use mktemp, and fix TERM quoting (#4664)
1 parent b389616 commit 9725eac

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

bin/fzf-tmux

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ fi
159159
set -e
160160

161161
# Clean up named pipes on exit
162-
id=$RANDOM
163-
argsf="${TMPDIR:-/tmp}/fzf-args-$id"
164-
fifo1="${TMPDIR:-/tmp}/fzf-fifo1-$id"
165-
fifo2="${TMPDIR:-/tmp}/fzf-fifo2-$id"
166-
fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id"
162+
tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/fzf-tmux-XXXXXX")
163+
argsf="$tmpdir/args"
164+
fifo1="$tmpdir/fifo1"
165+
fifo2="$tmpdir/fifo2"
166+
fifo3="$tmpdir/fifo3"
167167
if tmux_win_opts=$(tmux show-options -p remain-on-exit \; show-options -p synchronize-panes 2> /dev/null); then
168168
tmux_win_opts=($(sed '/ off/d; s/synchronize-panes/set-option -p synchronize-panes/; s/remain-on-exit/set-option -p remain-on-exit/; s/$/ \\;/' <<< "$tmux_win_opts"))
169169
tmux_off_opts='; set-option -p synchronize-panes off ; set-option -p remain-on-exit off'
@@ -172,8 +172,7 @@ else
172172
tmux_off_opts='; set-window-option synchronize-panes off ; set-window-option remain-on-exit off'
173173
fi
174174
cleanup() {
175-
\rm -f $argsf $fifo1 $fifo2 $fifo3
176-
175+
\rm -rf "$tmpdir"
177176
# Restore tmux window options
178177
if [[ ${#tmux_win_opts[@]} -gt 1 ]]; then
179178
eval "tmux ${tmux_win_opts[*]}"
@@ -196,7 +195,7 @@ cleanup() {
196195
trap 'cleanup 1' SIGUSR1
197196
trap 'cleanup' EXIT
198197

199-
envs="export TERM=$TERM "
198+
envs="export TERM=$(printf %q "$TERM") "
200199
if [[ $opt =~ "-E" ]]; then
201200
if [[ $tmux_version == 3.2 ]]; then
202201
FZF_DEFAULT_OPTS="--margin 0,1 $FZF_DEFAULT_OPTS"

0 commit comments

Comments
 (0)