Skip to content
Myr

Apply shfmt to bash script files (make fmt)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent f0c4ee4 · Browse files · 11 files+207 added−203 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

11 files+207 added−203 removed

  • other:+207 added−203 removed

11 files+207 added−203 removed

modified:bin/fzf-preview.sh+2 added-2 removed
modified:bin/fzf-tmux+43 added-40 removed
6 unmodified lines
7 exit 28}910fzf="$(command which fzf)" || fzf="$(dirname "$0")/fzf"11[[ -x "$fzf" ]] || fail 'fzf executable not found'11[[ -x $fzf ]] || fail 'fzf executable not found'1213args=()14opt=""15skip=""16swap=""17close=""18term=""19[[ -n "$LINES" ]] && lines=$LINES || lines=$(tput lines) || lines=$(tmux display-message -p "#{pane_height}")20[[ -n "$COLUMNS" ]] && columns=$COLUMNS || columns=$(tput cols) || columns=$(tmux display-message -p "#{pane_width}")19[[ -n $LINES ]] && lines=$LINES || lines=$(tput lines) || lines=$(tmux display-message -p "#{pane_height}")20[[ -n $COLUMNS ]] && columns=$COLUMNS || columns=$(tput cols) || columns=$(tmux display-message -p "#{pane_width}")2122tmux_version=$(tmux -V | sed 's/[^0-9.]//g')23tmux_32=$(awk '{print ($1 >= 3.2)}' <<< "$tmux_version" 2> /dev/null || bc -l <<< "$tmux_version >= 3.2")24
21 unmodified lines
4647while [[ $# -gt 0 ]]; do48 arg="$1"49 shift50 [[ -z "$skip" ]] && case "$arg" in50 [[ -z $skip ]] && case "$arg" in51 -)52 term=153 ;;54 --help)
2 unmodified lines
57 --version)58 echo "fzf-tmux (with fzf $("$fzf" --version))"59 exit60 ;;61 -p*|-w*|-h*|-x*|-y*|-d*|-u*|-r*|-l*)62 if [[ "$arg" =~ ^-[pwhxy] ]]; then63 [[ "$opt" =~ "-E" ]] || opt="-E"64 elif [[ "$arg" =~ ^.[lr] ]]; then61 -p* | -w* | -h* | -x* | -y* | -d* | -u* | -r* | -l*)62 if [[ $arg =~ ^-[pwhxy] ]]; then63 [[ $opt =~ "-E" ]] || opt="-E"64 elif [[ $arg =~ ^.[lr] ]]; then65 opt="-h"66 if [[ "$arg" =~ ^.l ]]; then66 if [[ $arg =~ ^.l ]]; then67 opt="$opt -d"68 swap="; swap-pane -D ; select-pane -L"69 close="; tmux swap-pane -D"70 fi71 else72 opt=""73 if [[ "$arg" =~ ^.u ]]; then73 if [[ $arg =~ ^.u ]]; then74 opt="$opt -d"75 swap="; swap-pane -D ; select-pane -U"76 close="; tmux swap-pane -D"77 fi78 fi79 if [[ ${#arg} -gt 2 ]]; then80 size="${arg:2}"81 else82 if [[ "$1" =~ ^[0-9%,]+$ ]] || [[ "$1" =~ ^[A-Z]$ ]]; then82 if [[ $1 =~ ^[0-9%,]+$ ]] || [[ $1 =~ ^[A-Z]$ ]]; then83 size="$1"84 shift85 else86 continue87 fi88 fi8990 if [[ "$arg" =~ ^-p ]]; then91 if [[ -n "$size" ]]; then90 if [[ $arg =~ ^-p ]]; then91 if [[ -n $size ]]; then92 w=${size%%,*}93 h=${size##*,}94 opt="$opt -w$w -h$h"95 fi96 elif [[ "$arg" =~ ^-[whxy] ]]; then96 elif [[ $arg =~ ^-[whxy] ]]; then97 opt="$opt ${arg:0:2}$size"98 elif [[ "$size" =~ %$ ]]; then99 size=${size:0:((${#size}-1))}100 if [[ $tmux_32 = 1 ]]; then101 if [[ -n "$swap" ]]; then102 opt="$opt -l $(( 100 - size ))%"98 elif [[ $size =~ %$ ]]; then99 size=${size:0:${#size}-1}100 if [[ $tmux_32 == 1 ]]; then101 if [[ -n $swap ]]; then102 opt="$opt -l $((100 - size))%"103 else104 opt="$opt -l $size%"105 fi106 else107 if [[ -n "$swap" ]]; then108 opt="$opt -p $(( 100 - size ))"107 if [[ -n $swap ]]; then108 opt="$opt -p $((100 - size))"109 else110 opt="$opt -p $size"111 fi112 fi113 else114 if [[ -n "$swap" ]]; then115 if [[ "$arg" =~ ^.l ]]; then114 if [[ -n $swap ]]; then115 if [[ $arg =~ ^.l ]]; then116 max=$columns117 else118 max=$lines119 fi120 size=$(( max - size ))120 size=$((max - size))121 [[ $size -lt 0 ]] && size=0122 opt="$opt -l $size"123 else124 opt="$opt -l $size"
9 unmodified lines
134 *)135 args+=("$arg")136 ;;137 esac138 [[ -n "$skip" ]] && args+=("$arg")138 [[ -n $skip ]] && args+=("$arg")139done140141if [[ -z "$TMUX" ]]; then141if [[ -z $TMUX ]]; then142 "$fzf" "${args[@]}"143 exit $?144fi145
2 unmodified lines
148# * fzf-tmux script is not compatible with --tmux option in fzf 0.53.0 or later149args=("${args[@]}" "--no-height" "--bind=ctrl-z:ignore" "--no-tmux")150151# Handle zoomed tmux pane without popup options by moving it to a temp window152if [[ ! "$opt" =~ "-E" ]] && tmux list-panes -F '#F' | grep -q Z; then152if [[ ! $opt =~ "-E" ]] && tmux list-panes -F '#F' | grep -q Z; then153 zoomed_without_popup=1154 original_window=$(tmux display-message -p "#{window_id}")155 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'")156 tmux swap-pane -t $tmp_window \; select-window -t $tmp_window
7 unmodified lines
164fifo1="${TMPDIR:-/tmp}/fzf-fifo1-$id"165fifo2="${TMPDIR:-/tmp}/fzf-fifo2-$id"166fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id"167if tmux_win_opts=$(tmux show-options -p remain-on-exit \; show-options -p synchronize-panes 2> /dev/null); then168 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") )168 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"))169 tmux_off_opts='; set-option -p synchronize-panes off ; set-option -p remain-on-exit off'170else171 tmux_win_opts=( $(tmux show-window-options remain-on-exit \; show-window-options synchronize-panes | sed '/ off/d; s/^/set-window-option /; s/$/ \\;/') )171 tmux_win_opts=($(tmux show-window-options remain-on-exit \; show-window-options synchronize-panes | sed '/ off/d; s/^/set-window-option /; s/$/ \\;/'))172 tmux_off_opts='; set-window-option synchronize-panes off ; set-window-option remain-on-exit off'173fi174cleanup() {175 \rm -f $argsf $fifo1 $fifo2 $fifo3176177 # Restore tmux window options178 if [[ "${#tmux_win_opts[@]}" -gt 1 ]]; then178 if [[ ${#tmux_win_opts[@]} -gt 1 ]]; then179 eval "tmux ${tmux_win_opts[*]}"180 fi181182 # Remove temp window if we were zoomed without popup options183 if [[ -n "$zoomed_without_popup" ]]; then183 if [[ -n $zoomed_without_popup ]]; then184 tmux display-message -p "#{window_id}" > /dev/null185 tmux swap-pane -t $original_window \; \186 select-window -t $original_window \; \187 kill-window -t $tmp_window \; \
8 unmodified lines
196trap 'cleanup 1' SIGUSR1197trap 'cleanup' EXIT198199envs="export TERM=$TERM "200if [[ "$opt" =~ "-E" ]]; then201 if [[ $tmux_version = 3.2 ]]; then200if [[ $opt =~ "-E" ]]; then201 if [[ $tmux_version == 3.2 ]]; then202 FZF_DEFAULT_OPTS="--margin 0,1 $FZF_DEFAULT_OPTS"203 elif [[ $tmux_32 = 1 ]]; then203 elif [[ $tmux_32 == 1 ]]; then204 FZF_DEFAULT_OPTS="--border $FZF_DEFAULT_OPTS"205 opt="-B $opt"206 else207 echo "fzf-tmux: tmux 3.2 or above is required for popup mode" >&2
2 unmodified lines
210fi211envs="$envs FZF_DEFAULT_COMMAND=$(printf %q "$FZF_DEFAULT_COMMAND")"212envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")"213envs="$envs FZF_DEFAULT_OPTS_FILE=$(printf %q "$FZF_DEFAULT_OPTS_FILE")"214[[ -n "$RUNEWIDTH_EASTASIAN" ]] && envs="$envs RUNEWIDTH_EASTASIAN=$(printf %q "$RUNEWIDTH_EASTASIAN")"215[[ -n "$BAT_THEME" ]] && envs="$envs BAT_THEME=$(printf %q "$BAT_THEME")"214[[ -n $RUNEWIDTH_EASTASIAN ]] && envs="$envs RUNEWIDTH_EASTASIAN=$(printf %q "$RUNEWIDTH_EASTASIAN")"215[[ -n $BAT_THEME ]] && envs="$envs BAT_THEME=$(printf %q "$BAT_THEME")"216echo "$envs;" > "$argsf"217218# Build arguments to fzf219opts=$(printf "%q " "${args[@]}")
3 unmodified lines
223close="; trap - EXIT SIGINT SIGTERM $close"224225export TMUX=$(cut -d , -f 1,2 <<< "$TMUX")226mkfifo -m o+w $fifo2227if [[ "$opt" =~ "-E" ]]; then227if [[ $opt =~ "-E" ]]; then228 cat $fifo2 &229 if [[ -n "$term" ]] || [[ -t 0 ]]; then229 if [[ -n $term ]] || [[ -t 0 ]]; then230 cat <<< "\"$fzf\" $opts > $fifo2; out=\$? $close; exit \$out" >> $argsf231 else232 mkfifo $fifo1233 cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; out=\$? $close; exit \$out" >> $argsf
4 unmodified lines
238 exit $?239fi240241mkfifo -m o+w $fifo3242if [[ -n "$term" ]] || [[ -t 0 ]]; then242if [[ -n $term ]] || [[ -t 0 ]]; then243 cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" >> $argsf244else245 mkfifo $fifo1246 cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" >> $argsf
1 unmodified line
248fi249tmux \250 split-window -c "$PWD" $opt "bash -c 'exec -a fzf bash $argsf'" $swap \251 $tmux_off_opts \252 > /dev/null 2>&1 || { "$fzf" "${args[@]}"; exit $?; }252 > /dev/null 2>&1 || {253 "$fzf" "${args[@]}"254 exit $?255}256cat $fifo2257exit "$(cat $fifo3)"
modified:shell/common.sh+2 added-3 removed
modified:shell/completion.bash+73 added-72 removed
46 unmodified lines
47 if [[ -z ${__fzf_awk-} ]]; then48 __fzf_awk=awk49 if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then50 __fzf_awk=/usr/xpg4/bin/awk51 elif command -v mawk >/dev/null 2>&1; then51 elif command -v mawk > /dev/null 2>&1; then52 local n x y z d53 IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)54 [[ $n == mawk ]] && (( d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004 )) && __fzf_awk=mawk54 [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk55 fi56 fi57 LC_ALL=C exec "$__fzf_awk" "$@"58}59#----END INCLUDE6061__fzf_comprun() {62 if [[ "$(type -t _fzf_comprun 2>&1)" = function ]]; then62 if [[ "$(type -t _fzf_comprun 2>&1)" == function ]]; then63 _fzf_comprun "$@"64 elif [[ -n "${TMUX_PANE-}" ]] && { [[ "${FZF_TMUX:-0}" != 0 ]] || [[ -n "${FZF_TMUX_OPTS-}" ]]; }; then64 elif [[ -n ${TMUX_PANE-} ]] && { [[ ${FZF_TMUX:-0} != 0 ]] || [[ -n ${FZF_TMUX_OPTS-} ]]; }; then65 shift66 fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- "$@"67 else68 shift
3 unmodified lines
7273__fzf_orig_completion() {74 local l comp f cmd75 while read -r l; do76 if [[ "$l" =~ ^(.*\ -F)\ *([^ ]*).*\ ([^ ]*)$ ]]; then76 if [[ $l =~ ^(.*\ -F)\ *([^ ]*).*\ ([^ ]*)$ ]]; then77 comp="${BASH_REMATCH[1]}"78 f="${BASH_REMATCH[2]}"79 cmd="${BASH_REMATCH[3]}"80 [[ "$f" = _fzf_* ]] && continue80 [[ $f == _fzf_* ]] && continue81 printf -v "_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}" "%s" "${comp} %s ${cmd} #${f}"82 if [[ "$l" = *" -o nospace "* ]] && [[ ! "${__fzf_nospace_commands-}" = *" $cmd "* ]]; then82 if [[ $l == *" -o nospace "* ]] && [[ ${__fzf_nospace_commands-} != *" $cmd "* ]]; then83 __fzf_nospace_commands="${__fzf_nospace_commands-} $cmd "84 fi85 fi86 done
27 unmodified lines
114_fzf_opts_completion() {115 local cur prev opts116 COMPREPLY=()117 cur="${COMP_WORDS[COMP_CWORD]}"118 prev="${COMP_WORDS[COMP_CWORD-1]}"118 prev="${COMP_WORDS[COMP_CWORD - 1]}"119 opts="120 +c --no-color121 +i --no-ignore-case122 +s --no-sort
74 unmodified lines
197 -q --query198 --"199200 case "${prev}" in201 --scheme)202 COMPREPLY=( $(compgen -W "default path history" -- "$cur") )203 return 0204 ;;205 --tiebreak)206 COMPREPLY=( $(compgen -W "length chunk begin end index" -- "$cur") )207 return 0208 ;;209 --color)210 COMPREPLY=( $(compgen -W "dark light 16 bw no" -- "$cur") )211 return 0212 ;;213 --layout)214 COMPREPLY=( $(compgen -W "default reverse reverse-list" -- "$cur") )215 return 0216 ;;217 --info)218 COMPREPLY=( $(compgen -W "default right hidden inline inline-right" -- "$cur") )219 return 0220 ;;221 --preview-window)222 COMPREPLY=( $(compgen -W "201 --scheme)202 COMPREPLY=($(compgen -W "default path history" -- "$cur"))203 return 0204 ;;205 --tiebreak)206 COMPREPLY=($(compgen -W "length chunk begin end index" -- "$cur"))207 return 0208 ;;209 --color)210 COMPREPLY=($(compgen -W "dark light 16 bw no" -- "$cur"))211 return 0212 ;;213 --layout)214 COMPREPLY=($(compgen -W "default reverse reverse-list" -- "$cur"))215 return 0216 ;;217 --info)218 COMPREPLY=($(compgen -W "default right hidden inline inline-right" -- "$cur"))219 return 0220 ;;221 --preview-window)222 COMPREPLY=($(compgen -W "223 default224 hidden225 nohidden226 wrap
17 unmodified lines
244 border-down border-bottom245 border-left246 border-right247 follow248 nofollow" -- "$cur") )249 return 0250 ;;251 --border)252 COMPREPLY=( $(compgen -W "rounded sharp bold block thinblock double horizontal vertical top bottom left right none" -- "$cur") )253 return 0254 ;;255 --border-label-pos|--preview-label-pos)256 COMPREPLY=( $(compgen -W "center bottom top" -- "$cur") )257 return 0258 ;;248 nofollow" -- "$cur"))249 return 0250 ;;251 --border)252 COMPREPLY=($(compgen -W "rounded sharp bold block thinblock double horizontal vertical top bottom left right none" -- "$cur"))253 return 0254 ;;255 --border-label-pos | --preview-label-pos)256 COMPREPLY=($(compgen -W "center bottom top" -- "$cur"))257 return 0258 ;;259 esac260261 if [[ "$cur" =~ ^-|\+ ]]; then262 COMPREPLY=( $(compgen -W "${opts}" -- "$cur") )261 if [[ $cur =~ ^-|\+ ]]; then262 COMPREPLY=($(compgen -W "${opts}" -- "$cur"))263 return 0264 fi265266 return 0
5 unmodified lines
272 shift273 orig_cmd="$1"274 if __fzf_orig_completion_get_orig_func "$cmd"; then275 "$REPLY" "$@"276 elif [[ -n "${_fzf_completion_loader-}" ]]; then276 elif [[ -n ${_fzf_completion_loader-} ]]; then277 orig_complete=$(complete -p "$orig_cmd" 2> /dev/null)278 $_fzf_completion_loader "$@"279 ret=$?280 # _completion_loader may not have updated completion for the command
5 unmodified lines
286 [[ $orig_complete =~ ' -F '(_fzf_[^ ]+)' ' ]] &&287 __fzf_orig_completion_instantiate "$cmd" "${BASH_REMATCH[1]}" &&288 orig_complete=$REPLY289290 if [[ "${__fzf_nospace_commands-}" = *" $orig_cmd "* ]]; then290 if [[ ${__fzf_nospace_commands-} == *" $orig_cmd "* ]]; then291 eval "${orig_complete/ -F / -o nospace -F }"292 else293 eval "$orig_complete"294 fi
11 unmodified lines
306 fi307 COMPREPLY=()308 trigger=${FZF_COMPLETION_TRIGGER-'**'}309 [[ $COMP_CWORD -ge 0 ]] && cur="${COMP_WORDS[COMP_CWORD]}"310 if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then310 if [[ $cur == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then311 base=${cur:0:${#cur}-${#trigger}}312 eval "base=$base" 2> /dev/null || return313314 dir=315 [[ $base = *"/"* ]] && dir="$base"315 [[ $base == *"/"* ]] && dir="$base"316 while true; do317 if [[ -z "$dir" ]] || [[ -d "$dir" ]]; then318 leftover=${base/#"$dir"}319 leftover=${leftover/#\/}320 [[ -z "$dir" ]] && dir='.'321 [[ "$dir" != "/" ]] && dir="${dir/%\//}"317 if [[ -z $dir ]] || [[ -d $dir ]]; then318 leftover=${base/#"$dir"/}319 leftover=${leftover/#\//}320 [[ -z $dir ]] && dir='.'321 [[ $dir != "/" ]] && dir="${dir/%\//}"322 matches=$(323 export FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --scheme=path" "${FZF_COMPLETION_OPTS-} $2")324 unset FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS_FILE325 if declare -F "$1" > /dev/null; then
11 unmodified lines
337 printf "%q " "${item%$3}$3"338 done339 )340 matches=${matches% }341 [[ -z "$3" ]] && [[ "${__fzf_nospace_commands-}" = *" ${COMP_WORDS[0]} "* ]] && matches="$matches "342 if [[ -n "$matches" ]]; then343 COMPREPLY=( "$matches" )341 [[ -z $3 ]] && [[ ${__fzf_nospace_commands-} == *" ${COMP_WORDS[0]} "* ]] && matches="$matches "342 if [[ -n $matches ]]; then343 COMPREPLY=("$matches")344 else345 COMPREPLY=( "$cur" )345 COMPREPLY=("$cur")346 fi347 # To redraw line after fzf closes (printf '\e[5n')348 bind '"\e[0n": redraw-current-line' 2> /dev/null349 printf '\e[5n'350 return 0351 fi352 dir=$(command dirname "$dir")353 [[ "$dir" =~ /$ ]] || dir="$dir"/353 [[ $dir =~ /$ ]] || dir="$dir"/354 done355 else356 shift357 shift
7 unmodified lines
365 local args rest str_arg i sep366 args=("$@")367 sep=368 for i in "${!args[@]}"; do369 if [[ "${args[$i]}" = -- ]]; then369 if [[ ${args[$i]} == -- ]]; then370 sep=$i371 break372 fi373 done374 if [[ -n "$sep" ]]; then374 if [[ -n $sep ]]; then375 str_arg=376 rest=("${args[@]:$((sep + 1)):${#args[@]}}")377 args=("${args[@]:0:$sep}")377 args=("${args[@]:0:sep}")378 else379 str_arg=$1380 args=()381 shift
6 unmodified lines
388389 trigger=${FZF_COMPLETION_TRIGGER-'**'}390 cmd="${COMP_WORDS[0]}"391 cur="${COMP_WORDS[COMP_CWORD]}"392 if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then392 if [[ $cur == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then393 cur=${cur:0:${#cur}-${#trigger}}394395 selected=$(396 FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse" "${FZF_COMPLETION_OPTS-} $str_arg") \397 FZF_DEFAULT_OPTS_FILE='' \398 __fzf_comprun "${rest[0]}" "${args[@]}" -q "$cur" | eval "$post" | command tr '\n' ' ')398 __fzf_comprun "${rest[0]}" "${args[@]}" -q "$cur" | eval "$post" | command tr '\n' ' '399 )400 selected=${selected% } # Strip trailing space not to repeat "-o nospace"400 if [[ -n "$selected" ]]; then401 if [[ -n $selected ]]; then402 COMPREPLY=("$selected")403 else404 COMPREPLY=("$cur")405 fi
49 unmodified lines
455 fi456 '457 _fzf_complete -m --header-lines=1 --no-preview --wrap --color fg:dim,nth:regular \458 --bind "click-header:transform:$transformer" -- "$@" < <(458 command ps -eo user,pid,ppid,start,time,command 2> /dev/null ||459 command ps -eo user,pid,ppid,time,args 2> /dev/null || # For BusyBox460 command ps --everyone --full --windows # For cygwin461 )459 command ps -eo user,pid,ppid,start,time,command 2> /dev/null ||460 command ps -eo user,pid,ppid,time,args 2> /dev/null || # For BusyBox461 command ps --everyone --full --windows # For cygwin462 )463}464465_fzf_proc_completion_post() {466 __fzf_exec_awk '{print $2}'
74 unmodified lines
541# > the second argument ($2) is the word being completed,542# > and the third argument ($3) is the word preceding the word being completed on the current command line.543_fzf_complete_ssh() {544 case $3 in544 -i|-F|-E)545 -i | -F | -E)546 _fzf_path_completion "$@"547 ;;548 *)549 local user=549 [[ "$2" =~ '@' ]] && user="${2%%@*}@"550 [[ $2 =~ '@' ]] && user="${2%%@*}@"551 _fzf_complete +m -- "$@" < <(__fzf_list_hosts | __fzf_exec_awk -v user="$user" '{print user $0}')552 ;;553 esac554}
122 unmodified lines
677 shift678 __fzf_orig_completion < <(complete -p "$@" 2> /dev/null)679 for cmd in "$@"; do680 case "$kind" in680 dir) __fzf_defc "$cmd" "$fn" "-o nospace -o dirnames" ;;681 var) __fzf_defc "$cmd" "$fn" "-o default -o nospace -v" ;;681 dir) __fzf_defc "$cmd" "$fn" "-o nospace -o dirnames" ;;682 var) __fzf_defc "$cmd" "$fn" "-o default -o nospace -v" ;;683 alias) __fzf_defc "$cmd" "$fn" "-a" ;;683 *) __fzf_defc "$cmd" "$fn" "-o default -o bashdefault" ;;684 *) __fzf_defc "$cmd" "$fn" "-o default -o bashdefault" ;;685 esac686 done687}688#----END shfmt
2 unmodified lines
modified:shell/completion.zsh+2 added-2 removed
110 unmodified lines
111 if [[ -z ${__fzf_awk-} ]]; then112 __fzf_awk=awk113 if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then114 __fzf_awk=/usr/xpg4/bin/awk115 elif command -v mawk >/dev/null 2>&1; then115 elif command -v mawk > /dev/null 2>&1; then116 local n x y z d117 IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)118 [[ $n == mawk ]] && (( d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004 )) && __fzf_awk=mawk118 [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk119 fi120 fi121 LC_ALL=C exec "$__fzf_awk" "$@"122}
350 unmodified lines
modified:shell/key-bindings.bash+19 added-19 removed
32 unmodified lines
33 if [[ -z ${__fzf_awk-} ]]; then34 __fzf_awk=awk35 if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then36 __fzf_awk=/usr/xpg4/bin/awk37 elif command -v mawk >/dev/null 2>&1; then37 elif command -v mawk > /dev/null 2>&1; then38 local n x y z d39 IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)40 [[ $n == mawk ]] && (( d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004 )) && __fzf_awk=mawk40 [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk41 fi42 fi43 LC_ALL=C exec "$__fzf_awk" "$@"44}45#----END INCLUDE4647__fzf_select__() {48 FZF_DEFAULT_COMMAND=${FZF_CTRL_T_COMMAND:-} \49 FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=file,dir,follow,hidden --scheme=path" "${FZF_CTRL_T_OPTS-} -m") \50 FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) "$@" |49 FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=file,dir,follow,hidden --scheme=path" "${FZF_CTRL_T_OPTS-} -m") \50 FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) "$@" |51 while read -r item; do52 printf '%q ' "$item" # escape special chars52 printf '%q ' "$item" # escape special chars53 done54}5556__fzfcmd() {57 [[ -n "${TMUX_PANE-}" ]] && { [[ "${FZF_TMUX:-0}" != 0 ]] || [[ -n "${FZF_TMUX_OPTS-}" ]]; } &&57 [[ -n ${TMUX_PANE-} ]] && { [[ ${FZF_TMUX:-0} != 0 ]] || [[ -n ${FZF_TMUX_OPTS-} ]]; } &&58 echo "fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- " || echo "fzf"59}6061fzf-file-widget() {62 local selected="$(__fzf_select__ "$@")"63 READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"64 READLINE_POINT=$(( READLINE_POINT + ${#selected} ))63 READLINE_LINE="${READLINE_LINE:0:READLINE_POINT}$selected${READLINE_LINE:READLINE_POINT}"64 READLINE_POINT=$((READLINE_POINT + ${#selected}))65}6667__fzf_cd__() {68 local dir69 dir=$(70 FZF_DEFAULT_COMMAND=${FZF_ALT_C_COMMAND:-} \71 FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=dir,follow,hidden --scheme=path" "${FZF_ALT_C_OPTS-} +m") \72 FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd)71 FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=dir,follow,hidden --scheme=path" "${FZF_ALT_C_OPTS-} +m") \72 FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd)73 ) && printf 'builtin cd -- %q' "$(builtin unset CDPATH && builtin cd -- "$dir" && builtin pwd)"74}7576if command -v perl > /dev/null; then
7 unmodified lines
84 FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"$'\t'"↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} +m --read0") \85 FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE"86 ) || return87 READLINE_LINE=$(command perl -pe 's/^\d*\t//' <<< "$output")88 if [[ -z "$READLINE_POINT" ]]; then88 if [[ -z $READLINE_POINT ]]; then89 echo "$READLINE_LINE"90 else91 READLINE_POINT=0x7fffffff92 fi93 }94else # awk - fallback for POSIX systems95 __fzf_history__() {96 local output script97 [[ $(HISTTIMEFORMAT='' builtin history 1) =~ [[:digit:]]+ ]] # how many history entries97 [[ $(HISTTIMEFORMAT='' builtin history 1) =~ [[:digit:]]+ ]] # how many history entries98 script='function P(b) { ++n; sub(/^[ *]/, "", b); if (!seen[b]++) { printf "%d\t%s%c", '$((BASH_REMATCH + 1))' - n, b, 0 } }99 NR==1 { b = substr($0, 2); next }100 /^\t/ { P(b); b = substr($0, 2); next }101 { b = b RS $0 }102 END { if (NR) P(b) }'103 output=$(104 set +o pipefail105 builtin fc -lnr -2147483648 2> /dev/null | # ( $'\t '<lines>$'\n' )* ; <lines> ::= [^\n]* ( $'\n'<lines> )*106 __fzf_exec_awk "$script" | # ( <counter>$'\t'<lines>$'\000' )*105 builtin fc -lnr -2147483648 2> /dev/null | # ( $'\t '<lines>$'\n' )* ; <lines> ::= [^\n]* ( $'\n'<lines> )*106 __fzf_exec_awk "$script" | # ( <counter>$'\t'<lines>$'\000' )*107 FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"$'\t'"↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} +m --read0") \108 FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE"109 ) || return110 READLINE_LINE=${output#*$'\t'}111 if [[ -z "$READLINE_POINT" ]]; then111 if [[ -z $READLINE_POINT ]]; then112 echo "$READLINE_LINE"113 else114 READLINE_POINT=0x7fffffff115 fi
6 unmodified lines
122bind -m vi-command '"\C-z": emacs-editing-mode'123bind -m vi-insert '"\C-z": emacs-editing-mode'124bind -m emacs-standard '"\C-z": vi-editing-mode'125126if (( BASH_VERSINFO[0] < 4 )); then126if ((BASH_VERSINFO[0] < 4)); then127 # CTRL-T - Paste the selected file path into the command line128 if [[ "${FZF_CTRL_T_COMMAND-x}" != "" ]]; then128 if [[ ${FZF_CTRL_T_COMMAND-x} != "" ]]; then129 bind -m emacs-standard '"\C-t": " \C-b\C-k \C-u`__fzf_select__`\e\C-e\er\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f\C-y\ey\C-_"'130 bind -m vi-command '"\C-t": "\C-z\C-t\C-z"'131 bind -m vi-insert '"\C-t": "\C-z\C-t\C-z"'132 fi
3 unmodified lines
136 bind -m vi-command '"\C-r": "\C-z\C-r\C-z"'137 bind -m vi-insert '"\C-r": "\C-z\C-r\C-z"'138else139 # CTRL-T - Paste the selected file path into the command line140 if [[ "${FZF_CTRL_T_COMMAND-x}" != "" ]]; then140 if [[ ${FZF_CTRL_T_COMMAND-x} != "" ]]; then141 bind -m emacs-standard -x '"\C-t": fzf-file-widget'142 bind -m vi-command -x '"\C-t": fzf-file-widget'143 bind -m vi-insert -x '"\C-t": fzf-file-widget'144 fi
4 unmodified lines
149 bind -m vi-insert -x '"\C-r": __fzf_history__'150fi151152# ALT-C - cd into the selected directory153if [[ "${FZF_ALT_C_COMMAND-x}" != "" ]]; then153if [[ ${FZF_ALT_C_COMMAND-x} != "" ]]; then154 bind -m emacs-standard '"\ec": " \C-b\C-k \C-u`__fzf_cd__`\e\C-e\er\C-m\C-y\C-h\e \C-y\ey\C-x\C-x\C-d\C-y\ey\C-_"'155 bind -m vi-command '"\ec": "\C-z\ec\C-z"'156 bind -m vi-insert '"\ec": "\C-z\ec\C-z"'157fi
3 unmodified lines
modified:shell/key-bindings.zsh+2 added-2 removed
52 unmodified lines
53 if [[ -z ${__fzf_awk-} ]]; then54 __fzf_awk=awk55 if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then56 __fzf_awk=/usr/xpg4/bin/awk57 elif command -v mawk >/dev/null 2>&1; then57 elif command -v mawk > /dev/null 2>&1; then58 local n x y z d59 IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)60 [[ $n == mawk ]] && (( d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004 )) && __fzf_awk=mawk60 [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk61 fi62 fi63 LC_ALL=C exec "$__fzf_awk" "$@"64}
98 unmodified lines
modified:shell/update.sh+2 added-1 removed
modified:.editorconfig+2 added-2 removed
2 unmodified lines
3[*.{sh,bash}]4indent_style = space5indent_size = 26simplify = true7binary_next_line = true7binary_next_line = false8switch_case_indent = true9space_redirects = true10function_next_line = false11
1 unmodified line
13[{install,uninstall,bin/fzf-preview.sh,bin/fzf-tmux}]14indent_style = space15indent_size = 216simplify = true17binary_next_line = true17binary_next_line = false18switch_case_indent = true19space_redirects = true20function_next_line = false
modified:install+54 added-54 removed
44 unmodified lines
45 prefix='"${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf'46 prefix_expand=${XDG_CONFIG_HOME:-$HOME/.config}/fzf/fzf47 mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/fzf"48 ;;49 --key-bindings) key_bindings=1 ;;50 --no-key-bindings) key_bindings=0 ;;51 --completion) auto_completion=1 ;;52 --no-completion) auto_completion=0 ;;53 --update-rc) update_config=1 ;;54 --no-update-rc) update_config=0 ;;55 --bin) ;;56 --no-bash) shells=${shells/bash/} ;;57 --no-zsh) shells=${shells/zsh/} ;;58 --no-fish) shells=${shells/fish/} ;;49 --key-bindings) key_bindings=1 ;;50 --no-key-bindings) key_bindings=0 ;;51 --completion) auto_completion=1 ;;52 --no-completion) auto_completion=0 ;;53 --update-rc) update_config=1 ;;54 --no-update-rc) update_config=0 ;;55 --bin) ;;56 --no-bash) shells=${shells/bash/} ;;57 --no-zsh) shells=${shells/zsh/} ;;58 --no-fish) shells=${shells/fish/} ;;59 *)60 echo "unknown option: $opt"61 help62 exit 1
40 unmodified lines
103}104105link_fzf_in_path() {106 if which_fzf="$(command -v fzf)"; then107 echo " - Found in \$PATH"107 echo ' - Found in $PATH'108 echo " - Creating symlink: bin/fzf -> $which_fzf"109 (cd "$fzf_base"/bin && rm -f fzf && ln -sf "$which_fzf" fzf)110 check_binary && return111 fi
1 unmodified line
113}114115try_curl() {116 command -v curl > /dev/null &&117 if [[ $1 =~ tar.gz$ ]]; then118 curl -fL $1 | tar --no-same-owner -xzf -119 else120 local temp=${TMPDIR:-/tmp}/fzf.zip121 curl -fLo "$temp" $1 && unzip -o "$temp" && rm -f "$temp"122 fi117 if [[ $1 =~ tar.gz$ ]]; then118 curl -fL $1 | tar --no-same-owner -xzf -119 else120 local temp=${TMPDIR:-/tmp}/fzf.zip121 curl -fLo "$temp" $1 && unzip -o "$temp" && rm -f "$temp"122 fi123}124125try_wget() {126 command -v wget > /dev/null &&127 if [[ $1 =~ tar.gz$ ]]; then128 wget -O - $1 | tar --no-same-owner -xzf -129 else130 local temp=${TMPDIR:-/tmp}/fzf.zip131 wget -O "$temp" $1 && unzip -o "$temp" && rm -f "$temp"132 fi127 if [[ $1 =~ tar.gz$ ]]; then128 wget -O - $1 | tar --no-same-owner -xzf -129 else130 local temp=${TMPDIR:-/tmp}/fzf.zip131 wget -O "$temp" $1 && unzip -o "$temp" && rm -f "$temp"132 fi133}134135download() {136 echo "Downloading bin/fzf ..."
26 unmodified lines
163 chmod +x fzf && check_binary164}165166# Try to download binary executable167archi=$(uname -smo 2>/dev/null || uname -sm)167archi=$(uname -smo 2> /dev/null || uname -sm)168binary_available=1169binary_error=""170case "$archi" in171 Darwin\ arm64*) download fzf-$version-darwin_arm64.tar.gz ;;172 Darwin\ x86_64*) download fzf-$version-darwin_amd64.tar.gz ;;173 Linux\ armv5*) download fzf-$version-linux_armv5.tar.gz ;;174 Linux\ armv6*) download fzf-$version-linux_armv6.tar.gz ;;175 Linux\ armv7*) download fzf-$version-linux_armv7.tar.gz ;;176 Linux\ armv8*) download fzf-$version-linux_arm64.tar.gz ;;171 Darwin\ arm64*) download fzf-$version-darwin_arm64.tar.gz ;;172 Darwin\ x86_64*) download fzf-$version-darwin_amd64.tar.gz ;;173 Linux\ armv5*) download fzf-$version-linux_armv5.tar.gz ;;174 Linux\ armv6*) download fzf-$version-linux_armv6.tar.gz ;;175 Linux\ armv7*) download fzf-$version-linux_armv7.tar.gz ;;176 Linux\ armv8*) download fzf-$version-linux_arm64.tar.gz ;;177 Linux\ aarch64\ Android) download fzf-$version-android_arm64.tar.gz ;;178 Linux\ aarch64*) download fzf-$version-linux_arm64.tar.gz ;;179 Linux\ loongarch64*) download fzf-$version-linux_loong64.tar.gz ;;180 Linux\ ppc64le*) download fzf-$version-linux_ppc64le.tar.gz ;;181 Linux\ *64*) download fzf-$version-linux_amd64.tar.gz ;;182 Linux\ s390x*) download fzf-$version-linux_s390x.tar.gz ;;183 FreeBSD\ *64*) download fzf-$version-freebsd_amd64.tar.gz ;;184 OpenBSD\ *64*) download fzf-$version-openbsd_amd64.tar.gz ;;185 CYGWIN*\ *64*) download fzf-$version-windows_amd64.zip ;;186 MINGW*\ *64*) download fzf-$version-windows_amd64.zip ;;187 MSYS*\ *64*) download fzf-$version-windows_amd64.zip ;;188 Windows*\ *64*) download fzf-$version-windows_amd64.zip ;;189 *) binary_available=0 binary_error=1 ;;178 Linux\ aarch64*) download fzf-$version-linux_arm64.tar.gz ;;179 Linux\ loongarch64*) download fzf-$version-linux_loong64.tar.gz ;;180 Linux\ ppc64le*) download fzf-$version-linux_ppc64le.tar.gz ;;181 Linux\ *64*) download fzf-$version-linux_amd64.tar.gz ;;182 Linux\ s390x*) download fzf-$version-linux_s390x.tar.gz ;;183 FreeBSD\ *64*) download fzf-$version-freebsd_amd64.tar.gz ;;184 OpenBSD\ *64*) download fzf-$version-openbsd_amd64.tar.gz ;;185 CYGWIN*\ *64*) download fzf-$version-windows_amd64.zip ;;186 MINGW*\ *64*) download fzf-$version-windows_amd64.zip ;;187 MSYS*\ *64*) download fzf-$version-windows_amd64.zip ;;188 Windows*\ *64*) download fzf-$version-windows_amd64.zip ;;189 *) binary_available=0 binary_error=1 ;;190esac191192cd "$fzf_base"193if [ -n "$binary_error" ]; then
20 unmodified lines
214 exit 1215 fi216fi217218[[ "$*" =~ "--bin" ]] && exit 0218[[ $* =~ "--bin" ]] && exit 0219220for s in $shells; do221 if ! command -v "$s" > /dev/null; then222 shells=${shells/$s/}
18 unmodified lines
241fi242243echo244for shell in $shells; do245 [[ "$shell" = fish ]] && continue245 [[ $shell == fish ]] && continue246 src=${prefix_expand}.${shell}247 echo -n "Generate $src ... "248249 fzf_completion="source \"$fzf_base/shell/completion.${shell}\""
15 unmodified lines
265266EOF267268 if [[ $auto_completion -eq 1 ]] && [[ $key_bindings -eq 1 ]]; then269 if [[ "$shell" = zsh ]]; then269 if [[ $shell == zsh ]]; then270 echo "source <(fzf --$shell)" >> "$src"271 else272 echo "eval \"\$(fzf --$shell)\"" >> "$src"273 fi
11 unmodified lines
285 echo "OK"286done287288# fish289if [[ "$shells" =~ fish ]]; then289if [[ $shells =~ fish ]]; then290 echo -n "Update fish_user_paths ... "291 fish << EOF292 echo \$fish_user_paths | \grep "$fzf_base"/bin > /dev/null293 or set --universal fish_user_paths \$fish_user_paths "$fzf_base"/bin
23 unmodified lines
317 echo " - Already exists:"318 sed 's/^/ Line /' <<< "$lines"319320 update=0321 if ! \grep -qv "^[0-9]*:[[:space:]]*#" <<< "$lines" ; then321 if ! \grep -qv "^[0-9]*:[[:space:]]*#" <<< "$lines"; then322 echo " - But they all seem to be commented"323 ask " - Continue modifying $file?"323 ask " - Continue modifying $file?"324 update=$?325 fi326 fi327
27 unmodified lines
355 update_config=$?356fi357echo358for shell in $shells; do359 [[ "$shell" = fish ]] && continue359 [[ $shell == fish ]] && continue360 [ $shell = zsh ] && dest=${ZDOTDIR:-~}/.zshrc || dest=~/.bashrc361 append_line $update_config "[ -f ${prefix}.${shell} ] && source ${prefix}.${shell}" "$dest" "${prefix}.${shell}"362done363364if [ $key_bindings -eq 1 ] && [[ "$shells" =~ fish ]]; then364if [ $key_bindings -eq 1 ] && [[ $shells =~ fish ]]; then365 bind_file="${fish_dir}/functions/fish_user_key_bindings.fish"366 if [ ! -e "$bind_file" ]; then367 mkdir -p "${fish_dir}/functions"368 create_file "$bind_file" \
16 unmodified lines
385fi386387if [ $update_config -eq 1 ]; then388 echo 'Finished. Restart your shell or reload config file.'389 if [[ "$shells" =~ bash ]]; then389 if [[ $shells =~ bash ]]; then390 echo -n ' source ~/.bashrc # bash'391 [[ "$archi" =~ Darwin ]] && echo -n ' (.bashrc should be loaded from .bash_profile)'391 [[ $archi =~ Darwin ]] && echo -n ' (.bashrc should be loaded from .bash_profile)'392 echo393 fi394 [[ "$shells" =~ zsh ]] && echo " source ${ZDOTDIR:-~}/.zshrc # zsh"395 [[ "$shells" =~ fish ]] && [ $key_bindings -eq 1 ] && echo ' fzf_key_bindings # fish'394 [[ $shells =~ zsh ]] && echo " source ${ZDOTDIR:-~}/.zshrc # zsh"395 [[ $shells =~ fish ]] && [ $key_bindings -eq 1 ] && echo ' fzf_key_bindings # fish'396 echo397 echo 'Use uninstall script to remove fzf.'398 echo399fi
1 unmodified line
modified:uninstall+6 added-6 removed
62 unmodified lines
63 shift64 line_no=165 continue66 fi67 line_no=$(( $(sed 's/:.*//' <<< "$line") + line_no - 1 ))67 line_no=$(($(sed 's/:.*//' <<< "$line") + line_no - 1))68 content=$(sed 's/^[0-9]*://' <<< "$line")69 match=170 echo " - Line #$line_no: $content"70 echo " - Line #$line_no: $content"71 [ "$content" = "$1" ] || ask " - Remove?"72 if [ $? -eq 0 ]; then73 temp=$(mktemp)74 awk -v n=$line_no 'NR == n {next} {print}' "$src" > "$temp" &&75 cat "$temp" > "$src" && rm -f "$temp" || break76 echo " - Removed"76 echo " - Removed"77 else78 echo " - Skipped"79 line_no=$(( line_no + 1 ))78 echo " - Skipped"79 line_no=$((line_no + 1))80 fi81 done82 [ $match -eq 0 ] && echo " - Nothing found"83 echo
24 unmodified lines
108 fi109fi110111config_dir=$(dirname "$prefix_expand")112if [[ "$xdg" = 1 ]] && [[ "$config_dir" = */fzf ]] && [[ -d "$config_dir" ]]; then112if [[ $xdg == 1 ]] && [[ $config_dir == */fzf ]] && [[ -d $config_dir ]]; then113 rmdir "$config_dir"114fi