completion.bash
This file
Path
shell/completion.bash
272 lines · 6.8 KiB · Shell
Last changed by
Merge pull request #285 from evverx/possible-retry-loopJunegunn Choibefore adoptionae72b0f
History of this fileTake it
The walk stopped after 200 commits: lines older than eb8fef0 point at it.
Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 1–7why, one step back1#!/bin/bash2# ____ ____3# / __/___ / __/4# / /_/_ / / /_5# / __/ / /_/ __/6# /_/ /___/_/-completion.bash7#FZF_TMUX and FZF_TMUX_HEIGHT for fuzzy completionJunegunn Choibefore adoption3ec83ba
lines 8–9why, one step back8# - $FZF_TMUX (default: 1)9# - $FZF_TMUX_HEIGHT (default: '40%')Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 10–18why, one step back10# - $FZF_COMPLETION_TRIGGER (default: '**')11# - $FZF_COMPLETION_OPTS (default: empty)1213_fzf_orig_completion_filter() {14 sed 's/.*-F *\([^ ]*\).* \([^ ]*\)$/export _fzf_orig_completion_\2=\1;/' |15 sed 's/[^a-z0-9_= ;]/_/g'16}1718_fzf_opts_completion() {Prepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c
line 19why, one step back19 local cur prev optsAdd man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 20–21why, one step back20 COMPREPLY=()21 cur="${COMP_WORDS[COMP_CWORD]}"Prepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c
line 22why, one step back22 prev="${COMP_WORDS[COMP_CWORD-1]}"Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 23–30why, one step back23 opts="24 -x --extended25 -e --extended-exact26 -i +i27 -n --nth28 -d --delimiter29 +s --no-sort30 --tacPrepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c
line 31why, one step back31 --tiebreak0.9.12Junegunn Choibefore adoption34946b7
line 32why, one step back32 --bindAdd man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 33–34why, one step back33 -m --multi34 --no-mouseUpdate completion for fzf itselfJunegunn Choibefore adoption22ae7ad
line 35why, one step back35 --colorAdd man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 36–37why, one step back36 --black37 --reversePrepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c
line 38why, one step back38 --no-hscrollUpdate completion for fzf itselfJunegunn Choibefore adoption22ae7ad
line 39why, one step back39 --inline-infoAdd man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 40–45why, one step back40 --prompt41 -q --query42 -1 --select-143 -0 --exit-044 -f --filter45 --print-queryPrepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c
lines 46–47why, one step back46 --expect47 --toggle-sortAdd support for search historyJunegunn Choibefore adoption3b52811
line 48why, one step back48 --sync0.10.0Junegunn Choibefore adoptiona336494
line 49why, one step back49 --cycleAdd support for search historyJunegunn Choibefore adoption3b52811
line 50why, one step back50 --history0.10.0Junegunn Choibefore adoptiona336494
line 51why, one step back51 --history-size"Prepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c
lines 52–55why, one step back5253 case "${prev}" in54 --tiebreak)55 COMPREPLY=( $(compgen -W "length begin end index" -- ${cur}) )Update completion for fzf itselfJunegunn Choibefore adoption22ae7ad
lines 56–59why, one step back56 return 057 ;;58 --color)59 COMPREPLY=( $(compgen -W "dark light 16 bw" -- ${cur}) )Prepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c
lines 60–61why, one step back60 return 061 ;;Add support for search historyJunegunn Choibefore adoption3b52811
lines 62–65why, one step back62 --history)63 COMPREPLY=()64 return 065 ;;Prepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c
line 66why, one step back66 esacAdd man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 67–76why, one step back6768 if [[ ${cur} =~ ^-|\+ ]]; then69 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )70 return 071 fi7273 return 074}7576_fzf_handle_dynamic_completion() {Merge pull request #285 from evverx/possible-retry-loopJunegunn Choibefore adoptionae72b0f
line 77why, one step back77 local cmd orig ret orig_cmdAdd man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 78–79why, one step back78 cmd="$1"79 shiftMerge pull request #285 from evverx/possible-retry-loopJunegunn Choibefore adoptionae72b0f
line 80why, one step back80 orig_cmd="$1"Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 81–87why, one step back8182 orig=$(eval "echo \$_fzf_orig_completion_$cmd")83 if [ -n "$orig" ] && type "$orig" > /dev/null 2>&1; then84 $orig "$@"85 elif [ -n "$_fzf_completion_loader" ]; then86 _completion_loader "$@"87 ret=$?Merge pull request #285 from evverx/possible-retry-loopJunegunn Choibefore adoptionae72b0f
line 88why, one step back88 eval $(complete | \grep "\-F.* $orig_cmd$" | _fzf_orig_completion_filter)Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 89–94why, one step back89 source $BASH_SOURCE90 return $ret91 fi92}9394_fzf_path_completion() {Fuzzy completion using fzf-tmuxJunegunn Choibefore adoptiona4f3d09
line 95why, one step back95 local cur base dir leftover matches trigger cmd fzfFZF_TMUX and FZF_TMUX_HEIGHT for fuzzy completionJunegunn Choibefore adoption3ec83ba
line 96why, one step back96 [ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 97–98why, one step back97 cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g')98 COMPREPLY=()[bash-completion] Allow specifying empty completion trigger (#230)Junegunn Choibefore adoption64949bf
line 99why, one step back99 trigger=${FZF_COMPLETION_TRIGGER-'**'}Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 100–111why, one step back100 cur="${COMP_WORDS[COMP_CWORD]}"101 if [[ ${cur} == *"$trigger" ]]; then102 base=${cur:0:${#cur}-${#trigger}}103 eval base=$base104105 dir="$base"106 while [ 1 ]; do107 if [ -z "$dir" -o -d "$dir" ]; then108 leftover=${base/#"$dir"}109 leftover=${leftover/#\/}110 [ "$dir" = './' ] && dir=''111 tput scFuzzy completion using fzf-tmuxJunegunn Choibefore adoptiona4f3d09
line 112why, one step back112 matches=$(find -L "$dir"* $1 2> /dev/null | $fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read item; doAdd man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 113–135why, one step back113 printf "%q$3 " "$item"114 done)115 matches=${matches% }116 if [ -n "$matches" ]; then117 COMPREPLY=( "$matches" )118 else119 COMPREPLY=( "$cur" )120 fi121 tput rc122 return 0123 fi124 dir=$(dirname "$dir")125 [[ "$dir" =~ /$ ]] || dir="$dir"/126 done127 else128 shift129 shift130 shift131 _fzf_handle_dynamic_completion "$cmd" "$@"132 fi133}134135_fzf_list_completion() {Fuzzy completion using fzf-tmuxJunegunn Choibefore adoptiona4f3d09
line 136why, one step back136 local cur selected trigger cmd src fzfFZF_TMUX and FZF_TMUX_HEIGHT for fuzzy completionJunegunn Choibefore adoption3ec83ba
line 137why, one step back137 [ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 138–139why, one step back138 read -r src139 cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g')[bash-completion] Allow specifying empty completion trigger (#230)Junegunn Choibefore adoption64949bf
line 140why, one step back140 trigger=${FZF_COMPLETION_TRIGGER-'**'}Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 141–145why, one step back141 cur="${COMP_WORDS[COMP_CWORD]}"142 if [[ ${cur} == *"$trigger" ]]; then143 cur=${cur:0:${#cur}-${#trigger}}144145 tput scFuzzy completion using fzf-tmuxJunegunn Choibefore adoptiona4f3d09
line 146why, one step back146 selected=$(eval "$src | $fzf $FZF_COMPLETION_OPTS $1 -q '$cur'" | tr '\n' ' ')Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 147–180why, one step back147 selected=${selected% }148 tput rc149150 if [ -n "$selected" ]; then151 COMPREPLY=("$selected")152 return 0153 fi154 else155 shift156 _fzf_handle_dynamic_completion "$cmd" "$@"157 fi158}159160_fzf_all_completion() {161 _fzf_path_completion \162 "-name .git -prune -o -name .svn -prune -o -type d -print -o -type f -print -o -type l -print" \163 "-m" "" "$@"164}165166_fzf_file_completion() {167 _fzf_path_completion \168 "-name .git -prune -o -name .svn -prune -o -type f -print -o -type l -print" \169 "-m" "" "$@"170}171172_fzf_dir_completion() {173 _fzf_path_completion \174 "-name .git -prune -o -name .svn -prune -o -type d -print" \175 "" "/" "$@"176}177178_fzf_kill_completion() {179 [ -n "${COMP_WORDS[COMP_CWORD]}" ] && return 1180Fuzzy completion using fzf-tmuxJunegunn Choibefore adoptiona4f3d09
line 181why, one step back181 local selected fzfFZF_TMUX and FZF_TMUX_HEIGHT for fuzzy completionJunegunn Choibefore adoption3ec83ba
line 182why, one step back182 [ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
line 183why, one step back183 tput scFuzzy completion using fzf-tmuxJunegunn Choibefore adoptiona4f3d09
line 184why, one step back184 selected=$(ps -ef | sed 1d | $fzf -m $FZF_COMPLETION_OPTS | awk '{print $2}' | tr '\n' ' ')Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 185–194why, one step back185 tput rc186187 if [ -n "$selected" ]; then188 COMPREPLY=( "$selected" )189 return 0190 fi191}192193_fzf_telnet_completion() {194 _fzf_list_completion '+m' "$@" << "EOF"[bash-completion] Ignore 0.0.0.0Junegunn Choibefore adoptioned8202e
line 195why, one step back195 \grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0' | awk '{if (length($2) > 0) {print $2}}' | sort -uAdd man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 196–200why, one step back196EOF197}198199_fzf_ssh_completion() {200 _fzf_list_completion '+m' "$@" << "EOF"[zsh/bash-completion] Avoid caret expansionJunegunn Choibefore adoptionc14aa99
line 201why, one step back201 cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | \grep -i '^host' | \grep -v '*') <(\grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0') | awk '{if (length($2) > 0) {print $2}}' | sort -uAdd man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 202–217why, one step back202EOF203}204205_fzf_env_var_completion() {206 _fzf_list_completion '-m' "$@" << "EOF"207 declare -xp | sed 's/=.*//' | sed 's/.* //'208EOF209}210211_fzf_alias_completion() {212 _fzf_list_completion '-m' "$@" << "EOF"213 alias | sed 's/=.*//' | sed 's/.* //'214EOF215}216217# fzf optionsAdd support for search historyJunegunn Choibefore adoption3b52811
line 218why, one step back218complete -o default -F _fzf_opts_completion fzfAdd man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 219–233why, one step back219220d_cmds="cd pushd rmdir"221f_cmds="222 awk cat diff diff3223 emacs ex file ftp g++ gcc gvim head hg java224 javac ld less more mvim patch perl python ruby225 sed sftp sort source tail tee uniq vi view vim wc"226a_cmds="227 basename bunzip2 bzip2 chmod chown curl cp dirname du228 find git grep gunzip gzip hg jar229 ln ls mv open rm rsync scp230 svn tar unzip zip"231x_cmds="kill ssh telnet unset unalias export"232233# Preserve existing completion0.9.12Junegunn Choibefore adoption34946b7
line 234why, one step back234if [ "$_fzf_completion_loaded" != '0.9.12' ]; thenAdd man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 235–237why, one step back235 # Really wish I could use associative array but OSX comes with bash 3.2 :(236 eval $(complete | \grep '\-F' | \grep -v _fzf_ |237 \grep -E " ($(echo $d_cmds $f_cmds $a_cmds $x_cmds | sed 's/ /|/g' | sed 's/+/\\+/g'))$" | _fzf_orig_completion_filter)0.9.12Junegunn Choibefore adoption34946b7
line 238why, one step back238 export _fzf_completion_loaded=0.9.12Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0
lines 239–272why, one step back239fi240241if type _completion_loader > /dev/null 2>&1; then242 _fzf_completion_loader=1243fi244245# Directory246for cmd in $d_cmds; do247 complete -F _fzf_dir_completion -o nospace -o plusdirs $cmd248done249250# File251for cmd in $f_cmds; do252 complete -F _fzf_file_completion -o default -o bashdefault $cmd253done254255# Anything256for cmd in $a_cmds; do257 complete -F _fzf_all_completion -o default -o bashdefault $cmd258done259260# Kill completion261complete -F _fzf_kill_completion -o nospace -o default -o bashdefault kill262263# Host completion264complete -F _fzf_ssh_completion -o default -o bashdefault ssh265complete -F _fzf_telnet_completion -o default -o bashdefault telnet266267# Environment variables / Aliases268complete -F _fzf_env_var_completion -o default -o bashdefault unset269complete -F _fzf_env_var_completion -o default -o bashdefault export270complete -F _fzf_alias_completion -o default -o bashdefault unalias271272unset cmd d_cmds f_cmds a_cmds x_cmds