Skip to content
Myr

completion.bash

This file

Path

shell/completion.bash

312 lines · 7.8 KiB · Shell

Last changed by

[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3

History of this file

Take it

The walk stopped after 200 commits: lines older than 022435a point at it.

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 1–12why, one step back
1#!/bin/bash
2# ____ ____3# / __/___ / __/4# / /_/_ / / /_5# / __/ / /_/ __/6# /_/ /___/_/-completion.bash7#8# - $FZF_TMUX (default: 1)9# - $FZF_TMUX_HEIGHT (default: '40%')10# - $FZF_COMPLETION_TRIGGER (default: '**')11# - $FZF_COMPLETION_OPTS (default: empty)12

Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647

lines 13–32why, one step back
13# To use custom commands instead of find, override _fzf_compgen_{path,dir}
14if ! declare -f _fzf_compgen_path > /dev/null; then15 _fzf_compgen_path() {16 echo "$1"17 \find -L "$1" \18 -name .git -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \19 -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'20 }21fi2223if ! declare -f _fzf_compgen_dir > /dev/null; then24 _fzf_compgen_dir() {25 \find -L "$1" \26 -name .git -prune -o -name .svn -prune -o -type d \27 -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'28 }29fi3031###########################################################32

More alternative notations for execute actionJunegunn Choibefore adoption022435a

line 33why, one step back
33_fzf_orig_completion_filter() {

[bash-completion] Retain original completion options (#288)Junegunn Choibefore adoption486b87d

lines 34–35why, one step back
34 sed 's/^\(.*-F\) *\([^ ]*\).* \([^ ]*\)$/export _fzf_orig_completion_\3="\1 %s \3 #\2";/' |
35 awk -F= '{gsub(/[^a-z0-9_= ;]/, "_", $1); print $1"="$2}'

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 36–44why, one step back
36}
3738_fzf_opts_completion() {39 local cur prev opts40 COMPREPLY=()41 cur="${COMP_WORDS[COMP_CWORD]}"42 prev="${COMP_WORDS[COMP_CWORD-1]}"43 opts="44 -x --extended

Make --extended defaultJunegunn Choibefore adoption81a8869

line 45why, one step back
45 -e --exact

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 46–68why, one step back
46 -i +i
47 -n --nth48 -d --delimiter49 +s --no-sort50 --tac51 --tiebreak52 --bind53 -m --multi54 --no-mouse55 --color56 --black57 --reverse58 --no-hscroll59 --inline-info60 --prompt61 -q --query62 -1 --select-163 -0 --exit-064 -f --filter65 --print-query66 --expect67 --toggle-sort68 --sync

0.10.0Junegunn Choibefore adoptiona336494

line 69why, one step back
69 --cycle

More alternative notations for execute actionJunegunn Choibefore adoption022435a

line 70why, one step back
70 --history

[bash] Update fzf option completionJunegunn Choibefore adoption51d84b1

line 71why, one step back
71 --history-size

Replace --header-file with --header (#346)Junegunn Choibefore adoption2022a3a

line 72why, one step back
72 --header

Add --margin optionJunegunn Choibefore adoptionee0c8a2

lines 73–74why, one step back
73 --header-lines
74 --margin"

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 75–77why, one step back
75
76 case "${prev}" in77 --tiebreak)

[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3

line 78why, one step back
78 COMPREPLY=( $(compgen -W "length begin end index" -- "$cur") )

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 79–81why, one step back
79 return 0
80 ;;81 --color)

[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3

line 82why, one step back
82 COMPREPLY=( $(compgen -W "dark light 16 bw" -- "$cur") )

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 83–84why, one step back
83 return 0
84 ;;

Replace --header-file with --header (#346)Junegunn Choibefore adoption2022a3a

line 85why, one step back
85 --history)

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 86–90why, one step back
86 COMPREPLY=()
87 return 088 ;;89 esac90

[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3

lines 91–92why, one step back
91 if [[ "$cur" =~ ^-|\+ ]]; then
92 COMPREPLY=( $(compgen -W "${opts}" -- "$cur") )

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 93–99why, one step back
93 return 0
94 fi9596 return 097}9899_fzf_handle_dynamic_completion() {

[bash-completion] Retain original completion options (#288)Junegunn Choibefore adoption486b87d

line 100why, one step back
100 local cmd orig_var orig ret orig_cmd

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 101–102why, one step back
101 cmd="$1"
102 shift

Merge pull request #285 from evverx/possible-retry-loopJunegunn Choibefore adoptionae72b0f

line 103why, one step back
103 orig_cmd="$1"

[bash-completion] Retain original completion options (#288)Junegunn Choibefore adoption486b87d

lines 104–105why, one step back
104 orig_var="_fzf_orig_completion_$cmd"
105 orig="${!orig_var##*#}"

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 106–110why, one step back
106 if [ -n "$orig" ] && type "$orig" > /dev/null 2>&1; then
107 $orig "$@"108 elif [ -n "$_fzf_completion_loader" ]; then109 _completion_loader "$@"110 ret=$?

[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3

lines 111–112why, one step back
111 eval "$(complete | \grep "\-F.* $orig_cmd$" | _fzf_orig_completion_filter)"
112 source "${BASH_SOURCE[0]}"

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 113–116why, one step back
113 return $ret
114 fi115}116

[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9

line 117why, one step back
117__fzf_generic_path_completion() {

More alternative notations for execute actionJunegunn Choibefore adoption022435a

line 118why, one step back
118 local cur base dir leftover matches trigger cmd fzf

[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3

lines 119–120why, one step back
119 [ "${FZF_TMUX:-1}" != 0 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
120 cmd=$(echo "${COMP_WORDS[0]}" | sed 's/[^a-z0-9_=]/_/g')

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 121–123why, one step back
121 COMPREPLY=()
122 trigger=${FZF_COMPLETION_TRIGGER-'**'}123 cur="${COMP_WORDS[COMP_CWORD]}"

[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3

line 124why, one step back
124 if [[ "$cur" == *"$trigger" ]]; then

More alternative notations for execute actionJunegunn Choibefore adoption022435a

line 125why, one step back
125 base=${cur:0:${#cur}-${#trigger}}

[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3

line 126why, one step back
126 eval "base=$base"

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 127–128why, one step back
127
128 dir="$base"

[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3

lines 129–130why, one step back
129 while true; do
130 if [ -z "$dir" ] || [ -d "$dir" ]; then

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 131–132why, one step back
131 leftover=${base/#"$dir"}
132 leftover=${leftover/#\/}

Merge pull request #458 from frizinak/fix-autocomplete-absJunegunn Choibefore adoptiona9aa263

lines 133–134why, one step back
133 [ -z "$dir" ] && dir='.'
134 [ "$dir" != "/" ] && dir="${dir/%\//}"

More alternative notations for execute actionJunegunn Choibefore adoption022435a

line 135why, one step back
135 tput sc

[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3

line 136why, one step back
136 matches=$(eval "$1 $(printf %q "$dir")" | $fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read -r item; do

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 137–158why, one step back
137 printf "%q$3 " "$item"
138 done)139 matches=${matches% }140 if [ -n "$matches" ]; then141 COMPREPLY=( "$matches" )142 else143 COMPREPLY=( "$cur" )144 fi145 tput rc146 return 0147 fi148 dir=$(dirname "$dir")149 [[ "$dir" =~ /$ ]] || dir="$dir"/150 done151 else152 shift153 shift154 shift155 _fzf_handle_dynamic_completion "$cmd" "$@"156 fi157}158

[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9

line 159why, one step back
159_fzf_complete() {

[completion] _fzf_complete_COMMAND_post for post processingJunegunn Choibefore adoption8206746

lines 160–161why, one step back
160 local cur selected trigger cmd fzf post
161 post="$(caller 0 | awk '{print $2}')_post"

[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3

lines 162–163why, one step back
162 type -t "$post" > /dev/null 2>&1 || post=cat
163 [ "${FZF_TMUX:-1}" != 0 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"

[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9

line 164why, one step back
164

[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3

line 165why, one step back
165 cmd=$(echo "${COMP_WORDS[0]}" | sed 's/[^a-z0-9_=]/_/g')

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 166–167why, one step back
166 trigger=${FZF_COMPLETION_TRIGGER-'**'}
167 cur="${COMP_WORDS[COMP_CWORD]}"

[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3

line 168why, one step back
168 if [[ "$cur" == *"$trigger" ]]; then

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 169–171why, one step back
169 cur=${cur:0:${#cur}-${#trigger}}
170171 tput sc

[completion] _fzf_complete_COMMAND_post for post processingJunegunn Choibefore adoption8206746

line 172why, one step back
172 selected=$(cat | $fzf $FZF_COMPLETION_OPTS $1 -q "$cur" | $post | tr '\n' ' ')

[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9

line 173why, one step back
173 selected=${selected% } # Strip trailing space not to repeat "-o nospace"

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 174–185why, one step back
174 tput rc
175176 if [ -n "$selected" ]; then177 COMPREPLY=("$selected")178 return 0179 fi180 else181 shift182 _fzf_handle_dynamic_completion "$cmd" "$@"183 fi184}185

[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9

line 186why, one step back
186_fzf_path_completion() {

Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647

line 187why, one step back
187 __fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@"

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 188–189why, one step back
188}
189

Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647

line 190why, one step back
190# Deprecated. No file only completion.

More alternative notations for execute actionJunegunn Choibefore adoption022435a

line 191why, one step back
191_fzf_file_completion() {

Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647

line 192why, one step back
192 _fzf_path_completion "$@"

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 193–195why, one step back
193}
194195_fzf_dir_completion() {

Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647

line 196why, one step back
196 __fzf_generic_path_completion _fzf_compgen_dir "" "/" "$@"

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 197–198why, one step back
197}
198

[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9

line 199why, one step back
199_fzf_complete_kill() {

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 200–202why, one step back
200 [ -n "${COMP_WORDS[COMP_CWORD]}" ] && return 1
201202 local selected fzf

[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3

line 203why, one step back
203 [ "${FZF_TMUX:-1}" != 0 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 204–213why, one step back
204 tput sc
205 selected=$(ps -ef | sed 1d | $fzf -m $FZF_COMPLETION_OPTS | awk '{print $2}' | tr '\n' ' ')206 tput rc207208 if [ -n "$selected" ]; then209 COMPREPLY=( "$selected" )210 return 0211 fi212}213

[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9

lines 214–218why, one step back
214_fzf_complete_telnet() {
215 _fzf_complete '+m' "$@" < <(216 \grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0' |217 awk '{if (length($2) > 0) {print $2}}' | sort -u218 )

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 219–220why, one step back
219}
220

[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9

lines 221–226why, one step back
221_fzf_complete_ssh() {
222 _fzf_complete '+m' "$@" < <(223 cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | \grep -i '^host' | \grep -v '*') \224 <(\grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0') |225 awk '{if (length($2) > 0) {print $2}}' | sort -u226 )

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 227–228why, one step back
227}
228

[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9

lines 229–230why, one step back
229_fzf_complete_unset() {
230 _fzf_complete '-m' "$@" < <(

[zsh-completion] Allow custom completion functionJunegunn Choibefore adoption8fa9e85

line 231why, one step back
231 declare -xp | sed 's/=.*//' | sed 's/.* //'

[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9

line 232why, one step back
232 )

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 233–234why, one step back
233}
234

[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9

lines 235–242why, one step back
235_fzf_complete_export() {
236 _fzf_complete '-m' "$@" < <(237 declare -xp | sed 's/=.*//' | sed 's/.* //'238 )239}240241_fzf_complete_unalias() {242 _fzf_complete '-m' "$@" < <(

[zsh-completion] Allow custom completion functionJunegunn Choibefore adoption8fa9e85

line 243why, one step back
243 alias | sed 's/=.*//' | sed 's/.* //'

[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9

line 244why, one step back
244 )

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 245–249why, one step back
245}
246247# fzf options248complete -o default -F _fzf_opts_completion fzf249

Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647

lines 250–251why, one step back
250d_cmds="${FZF_COMPLETION_DIR_COMMANDS:-cd pushd rmdir}"
251a_cmds="

More alternative notations for execute actionJunegunn Choibefore adoption022435a

line 252why, one step back
252 awk cat diff diff3

[bash-completion] Fix #417 - Update command listJunegunn Choibefore adoption57a37b5

line 253why, one step back
253 emacs emacsclient ex file ftp g++ gcc gvim head hg java

Merge pull request #409 from freitass/masterJunegunn Choibefore adoption15659ac

line 254why, one step back
254 javac ld less more mvim nvim patch perl python ruby

Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647

line 255why, one step back
255 sed sftp sort source tail tee uniq vi view vim wc xdg-open

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 256–262why, one step back
256 basename bunzip2 bzip2 chmod chown curl cp dirname du
257 find git grep gunzip gzip hg jar258 ln ls mv open rm rsync scp259 svn tar unzip zip"260x_cmds="kill ssh telnet unset unalias export"261262# Preserve existing completion

0.11.3Junegunn Choibefore adoption40d934e

line 263why, one step back
263if [ "$_fzf_completion_loaded" != '0.11.3' ]; then

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 264–265why, one step back
264 # Really wish I could use associative array but OSX comes with bash 3.2 :(
265 eval $(complete | \grep '\-F' | \grep -v _fzf_ |

Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647

line 266why, one step back
266 \grep -E " ($(echo $d_cmds $a_cmds $x_cmds | sed 's/ /|/g' | sed 's/+/\\+/g'))$" | _fzf_orig_completion_filter)

0.11.3Junegunn Choibefore adoption40d934e

line 267why, one step back
267 export _fzf_completion_loaded=0.11.3

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 268–273why, one step back
268fi
269270if type _completion_loader > /dev/null 2>&1; then271 _fzf_completion_loader=1272fi273

[bash-completion] Retain original completion options (#288)Junegunn Choibefore adoption486b87d

lines 274–287why, one step back
274_fzf_defc() {
275 local cmd func opts orig_var orig276 cmd="$1"277 func="$2"278 opts="$3"279 orig_var="_fzf_orig_completion_$cmd"280 orig="${!orig_var}"281 if [ -n "$orig" ]; then282 eval "$(printf "$orig" "$func")"283 else284 complete -F "$func" $opts "$cmd"285 fi286}287

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 288–289why, one step back
288# Anything
289for cmd in $a_cmds; do

[bash-completion] Retain original completion options (#288)Junegunn Choibefore adoption486b87d

line 290why, one step back
290 _fzf_defc "$cmd" _fzf_path_completion "-o default -o bashdefault"

More alternative notations for execute actionJunegunn Choibefore adoption022435a

line 291why, one step back
291done

[bash-completion] Retain original completion options (#288)Junegunn Choibefore adoption486b87d

line 292why, one step back
292

Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647

lines 293–297why, one step back
293# Directory
294for cmd in $d_cmds; do295 _fzf_defc "$cmd" _fzf_dir_completion "-o nospace -o plusdirs"296done297

[bash-completion] Retain original completion options (#288)Junegunn Choibefore adoption486b87d

line 298why, one step back
298unset _fzf_defc

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 299–300why, one step back
299
300# Kill completion

[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9

line 301why, one step back
301complete -F _fzf_complete_kill -o nospace -o default -o bashdefault kill

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 302–303why, one step back
302
303# Host completion

[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9

lines 304–305why, one step back
304complete -F _fzf_complete_ssh -o default -o bashdefault ssh
305complete -F _fzf_complete_telnet -o default -o bashdefault telnet

More alternative notations for execute actionJunegunn Choibefore adoption022435a

lines 306–307why, one step back
306
307# Environment variables / Aliases

[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9

lines 308–310why, one step back
308complete -F _fzf_complete_unset -o default -o bashdefault unset
309complete -F _fzf_complete_export -o default -o bashdefault export310complete -F _fzf_complete_unalias -o default -o bashdefault unalias

More alternative notations for execute actionJunegunn Choibefore adoption022435a

line 311why, one step back
311

Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647

line 312why, one step back
312unset cmd d_cmds a_cmds x_cmds