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 fileTake 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 back1#!/bin/bash2# ____ ____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)12Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647
lines 13–32why, one step back13# 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###########################################################32More alternative notations for execute actionJunegunn Choibefore adoption022435a
line 33why, one step back33_fzf_orig_completion_filter() {[bash-completion] Retain original completion options (#288)Junegunn Choibefore adoption486b87d
lines 34–35why, one step back34 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 back36}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 --extendedMake --extended defaultJunegunn Choibefore adoption81a8869
line 45why, one step back45 -e --exactMore alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 46–68why, one step back46 -i +i47 -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 --sync0.10.0Junegunn Choibefore adoptiona336494
line 69why, one step back69 --cycleMore alternative notations for execute actionJunegunn Choibefore adoption022435a
line 70why, one step back70 --history[bash] Update fzf option completionJunegunn Choibefore adoption51d84b1
line 71why, one step back71 --history-sizeReplace --header-file with --header (#346)Junegunn Choibefore adoption2022a3a
line 72why, one step back72 --headerAdd --margin optionJunegunn Choibefore adoptionee0c8a2
lines 73–74why, one step back73 --header-lines74 --margin"More alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 75–77why, one step back7576 case "${prev}" in77 --tiebreak)[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3
line 78why, one step back78 COMPREPLY=( $(compgen -W "length begin end index" -- "$cur") )More alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 79–81why, one step back79 return 080 ;;81 --color)[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3
line 82why, one step back82 COMPREPLY=( $(compgen -W "dark light 16 bw" -- "$cur") )More alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 83–84why, one step back83 return 084 ;;Replace --header-file with --header (#346)Junegunn Choibefore adoption2022a3a
line 85why, one step back85 --history)More alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 86–90why, one step back86 COMPREPLY=()87 return 088 ;;89 esac90[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3
lines 91–92why, one step back91 if [[ "$cur" =~ ^-|\+ ]]; then92 COMPREPLY=( $(compgen -W "${opts}" -- "$cur") )More alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 93–99why, one step back93 return 094 fi9596 return 097}9899_fzf_handle_dynamic_completion() {[bash-completion] Retain original completion options (#288)Junegunn Choibefore adoption486b87d
line 100why, one step back100 local cmd orig_var orig ret orig_cmdMore alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 101–102why, one step back101 cmd="$1"102 shiftMerge pull request #285 from evverx/possible-retry-loopJunegunn Choibefore adoptionae72b0f
line 103why, one step back103 orig_cmd="$1"[bash-completion] Retain original completion options (#288)Junegunn Choibefore adoption486b87d
lines 104–105why, one step back104 orig_var="_fzf_orig_completion_$cmd"105 orig="${!orig_var##*#}"More alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 106–110why, one step back106 if [ -n "$orig" ] && type "$orig" > /dev/null 2>&1; then107 $orig "$@"108 elif [ -n "$_fzf_completion_loader" ]; then109 _completion_loader "$@"110 ret=$?[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3
lines 111–112why, one step back111 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 back113 return $ret114 fi115}116[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9
line 117why, one step back117__fzf_generic_path_completion() {More alternative notations for execute actionJunegunn Choibefore adoption022435a
line 118why, one step back118 local cur base dir leftover matches trigger cmd fzf[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3
lines 119–120why, one step back119 [ "${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 back121 COMPREPLY=()122 trigger=${FZF_COMPLETION_TRIGGER-'**'}123 cur="${COMP_WORDS[COMP_CWORD]}"[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3
line 124why, one step back124 if [[ "$cur" == *"$trigger" ]]; thenMore alternative notations for execute actionJunegunn Choibefore adoption022435a
line 125why, one step back125 base=${cur:0:${#cur}-${#trigger}}[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3
line 126why, one step back126 eval "base=$base"More alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 127–128why, one step back127128 dir="$base"[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3
lines 129–130why, one step back129 while true; do130 if [ -z "$dir" ] || [ -d "$dir" ]; thenMore alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 131–132why, one step back131 leftover=${base/#"$dir"}132 leftover=${leftover/#\/}Merge pull request #458 from frizinak/fix-autocomplete-absJunegunn Choibefore adoptiona9aa263
lines 133–134why, one step back133 [ -z "$dir" ] && dir='.'134 [ "$dir" != "/" ] && dir="${dir/%\//}"More alternative notations for execute actionJunegunn Choibefore adoption022435a
line 135why, one step back135 tput sc[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3
line 136why, one step back136 matches=$(eval "$1 $(printf %q "$dir")" | $fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read -r item; doMore alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 137–158why, one step back137 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 back159_fzf_complete() {[completion] _fzf_complete_COMMAND_post for post processingJunegunn Choibefore adoption8206746
lines 160–161why, one step back160 local cur selected trigger cmd fzf post161 post="$(caller 0 | awk '{print $2}')_post"[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3
lines 162–163why, one step back162 type -t "$post" > /dev/null 2>&1 || post=cat163 [ "${FZF_TMUX:-1}" != 0 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9
line 164why, one step back164[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3
line 165why, one step back165 cmd=$(echo "${COMP_WORDS[0]}" | sed 's/[^a-z0-9_=]/_/g')More alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 166–167why, one step back166 trigger=${FZF_COMPLETION_TRIGGER-'**'}167 cur="${COMP_WORDS[COMP_CWORD]}"[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3
line 168why, one step back168 if [[ "$cur" == *"$trigger" ]]; thenMore alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 169–171why, one step back169 cur=${cur:0:${#cur}-${#trigger}}170171 tput sc[completion] _fzf_complete_COMMAND_post for post processingJunegunn Choibefore adoption8206746
line 172why, one step back172 selected=$(cat | $fzf $FZF_COMPLETION_OPTS $1 -q "$cur" | $post | tr '\n' ' ')[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9
line 173why, one step back173 selected=${selected% } # Strip trailing space not to repeat "-o nospace"More alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 174–185why, one step back174 tput rc175176 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 back186_fzf_path_completion() {Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647
line 187why, one step back187 __fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@"More alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 188–189why, one step back188}189Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647
line 190why, one step back190# Deprecated. No file only completion.More alternative notations for execute actionJunegunn Choibefore adoption022435a
line 191why, one step back191_fzf_file_completion() {Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647
line 192why, one step back192 _fzf_path_completion "$@"More alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 193–195why, one step back193}194195_fzf_dir_completion() {Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647
line 196why, one step back196 __fzf_generic_path_completion _fzf_compgen_dir "" "/" "$@"More alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 197–198why, one step back197}198[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9
line 199why, one step back199_fzf_complete_kill() {More alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 200–202why, one step back200 [ -n "${COMP_WORDS[COMP_CWORD]}" ] && return 1201202 local selected fzf[bash] Fix shellcheck warningsJunegunn Choibefore adoption09a2ab3
line 203why, one step back203 [ "${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 back204 tput sc205 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 back214_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 back219}220[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9
lines 221–226why, one step back221_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 back227}228[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9
lines 229–230why, one step back229_fzf_complete_unset() {230 _fzf_complete '-m' "$@" < <([zsh-completion] Allow custom completion functionJunegunn Choibefore adoption8fa9e85
line 231why, one step back231 declare -xp | sed 's/=.*//' | sed 's/.* //'[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9
line 232why, one step back232 )More alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 233–234why, one step back233}234[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9
lines 235–242why, one step back235_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 back243 alias | sed 's/=.*//' | sed 's/.* //'[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9
line 244why, one step back244 )More alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 245–249why, one step back245}246247# fzf options248complete -o default -F _fzf_opts_completion fzf249Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647
lines 250–251why, one step back250d_cmds="${FZF_COMPLETION_DIR_COMMANDS:-cd pushd rmdir}"251a_cmds="More alternative notations for execute actionJunegunn Choibefore adoption022435a
line 252why, one step back252 awk cat diff diff3[bash-completion] Fix #417 - Update command listJunegunn Choibefore adoption57a37b5
line 253why, one step back253 emacs emacsclient ex file ftp g++ gcc gvim head hg javaMerge pull request #409 from freitass/masterJunegunn Choibefore adoption15659ac
line 254why, one step back254 javac ld less more mvim nvim patch perl python rubyMake fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647
line 255why, one step back255 sed sftp sort source tail tee uniq vi view vim wc xdg-openMore alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 256–262why, one step back256 basename bunzip2 bzip2 chmod chown curl cp dirname du257 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 completion0.11.3Junegunn Choibefore adoption40d934e
line 263why, one step back263if [ "$_fzf_completion_loaded" != '0.11.3' ]; thenMore alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 264–265why, one step back264 # 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 back266 \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 back267 export _fzf_completion_loaded=0.11.3More alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 268–273why, one step back268fi269270if 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 back274_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}287More alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 288–289why, one step back288# Anything289for cmd in $a_cmds; do[bash-completion] Retain original completion options (#288)Junegunn Choibefore adoption486b87d
line 290why, one step back290 _fzf_defc "$cmd" _fzf_path_completion "-o default -o bashdefault"More alternative notations for execute actionJunegunn Choibefore adoption022435a
line 291why, one step back291done[bash-completion] Retain original completion options (#288)Junegunn Choibefore adoption486b87d
line 292why, one step back292Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647
lines 293–297why, one step back293# Directory294for 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 back298unset _fzf_defcMore alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 299–300why, one step back299300# Kill completion[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9
line 301why, one step back301complete -F _fzf_complete_kill -o nospace -o default -o bashdefault killMore alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 302–303why, one step back302303# Host completion[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9
lines 304–305why, one step back304complete -F _fzf_complete_ssh -o default -o bashdefault ssh305complete -F _fzf_complete_telnet -o default -o bashdefault telnetMore alternative notations for execute actionJunegunn Choibefore adoption022435a
lines 306–307why, one step back306307# Environment variables / Aliases[completion] Revamp completion APIJunegunn Choibefore adoptioneee45a9
lines 308–310why, one step back308complete -F _fzf_complete_unset -o default -o bashdefault unset309complete -F _fzf_complete_export -o default -o bashdefault export310complete -F _fzf_complete_unalias -o default -o bashdefault unaliasMore alternative notations for execute actionJunegunn Choibefore adoption022435a
line 311why, one step back311Make fuzzy completion customizable with _fzf_compgen_{path,dir}Junegunn Choibefore adoption9617647
line 312why, one step back312unset cmd d_cmds a_cmds x_cmds