Simplify fzf-tmux script
Before adoption: this commit came in with the history the project adopted, so no landing records it.
# Should properly escape arguments FZF_DEFAULT_OPTS='--prompt "\$a`b\"c"' fzf-tmux --header $'$a\nb"c`d'
authored by Junegunn Choi · committed by Junegunn Choi · parent 8651448 · Browse files · 1 file·+15 added−27 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+15 added−27 removed
- other:+15 added−27 removed
Provenance
- Commit
246b9f3- Tree
5fc280e- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
8651448
1 file changed+15 added−27 removed
modified:bin/fzf-tmux+15 added-27 removed
134 unmodified lines135 exit $?136 fi137 138 # --height option is not allowed139-args=("--no-height" "${args[@]}")139+args=("${args[@]}" "--no-height")140 141 # Handle zoomed tmux pane without popup options by moving it to a temp window142 if [[ ! "$opt" =~ "-K -E" ]] && tmux list-panes -F '#F' | grep -q Z; then143 zoomed_without_popup=19 unmodified lines153 argsf="${TMPDIR:-/tmp}/fzf-args-$id"154 fifo1="${TMPDIR:-/tmp}/fzf-fifo1-$id"155 fifo2="${TMPDIR:-/tmp}/fzf-fifo2-$id"156 fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id"157+tmux_win_opts=( $(tmux show-window-options remain-on-exit \; show-window-options synchronize-panes | sed '/ off/d; s/^/set-window-option /; s/$/ \\;/') )158 cleanup() {159 \rm -f $argsf $fifo1 $fifo2 $fifo3160 161 # Restore tmux window options162 if [[ "${#tmux_win_opts[@]}" -gt 0 ]]; then162- eval "tmux ${tmux_win_opts[@]}"163+ eval "tmux ${tmux_win_opts[*]}"164 fi165 166 # Remove temp window if we were zoomed without popup options167 if [[ -n "$zoomed_without_popup" ]]; then11 unmodified lines179 }180 trap 'cleanup 1' SIGUSR1181 trap 'cleanup' EXIT182 182-envs="env TERM=$TERM "183+envs="export TERM=$TERM "184 [[ "$opt" =~ "-K -E" ]] && FZF_DEFAULT_OPTS="--margin 0,1 $FZF_DEFAULT_OPTS"185 [[ -n "$FZF_DEFAULT_OPTS" ]] && envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")"186 [[ -n "$FZF_DEFAULT_COMMAND" ]] && envs="$envs FZF_DEFAULT_COMMAND=$(printf %q "$FZF_DEFAULT_COMMAND")"187+echo "$envs;" > "$argsf"188 187-mkfifo -m o+w $fifo2188-mkfifo -m o+w $fifo3189-189 # Build arguments to fzf191-opts=""192-for arg in "${args[@]}"; do193- arg="${arg//\\/\\\\}"194- arg="${arg//\"/\\\"}"195- arg="${arg//\`/\\\`}"196- arg="${arg//$/\\$}"197- opts="$opts \"$arg\""198-done190+opts=$(printf "%q " "${args[@]}")191 192 pppid=$$201-echo -n "trap 'kill -SIGUSR1 -$pppid' EXIT SIGINT SIGTERM;" > $argsf193+echo -n "trap 'kill -SIGUSR1 -$pppid' EXIT SIGINT SIGTERM;" >> $argsf194 close="; trap - EXIT SIGINT SIGTERM $close"195 204-tmux_win_opts=( $(tmux show-window-options remain-on-exit \; show-window-options synchronize-panes | sed '/ off/d; s/^/set-window-option /; s/$/ \\;/') )205-196+export TMUX=$(cut -d , -f 1,2 <<< "$TMUX")197+mkfifo -m o+w $fifo2198 if [[ "$opt" =~ "-K -E" ]]; then199 cat $fifo2 &200 if [[ -n "$term" ]] || [[ -t 0 ]]; then201 cat <<< "\"$fzf\" $opts > $fifo2; out=\$? $close; exit \$out" >> $argsf210- TMUX=$(echo $TMUX | cut -d , -f 1,2) tmux popup -d "$PWD" "${tmux_args[@]}" $opt -R "$envs bash $argsf" > /dev/null 2>&1202 else203 mkfifo $fifo1204 cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; out=\$? $close; exit \$out" >> $argsf205 cat <&0 > $fifo1 &215- TMUX=$(echo $TMUX | cut -d , -f 1,2) tmux popup -d "$PWD" "${tmux_args[@]}" $opt -R "$envs bash $argsf" > /dev/null 2>&1206 fi207+ tmux popup -d "$PWD" "${tmux_args[@]}" $opt -R "bash $argsf" > /dev/null 2>&1208 exit $?209 fi210 211+mkfifo -m o+w $fifo3212 if [[ -n "$term" ]] || [[ -t 0 ]]; then213 cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" >> $argsf222- TMUX=$(echo $TMUX | cut -d , -f 1,2) tmux set-window-option synchronize-panes off \;\223- set-window-option remain-on-exit off \;\224- split-window $opt "${tmux_args[@]}" "$envs bash -c 'cd $(printf %q "$PWD"); exec -a fzf bash $argsf'" $swap \225- > /dev/null 2>&1 || { "$fzf" "${args[@]}"; exit $?; }214 else215 mkfifo $fifo1216 cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" >> $argsf229- TMUX=$(echo $TMUX | cut -d , -f 1,2) tmux set-window-option synchronize-panes off \;\230- set-window-option remain-on-exit off \;\231- split-window $opt "${tmux_args[@]}" "$envs bash -c 'exec -a fzf bash $argsf'" $swap \232- > /dev/null 2>&1 || { "$fzf" "${args[@]}"; exit $?; }217 cat <&0 > $fifo1 &218 fi219+tmux set-window-option synchronize-panes off \;\220+ set-window-option remain-on-exit off \;\221+ split-window -c "$PWD" $opt "${tmux_args[@]}" "bash -c 'exec -a fzf bash $argsf'" $swap \222+ > /dev/null 2>&1 || { "$fzf" "${args[@]}"; exit $?; }223 cat $fifo2224 exit "$(cat $fifo3)"