Skip to content
Myr

completion.bash

This file

Path

shell/completion.bash

314 lines · 8.0 KiB · Shell

Last changed by

Merge pull request #670 from maverickwoo/fix-668Junegunn Choibefore adoption3bf51d8

History of this file

Take it

The walk stopped after 200 commits: lines older than 24f3ec7 point at it.

Fix FZF_CTRL_R_OPTS for zsh (#526)Junegunn Choibefore adoption24f3ec7

lines 1–16why, 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)1213# 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"

[shell] Suppress alias/function expansionJunegunn Choibefore adoption6081eac

line 17why, one step back
17 command find -L "$1" \

Fix FZF_CTRL_R_OPTS for zsh (#526)Junegunn Choibefore adoption24f3ec7

lines 18–24why, one step back
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() {

[shell] Suppress alias/function expansionJunegunn Choibefore adoption6081eac

line 25why, one step back
25 command find -L "$1" \

Fix FZF_CTRL_R_OPTS for zsh (#526)Junegunn Choibefore adoption24f3ec7

lines 26–34why, one step back
26 -name .git -prune -o -name .svn -prune -o -type d \
27 -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'28 }29fi3031###########################################################3233_fzf_orig_completion_filter() {34 sed 's/^\(.*-F\) *\([^ ]*\).* \([^ ]*\)$/export _fzf_orig_completion_\3="\1 %s \3 #\2";/' |

Merge pull request #670 from maverickwoo/fix-668Junegunn Choibefore adoption3bf51d8

line 35why, one step back
35 awk -F= '{gsub(/[^A-Za-z0-9_= ;]/, "_", $1); print $1"="$2}'

Fix FZF_CTRL_R_OPTS for zsh (#526)Junegunn Choibefore adoption24f3ec7

lines 36–110why, 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 --extended45 -e --exact46 -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 --sync69 --cycle70 --history71 --history-size72 --header73 --header-lines74 --margin"7576 case "${prev}" in77 --tiebreak)78 COMPREPLY=( $(compgen -W "length begin end index" -- "$cur") )79 return 080 ;;81 --color)82 COMPREPLY=( $(compgen -W "dark light 16 bw" -- "$cur") )83 return 084 ;;85 --history)86 COMPREPLY=()87 return 088 ;;89 esac9091 if [[ "$cur" =~ ^-|\+ ]]; then92 COMPREPLY=( $(compgen -W "${opts}" -- "$cur") )93 return 094 fi9596 return 097}9899_fzf_handle_dynamic_completion() {100 local cmd orig_var orig ret orig_cmd101 cmd="$1"102 shift103 orig_cmd="$1"104 orig_var="_fzf_orig_completion_$cmd"105 orig="${!orig_var##*#}"106 if [ -n "$orig" ] && type "$orig" > /dev/null 2>&1; then107 $orig "$@"108 elif [ -n "$_fzf_completion_loader" ]; then109 _completion_loader "$@"110 ret=$?

[shell] Suppress alias/function expansionJunegunn Choibefore adoption6081eac

line 111why, one step back
111 eval "$(complete | command grep "\-F.* $orig_cmd$" | _fzf_orig_completion_filter)"

Fix FZF_CTRL_R_OPTS for zsh (#526)Junegunn Choibefore adoption24f3ec7

lines 112–119why, one step back
112 source "${BASH_SOURCE[0]}"
113 return $ret114 fi115}116117__fzf_generic_path_completion() {118 local cur base dir leftover matches trigger cmd fzf119 [ "${FZF_TMUX:-1}" != 0 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"

Merge pull request #670 from maverickwoo/fix-668Junegunn Choibefore adoption3bf51d8

line 120why, one step back
120 cmd="${COMP_WORDS[0]//[^A-Za-z0-9_=]/_}"

Fix FZF_CTRL_R_OPTS for zsh (#526)Junegunn Choibefore adoption24f3ec7

lines 121–164why, one step back
121 COMPREPLY=()
122 trigger=${FZF_COMPLETION_TRIGGER-'**'}123 cur="${COMP_WORDS[COMP_CWORD]}"124 if [[ "$cur" == *"$trigger" ]]; then125 base=${cur:0:${#cur}-${#trigger}}126 eval "base=$base"127128 dir="$base"129 while true; do130 if [ -z "$dir" ] || [ -d "$dir" ]; then131 leftover=${base/#"$dir"}132 leftover=${leftover/#\/}133 [ -z "$dir" ] && dir='.'134 [ "$dir" != "/" ] && dir="${dir/%\//}"135 tput sc136 matches=$(eval "$1 $(printf %q "$dir")" | $fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read -r item; do137 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}158159_fzf_complete() {160 local cur selected trigger cmd fzf post161 post="$(caller 0 | awk '{print $2}')_post"162 type -t "$post" > /dev/null 2>&1 || post=cat163 [ "${FZF_TMUX:-1}" != 0 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"164

Merge pull request #670 from maverickwoo/fix-668Junegunn Choibefore adoption3bf51d8

line 165why, one step back
165 cmd="${COMP_WORDS[0]//[^A-Za-z0-9_=]/_}"

Fix FZF_CTRL_R_OPTS for zsh (#526)Junegunn Choibefore adoption24f3ec7

lines 166–215why, one step back
166 trigger=${FZF_COMPLETION_TRIGGER-'**'}
167 cur="${COMP_WORDS[COMP_CWORD]}"168 if [[ "$cur" == *"$trigger" ]]; then169 cur=${cur:0:${#cur}-${#trigger}}170171 tput sc172 selected=$(cat | $fzf $FZF_COMPLETION_OPTS $1 -q "$cur" | $post | tr '\n' ' ')173 selected=${selected% } # Strip trailing space not to repeat "-o nospace"174 tput rc175176 if [ -n "$selected" ]; then177 COMPREPLY=("$selected")178 return 0179 fi180 else181 shift182 _fzf_handle_dynamic_completion "$cmd" "$@"183 fi184}185186_fzf_path_completion() {187 __fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@"188}189190# Deprecated. No file only completion.191_fzf_file_completion() {192 _fzf_path_completion "$@"193}194195_fzf_dir_completion() {196 __fzf_generic_path_completion _fzf_compgen_dir "" "/" "$@"197}198199_fzf_complete_kill() {200 [ -n "${COMP_WORDS[COMP_CWORD]}" ] && return 1201202 local selected fzf203 [ "${FZF_TMUX:-1}" != 0 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"204 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}213214_fzf_complete_telnet() {215 _fzf_complete '+m' "$@" < <(

[shell] Suppress alias/function expansionJunegunn Choibefore adoption6081eac

line 216why, one step back
216 command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0' |

Fix FZF_CTRL_R_OPTS for zsh (#526)Junegunn Choibefore adoption24f3ec7

lines 217–222why, one step back
217 awk '{if (length($2) > 0) {print $2}}' | sort -u
218 )219}220221_fzf_complete_ssh() {222 _fzf_complete '+m' "$@" < <(

[shell] Suppress alias/function expansionJunegunn Choibefore adoption6081eac

lines 223–225why, one step back
223 cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | command grep -i '^host' | command grep -v '*') \
224 <(command grep -oE '^[^ ]+' ~/.ssh/known_hosts | tr ',' '\n' | awk '{ print $1 " " $1 }') \225 <(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') |

Fix FZF_CTRL_R_OPTS for zsh (#526)Junegunn Choibefore adoption24f3ec7

lines 226–265why, one step back
226 awk '{if (length($2) > 0) {print $2}}' | sort -u
227 )228}229230_fzf_complete_unset() {231 _fzf_complete '-m' "$@" < <(232 declare -xp | sed 's/=.*//' | sed 's/.* //'233 )234}235236_fzf_complete_export() {237 _fzf_complete '-m' "$@" < <(238 declare -xp | sed 's/=.*//' | sed 's/.* //'239 )240}241242_fzf_complete_unalias() {243 _fzf_complete '-m' "$@" < <(244 alias | sed 's/=.*//' | sed 's/.* //'245 )246}247248# fzf options249complete -o default -F _fzf_opts_completion fzf250251d_cmds="${FZF_COMPLETION_DIR_COMMANDS:-cd pushd rmdir}"252a_cmds="253 awk cat diff diff3254 emacs emacsclient ex file ftp g++ gcc gvim head hg java255 javac ld less more mvim nvim patch perl python ruby256 sed sftp sort source tail tee uniq vi view vim wc xdg-open257 basename bunzip2 bzip2 chmod chown curl cp dirname du258 find git grep gunzip gzip hg jar259 ln ls mv open rm rsync scp260 svn tar unzip zip"261x_cmds="kill ssh telnet unset unalias export"262263# Preserve existing completion264if [ "$_fzf_completion_loaded" != '0.11.3' ]; then265 # Really wish I could use associative array but OSX comes with bash 3.2 :(

[shell] Suppress alias/function expansionJunegunn Choibefore adoption6081eac

lines 266–267why, one step back
266 eval $(complete | command grep '\-F' | command grep -v _fzf_ |
267 command grep -E " ($(echo $d_cmds $a_cmds $x_cmds | sed 's/ /|/g' | sed 's/+/\\+/g'))$" | _fzf_orig_completion_filter)

Fix FZF_CTRL_R_OPTS for zsh (#526)Junegunn Choibefore adoption24f3ec7

lines 268–275why, one step back
268 export _fzf_completion_loaded=0.11.3
269fi270271if type _completion_loader > /dev/null 2>&1; then272 _fzf_completion_loader=1273fi274275_fzf_defc() {

[bash] Update completion.bashJunegunn Choibefore adoptionc3aa836

line 276why, one step back
276 local cmd func opts orig_var orig def

Fix FZF_CTRL_R_OPTS for zsh (#526)Junegunn Choibefore adoption24f3ec7

lines 277–279why, one step back
277 cmd="$1"
278 func="$2"279 opts="$3"

Merge pull request #670 from maverickwoo/fix-668Junegunn Choibefore adoption3bf51d8

line 280why, one step back
280 orig_var="_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}"

Fix FZF_CTRL_R_OPTS for zsh (#526)Junegunn Choibefore adoption24f3ec7

lines 281–282why, one step back
281 orig="${!orig_var}"
282 if [ -n "$orig" ]; then

[bash] Update completion.bashJunegunn Choibefore adoptionc3aa836

lines 283–284why, one step back
283 printf -v def "$orig" "$func"
284 eval "$def"

Fix FZF_CTRL_R_OPTS for zsh (#526)Junegunn Choibefore adoption24f3ec7

lines 285–314why, one step back
285 else
286 complete -F "$func" $opts "$cmd"287 fi288}289290# Anything291for cmd in $a_cmds; do292 _fzf_defc "$cmd" _fzf_path_completion "-o default -o bashdefault"293done294295# Directory296for cmd in $d_cmds; do297 _fzf_defc "$cmd" _fzf_dir_completion "-o nospace -o plusdirs"298done299300unset _fzf_defc301302# Kill completion303complete -F _fzf_complete_kill -o nospace -o default -o bashdefault kill304305# Host completion306complete -F _fzf_complete_ssh -o default -o bashdefault ssh307complete -F _fzf_complete_telnet -o default -o bashdefault telnet308309# Environment variables / Aliases310complete -F _fzf_complete_unset -o default -o bashdefault unset311complete -F _fzf_complete_export -o default -o bashdefault export312complete -F _fzf_complete_unalias -o default -o bashdefault unalias313314unset cmd d_cmds a_cmds x_cmds