diff options
Diffstat (limited to 'bin/fzf-tmux')
| -rwxr-xr-x | bin/fzf-tmux | 83 |
1 files changed, 43 insertions, 40 deletions
diff --git a/bin/fzf-tmux b/bin/fzf-tmux index c580a4c4..e73a9085 100755 --- a/bin/fzf-tmux +++ b/bin/fzf-tmux @@ -8,7 +8,7 @@ fail() { } fzf="$(command which fzf)" || fzf="$(dirname "$0")/fzf" -[[ -x "$fzf" ]] || fail 'fzf executable not found' +[[ -x $fzf ]] || fail 'fzf executable not found' args=() opt="" @@ -16,8 +16,8 @@ skip="" swap="" close="" term="" -[[ -n "$LINES" ]] && lines=$LINES || lines=$(tput lines) || lines=$(tmux display-message -p "#{pane_height}") -[[ -n "$COLUMNS" ]] && columns=$COLUMNS || columns=$(tput cols) || columns=$(tmux display-message -p "#{pane_width}") +[[ -n $LINES ]] && lines=$LINES || lines=$(tput lines) || lines=$(tmux display-message -p "#{pane_height}") +[[ -n $COLUMNS ]] && columns=$COLUMNS || columns=$(tput cols) || columns=$(tmux display-message -p "#{pane_width}") tmux_version=$(tmux -V | sed 's/[^0-9.]//g') tmux_32=$(awk '{print ($1 >= 3.2)}' <<< "$tmux_version" 2> /dev/null || bc -l <<< "$tmux_version >= 3.2") @@ -47,7 +47,7 @@ help() { while [[ $# -gt 0 ]]; do arg="$1" shift - [[ -z "$skip" ]] && case "$arg" in + [[ -z $skip ]] && case "$arg" in -) term=1 ;; @@ -58,19 +58,19 @@ while [[ $# -gt 0 ]]; do echo "fzf-tmux (with fzf $("$fzf" --version))" exit ;; - -p*|-w*|-h*|-x*|-y*|-d*|-u*|-r*|-l*) - if [[ "$arg" =~ ^-[pwhxy] ]]; then - [[ "$opt" =~ "-E" ]] || opt="-E" - elif [[ "$arg" =~ ^.[lr] ]]; then + -p* | -w* | -h* | -x* | -y* | -d* | -u* | -r* | -l*) + if [[ $arg =~ ^-[pwhxy] ]]; then + [[ $opt =~ "-E" ]] || opt="-E" + elif [[ $arg =~ ^.[lr] ]]; then opt="-h" - if [[ "$arg" =~ ^.l ]]; then + if [[ $arg =~ ^.l ]]; then opt="$opt -d" swap="; swap-pane -D ; select-pane -L" close="; tmux swap-pane -D" fi else opt="" - if [[ "$arg" =~ ^.u ]]; then + if [[ $arg =~ ^.u ]]; then opt="$opt -d" swap="; swap-pane -D ; select-pane -U" close="; tmux swap-pane -D" @@ -79,7 +79,7 @@ while [[ $# -gt 0 ]]; do if [[ ${#arg} -gt 2 ]]; then size="${arg:2}" else - if [[ "$1" =~ ^[0-9%,]+$ ]] || [[ "$1" =~ ^[A-Z]$ ]]; then + if [[ $1 =~ ^[0-9%,]+$ ]] || [[ $1 =~ ^[A-Z]$ ]]; then size="$1" shift else @@ -87,37 +87,37 @@ while [[ $# -gt 0 ]]; do fi fi - if [[ "$arg" =~ ^-p ]]; then - if [[ -n "$size" ]]; then + if [[ $arg =~ ^-p ]]; then + if [[ -n $size ]]; then w=${size%%,*} h=${size##*,} opt="$opt -w$w -h$h" fi - elif [[ "$arg" =~ ^-[whxy] ]]; then + elif [[ $arg =~ ^-[whxy] ]]; then opt="$opt ${arg:0:2}$size" - elif [[ "$size" =~ %$ ]]; then - size=${size:0:((${#size}-1))} - if [[ $tmux_32 = 1 ]]; then - if [[ -n "$swap" ]]; then - opt="$opt -l $(( 100 - size ))%" + elif [[ $size =~ %$ ]]; then + size=${size:0:${#size}-1} + if [[ $tmux_32 == 1 ]]; then + if [[ -n $swap ]]; then + opt="$opt -l $((100 - size))%" else opt="$opt -l $size%" fi else - if [[ -n "$swap" ]]; then - opt="$opt -p $(( 100 - size ))" + if [[ -n $swap ]]; then + opt="$opt -p $((100 - size))" else opt="$opt -p $size" fi fi else - if [[ -n "$swap" ]]; then - if [[ "$arg" =~ ^.l ]]; then + if [[ -n $swap ]]; then + if [[ $arg =~ ^.l ]]; then max=$columns else max=$lines fi - size=$(( max - size )) + size=$((max - size)) [[ $size -lt 0 ]] && size=0 opt="$opt -l $size" else @@ -135,10 +135,10 @@ while [[ $# -gt 0 ]]; do args+=("$arg") ;; esac - [[ -n "$skip" ]] && args+=("$arg") + [[ -n $skip ]] && args+=("$arg") done -if [[ -z "$TMUX" ]]; then +if [[ -z $TMUX ]]; then "$fzf" "${args[@]}" exit $? fi @@ -149,7 +149,7 @@ fi args=("${args[@]}" "--no-height" "--bind=ctrl-z:ignore" "--no-tmux") # Handle zoomed tmux pane without popup options by moving it to a temp window -if [[ ! "$opt" =~ "-E" ]] && tmux list-panes -F '#F' | grep -q Z; then +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'") @@ -165,22 +165,22 @@ fifo1="${TMPDIR:-/tmp}/fzf-fifo1-$id" fifo2="${TMPDIR:-/tmp}/fzf-fifo2-$id" fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id" if tmux_win_opts=$(tmux show-options -p remain-on-exit \; show-options -p synchronize-panes 2> /dev/null); then - 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") ) + 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")) tmux_off_opts='; set-option -p synchronize-panes off ; set-option -p remain-on-exit off' else - tmux_win_opts=( $(tmux show-window-options remain-on-exit \; show-window-options synchronize-panes | sed '/ off/d; s/^/set-window-option /; s/$/ \\;/') ) + tmux_win_opts=($(tmux show-window-options remain-on-exit \; show-window-options synchronize-panes | sed '/ off/d; s/^/set-window-option /; s/$/ \\;/')) tmux_off_opts='; set-window-option synchronize-panes off ; set-window-option remain-on-exit off' fi cleanup() { \rm -f $argsf $fifo1 $fifo2 $fifo3 # Restore tmux window options - if [[ "${#tmux_win_opts[@]}" -gt 1 ]]; then + if [[ ${#tmux_win_opts[@]} -gt 1 ]]; then eval "tmux ${tmux_win_opts[*]}" fi # Remove temp window if we were zoomed without popup options - if [[ -n "$zoomed_without_popup" ]]; then + 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 \; \ @@ -197,10 +197,10 @@ trap 'cleanup 1' SIGUSR1 trap 'cleanup' EXIT envs="export TERM=$TERM " -if [[ "$opt" =~ "-E" ]]; then - if [[ $tmux_version = 3.2 ]]; then +if [[ $opt =~ "-E" ]]; then + if [[ $tmux_version == 3.2 ]]; then FZF_DEFAULT_OPTS="--margin 0,1 $FZF_DEFAULT_OPTS" - elif [[ $tmux_32 = 1 ]]; then + elif [[ $tmux_32 == 1 ]]; then FZF_DEFAULT_OPTS="--border $FZF_DEFAULT_OPTS" opt="-B $opt" else @@ -211,8 +211,8 @@ fi envs="$envs FZF_DEFAULT_COMMAND=$(printf %q "$FZF_DEFAULT_COMMAND")" envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")" envs="$envs FZF_DEFAULT_OPTS_FILE=$(printf %q "$FZF_DEFAULT_OPTS_FILE")" -[[ -n "$RUNEWIDTH_EASTASIAN" ]] && envs="$envs RUNEWIDTH_EASTASIAN=$(printf %q "$RUNEWIDTH_EASTASIAN")" -[[ -n "$BAT_THEME" ]] && envs="$envs BAT_THEME=$(printf %q "$BAT_THEME")" +[[ -n $RUNEWIDTH_EASTASIAN ]] && envs="$envs RUNEWIDTH_EASTASIAN=$(printf %q "$RUNEWIDTH_EASTASIAN")" +[[ -n $BAT_THEME ]] && envs="$envs BAT_THEME=$(printf %q "$BAT_THEME")" echo "$envs;" > "$argsf" # Build arguments to fzf @@ -224,9 +224,9 @@ close="; trap - EXIT SIGINT SIGTERM $close" export TMUX=$(cut -d , -f 1,2 <<< "$TMUX") mkfifo -m o+w $fifo2 -if [[ "$opt" =~ "-E" ]]; then +if [[ $opt =~ "-E" ]]; then cat $fifo2 & - if [[ -n "$term" ]] || [[ -t 0 ]]; then + if [[ -n $term ]] || [[ -t 0 ]]; then cat <<< "\"$fzf\" $opts > $fifo2; out=\$? $close; exit \$out" >> $argsf else mkfifo $fifo1 @@ -239,7 +239,7 @@ if [[ "$opt" =~ "-E" ]]; then fi mkfifo -m o+w $fifo3 -if [[ -n "$term" ]] || [[ -t 0 ]]; then +if [[ -n $term ]] || [[ -t 0 ]]; then cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" >> $argsf else mkfifo $fifo1 @@ -249,6 +249,9 @@ fi tmux \ split-window -c "$PWD" $opt "bash -c 'exec -a fzf bash $argsf'" $swap \ $tmux_off_opts \ - > /dev/null 2>&1 || { "$fzf" "${args[@]}"; exit $?; } + > /dev/null 2>&1 || { + "$fzf" "${args[@]}" + exit $? +} cat $fifo2 exit "$(cat $fifo3)" |
