completion.bash
This file
Path
shell/completion.bash
274 lines · 6.8 KiB · Shell
Last changed by
[bash] Update fzf option completionJunegunn Choibefore adoption51d84b1
History of this fileTake it
The walk stopped after 200 commits: lines older than c4bf820 point at it.
Update man pageJunegunn Choibefore adoptionc4bf820
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%')Update man pageJunegunn Choibefore adoptionc4bf820
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 optsUpdate man pageJunegunn Choibefore adoptionc4bf820
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]}"Update man pageJunegunn Choibefore adoptionc4bf820
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 --bindUpdate man pageJunegunn Choibefore adoptionc4bf820
lines 33–34why, one step back33 -m --multi34 --no-mouseUpdate completion for fzf itselfJunegunn Choibefore adoption22ae7ad
line 35why, one step back35 --colorUpdate man pageJunegunn Choibefore adoptionc4bf820
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-infoUpdate man pageJunegunn Choibefore adoptionc4bf820
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 --history[bash] Update fzf option completionJunegunn Choibefore adoption51d84b1
lines 51–53why, one step back51 --history-size52 --header-file53 --header-lines"Prepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c
lines 54–57why, one step back5455 case "${prev}" in56 --tiebreak)57 COMPREPLY=( $(compgen -W "length begin end index" -- ${cur}) )Update completion for fzf itselfJunegunn Choibefore adoption22ae7ad
lines 58–61why, one step back58 return 059 ;;60 --color)61 COMPREPLY=( $(compgen -W "dark light 16 bw" -- ${cur}) )Prepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c
lines 62–63why, one step back62 return 063 ;;[bash] Update fzf option completionJunegunn Choibefore adoption51d84b1
line 64why, one step back64 --history|--header-file)Add support for search historyJunegunn Choibefore adoption3b52811
lines 65–67why, one step back65 COMPREPLY=()66 return 067 ;;Prepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c
line 68why, one step back68 esacUpdate man pageJunegunn Choibefore adoptionc4bf820
lines 69–78why, one step back6970 if [[ ${cur} =~ ^-|\+ ]]; then71 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )72 return 073 fi7475 return 076}7778_fzf_handle_dynamic_completion() {Merge pull request #285 from evverx/possible-retry-loopJunegunn Choibefore adoptionae72b0f
line 79why, one step back79 local cmd orig ret orig_cmdUpdate man pageJunegunn Choibefore adoptionc4bf820
lines 80–81why, one step back80 cmd="$1"81 shiftMerge pull request #285 from evverx/possible-retry-loopJunegunn Choibefore adoptionae72b0f
line 82why, one step back82 orig_cmd="$1"Update man pageJunegunn Choibefore adoptionc4bf820
lines 83–89why, one step back8384 orig=$(eval "echo \$_fzf_orig_completion_$cmd")85 if [ -n "$orig" ] && type "$orig" > /dev/null 2>&1; then86 $orig "$@"87 elif [ -n "$_fzf_completion_loader" ]; then88 _completion_loader "$@"89 ret=$?Merge pull request #285 from evverx/possible-retry-loopJunegunn Choibefore adoptionae72b0f
line 90why, one step back90 eval $(complete | \grep "\-F.* $orig_cmd$" | _fzf_orig_completion_filter)Update man pageJunegunn Choibefore adoptionc4bf820
lines 91–96why, one step back91 source $BASH_SOURCE92 return $ret93 fi94}9596_fzf_path_completion() {Fuzzy completion using fzf-tmuxJunegunn Choibefore adoptiona4f3d09
line 97why, one step back97 local cur base dir leftover matches trigger cmd fzfFZF_TMUX and FZF_TMUX_HEIGHT for fuzzy completionJunegunn Choibefore adoption3ec83ba
line 98why, one step back98 [ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"Update man pageJunegunn Choibefore adoptionc4bf820
lines 99–100why, one step back99 cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g')100 COMPREPLY=()[bash-completion] Allow specifying empty completion trigger (#230)Junegunn Choibefore adoption64949bf
line 101why, one step back101 trigger=${FZF_COMPLETION_TRIGGER-'**'}Update man pageJunegunn Choibefore adoptionc4bf820
lines 102–113why, one step back102 cur="${COMP_WORDS[COMP_CWORD]}"103 if [[ ${cur} == *"$trigger" ]]; then104 base=${cur:0:${#cur}-${#trigger}}105 eval base=$base106107 dir="$base"108 while [ 1 ]; do109 if [ -z "$dir" -o -d "$dir" ]; then110 leftover=${base/#"$dir"}111 leftover=${leftover/#\/}112 [ "$dir" = './' ] && dir=''113 tput scFuzzy completion using fzf-tmuxJunegunn Choibefore adoptiona4f3d09
line 114why, one step back114 matches=$(find -L "$dir"* $1 2> /dev/null | $fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read item; doUpdate man pageJunegunn Choibefore adoptionc4bf820
lines 115–137why, one step back115 printf "%q$3 " "$item"116 done)117 matches=${matches% }118 if [ -n "$matches" ]; then119 COMPREPLY=( "$matches" )120 else121 COMPREPLY=( "$cur" )122 fi123 tput rc124 return 0125 fi126 dir=$(dirname "$dir")127 [[ "$dir" =~ /$ ]] || dir="$dir"/128 done129 else130 shift131 shift132 shift133 _fzf_handle_dynamic_completion "$cmd" "$@"134 fi135}136137_fzf_list_completion() {Fuzzy completion using fzf-tmuxJunegunn Choibefore adoptiona4f3d09
line 138why, one step back138 local cur selected trigger cmd src fzfFZF_TMUX and FZF_TMUX_HEIGHT for fuzzy completionJunegunn Choibefore adoption3ec83ba
line 139why, one step back139 [ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"Update man pageJunegunn Choibefore adoptionc4bf820
lines 140–141why, one step back140 read -r src141 cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g')[bash-completion] Allow specifying empty completion trigger (#230)Junegunn Choibefore adoption64949bf
line 142why, one step back142 trigger=${FZF_COMPLETION_TRIGGER-'**'}Update man pageJunegunn Choibefore adoptionc4bf820
lines 143–147why, one step back143 cur="${COMP_WORDS[COMP_CWORD]}"144 if [[ ${cur} == *"$trigger" ]]; then145 cur=${cur:0:${#cur}-${#trigger}}146147 tput scFuzzy completion using fzf-tmuxJunegunn Choibefore adoptiona4f3d09
line 148why, one step back148 selected=$(eval "$src | $fzf $FZF_COMPLETION_OPTS $1 -q '$cur'" | tr '\n' ' ')Update man pageJunegunn Choibefore adoptionc4bf820
lines 149–182why, one step back149 selected=${selected% }150 tput rc151152 if [ -n "$selected" ]; then153 COMPREPLY=("$selected")154 return 0155 fi156 else157 shift158 _fzf_handle_dynamic_completion "$cmd" "$@"159 fi160}161162_fzf_all_completion() {163 _fzf_path_completion \164 "-name .git -prune -o -name .svn -prune -o -type d -print -o -type f -print -o -type l -print" \165 "-m" "" "$@"166}167168_fzf_file_completion() {169 _fzf_path_completion \170 "-name .git -prune -o -name .svn -prune -o -type f -print -o -type l -print" \171 "-m" "" "$@"172}173174_fzf_dir_completion() {175 _fzf_path_completion \176 "-name .git -prune -o -name .svn -prune -o -type d -print" \177 "" "/" "$@"178}179180_fzf_kill_completion() {181 [ -n "${COMP_WORDS[COMP_CWORD]}" ] && return 1182Fuzzy completion using fzf-tmuxJunegunn Choibefore adoptiona4f3d09
line 183why, one step back183 local selected fzfFZF_TMUX and FZF_TMUX_HEIGHT for fuzzy completionJunegunn Choibefore adoption3ec83ba
line 184why, one step back184 [ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"Update man pageJunegunn Choibefore adoptionc4bf820
line 185why, one step back185 tput scFuzzy completion using fzf-tmuxJunegunn Choibefore adoptiona4f3d09
line 186why, one step back186 selected=$(ps -ef | sed 1d | $fzf -m $FZF_COMPLETION_OPTS | awk '{print $2}' | tr '\n' ' ')Update man pageJunegunn Choibefore adoptionc4bf820
lines 187–196why, one step back187 tput rc188189 if [ -n "$selected" ]; then190 COMPREPLY=( "$selected" )191 return 0192 fi193}194195_fzf_telnet_completion() {196 _fzf_list_completion '+m' "$@" << "EOF"[bash-completion] Ignore 0.0.0.0Junegunn Choibefore adoptioned8202e
line 197why, one step back197 \grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0' | awk '{if (length($2) > 0) {print $2}}' | sort -uUpdate man pageJunegunn Choibefore adoptionc4bf820
lines 198–202why, one step back198EOF199}200201_fzf_ssh_completion() {202 _fzf_list_completion '+m' "$@" << "EOF"[zsh/bash-completion] Avoid caret expansionJunegunn Choibefore adoptionc14aa99
line 203why, one step back203 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 -uUpdate man pageJunegunn Choibefore adoptionc4bf820
lines 204–219why, one step back204EOF205}206207_fzf_env_var_completion() {208 _fzf_list_completion '-m' "$@" << "EOF"209 declare -xp | sed 's/=.*//' | sed 's/.* //'210EOF211}212213_fzf_alias_completion() {214 _fzf_list_completion '-m' "$@" << "EOF"215 alias | sed 's/=.*//' | sed 's/.* //'216EOF217}218219# fzf optionsAdd support for search historyJunegunn Choibefore adoption3b52811
line 220why, one step back220complete -o default -F _fzf_opts_completion fzfUpdate man pageJunegunn Choibefore adoptionc4bf820
lines 221–235why, one step back221222d_cmds="cd pushd rmdir"223f_cmds="224 awk cat diff diff3225 emacs ex file ftp g++ gcc gvim head hg java226 javac ld less more mvim patch perl python ruby227 sed sftp sort source tail tee uniq vi view vim wc"228a_cmds="229 basename bunzip2 bzip2 chmod chown curl cp dirname du230 find git grep gunzip gzip hg jar231 ln ls mv open rm rsync scp232 svn tar unzip zip"233x_cmds="kill ssh telnet unset unalias export"234235# Preserve existing completion0.9.12Junegunn Choibefore adoption34946b7
line 236why, one step back236if [ "$_fzf_completion_loaded" != '0.9.12' ]; thenUpdate man pageJunegunn Choibefore adoptionc4bf820
lines 237–239why, one step back237 # Really wish I could use associative array but OSX comes with bash 3.2 :(238 eval $(complete | \grep '\-F' | \grep -v _fzf_ |239 \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 240why, one step back240 export _fzf_completion_loaded=0.9.12Update man pageJunegunn Choibefore adoptionc4bf820
lines 241–274why, one step back241fi242243if type _completion_loader > /dev/null 2>&1; then244 _fzf_completion_loader=1245fi246247# Directory248for cmd in $d_cmds; do249 complete -F _fzf_dir_completion -o nospace -o plusdirs $cmd250done251252# File253for cmd in $f_cmds; do254 complete -F _fzf_file_completion -o default -o bashdefault $cmd255done256257# Anything258for cmd in $a_cmds; do259 complete -F _fzf_all_completion -o default -o bashdefault $cmd260done261262# Kill completion263complete -F _fzf_kill_completion -o nospace -o default -o bashdefault kill264265# Host completion266complete -F _fzf_ssh_completion -o default -o bashdefault ssh267complete -F _fzf_telnet_completion -o default -o bashdefault telnet268269# Environment variables / Aliases270complete -F _fzf_env_var_completion -o default -o bashdefault unset271complete -F _fzf_env_var_completion -o default -o bashdefault export272complete -F _fzf_alias_completion -o default -o bashdefault unalias273274unset cmd d_cmds f_cmds a_cmds x_cmds