Skip to content
Myr

completion.bash

This file

Path

shell/completion.bash

275 lines · 6.8 KiB · Shell

Last changed by

[zsh-completion] Allow custom completion functionJunegunn Choibefore adoption8fa9e85

History of this file

Take it

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

Update READMEJunegunn Choibefore adoptionf4fe933

lines 1–31why, 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_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() {19 local cur prev opts20 COMPREPLY=()21 cur="${COMP_WORDS[COMP_CWORD]}"22 prev="${COMP_WORDS[COMP_CWORD-1]}"23 opts="24 -x --extended25 -e --extended-exact26 -i +i27 -n --nth28 -d --delimiter29 +s --no-sort30 --tac31 --tiebreak

0.9.12Junegunn Choibefore adoption34946b7

line 32why, one step back
32 --bind

Update READMEJunegunn Choibefore adoptionf4fe933

lines 33–34why, one step back
33 -m --multi
34 --no-mouse

Update completion for fzf itselfJunegunn Choibefore adoption22ae7ad

line 35why, one step back
35 --color

Update READMEJunegunn Choibefore adoptionf4fe933

lines 36–38why, one step back
36 --black
37 --reverse38 --no-hscroll

Update completion for fzf itselfJunegunn Choibefore adoption22ae7ad

line 39why, one step back
39 --inline-info

Update READMEJunegunn Choibefore adoptionf4fe933

lines 40–47why, one step back
40 --prompt
41 -q --query42 -1 --select-143 -0 --exit-044 -f --filter45 --print-query46 --expect47 --toggle-sort

Add support for search historyJunegunn Choibefore adoption3b52811

line 48why, one step back
48 --sync

0.10.0Junegunn Choibefore adoptiona336494

line 49why, one step back
49 --cycle

Add support for search historyJunegunn Choibefore adoption3b52811

line 50why, one step back
50 --history

[bash] Update fzf option completionJunegunn Choibefore adoption51d84b1

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

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

line 52why, one step back
52 --header

Add --margin optionJunegunn Choibefore adoptionee0c8a2

lines 53–54why, one step back
53 --header-lines
54 --margin"

Update READMEJunegunn Choibefore adoptionf4fe933

lines 55–58why, one step back
55
56 case "${prev}" in57 --tiebreak)58 COMPREPLY=( $(compgen -W "length begin end index" -- ${cur}) )

Update completion for fzf itselfJunegunn Choibefore adoption22ae7ad

lines 59–62why, one step back
59 return 0
60 ;;61 --color)62 COMPREPLY=( $(compgen -W "dark light 16 bw" -- ${cur}) )

Update READMEJunegunn Choibefore adoptionf4fe933

lines 63–64why, one step back
63 return 0
64 ;;

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

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

Add support for search historyJunegunn Choibefore adoption3b52811

lines 66–68why, one step back
66 COMPREPLY=()
67 return 068 ;;

Update READMEJunegunn Choibefore adoptionf4fe933

lines 69–79why, one step back
69 esac
7071 if [[ ${cur} =~ ^-|\+ ]]; then72 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )73 return 074 fi7576 return 077}7879_fzf_handle_dynamic_completion() {

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

line 80why, one step back
80 local cmd orig ret orig_cmd

Update READMEJunegunn Choibefore adoptionf4fe933

lines 81–82why, one step back
81 cmd="$1"
82 shift

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

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

Update READMEJunegunn Choibefore adoptionf4fe933

lines 84–90why, one step back
84
85 orig=$(eval "echo \$_fzf_orig_completion_$cmd")86 if [ -n "$orig" ] && type "$orig" > /dev/null 2>&1; then87 $orig "$@"88 elif [ -n "$_fzf_completion_loader" ]; then89 _completion_loader "$@"90 ret=$?

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

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

Update READMEJunegunn Choibefore adoptionf4fe933

lines 92–101why, one step back
92 source $BASH_SOURCE
93 return $ret94 fi95}9697_fzf_path_completion() {98 local cur base dir leftover matches trigger cmd fzf99 [ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"100 cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g')101 COMPREPLY=()

[bash-completion] Allow specifying empty completion trigger (#230)Junegunn Choibefore adoption64949bf

line 102why, one step back
102 trigger=${FZF_COMPLETION_TRIGGER-'**'}

Update READMEJunegunn Choibefore adoptionf4fe933

lines 103–142why, one step back
103 cur="${COMP_WORDS[COMP_CWORD]}"
104 if [[ ${cur} == *"$trigger" ]]; then105 base=${cur:0:${#cur}-${#trigger}}106 eval base=$base107108 dir="$base"109 while [ 1 ]; do110 if [ -z "$dir" -o -d "$dir" ]; then111 leftover=${base/#"$dir"}112 leftover=${leftover/#\/}113 [ "$dir" = './' ] && dir=''114 tput sc115 matches=$(find -L "$dir"* $1 2> /dev/null | $fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read item; do116 printf "%q$3 " "$item"117 done)118 matches=${matches% }119 if [ -n "$matches" ]; then120 COMPREPLY=( "$matches" )121 else122 COMPREPLY=( "$cur" )123 fi124 tput rc125 return 0126 fi127 dir=$(dirname "$dir")128 [[ "$dir" =~ /$ ]] || dir="$dir"/129 done130 else131 shift132 shift133 shift134 _fzf_handle_dynamic_completion "$cmd" "$@"135 fi136}137138_fzf_list_completion() {139 local cur selected trigger cmd src fzf140 [ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"141 read -r src142 cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g')

[bash-completion] Allow specifying empty completion trigger (#230)Junegunn Choibefore adoption64949bf

line 143why, one step back
143 trigger=${FZF_COMPLETION_TRIGGER-'**'}

Update READMEJunegunn Choibefore adoptionf4fe933

lines 144–197why, one step back
144 cur="${COMP_WORDS[COMP_CWORD]}"
145 if [[ ${cur} == *"$trigger" ]]; then146 cur=${cur:0:${#cur}-${#trigger}}147148 tput sc149 selected=$(eval "$src | $fzf $FZF_COMPLETION_OPTS $1 -q '$cur'" | tr '\n' ' ')150 selected=${selected% }151 tput rc152153 if [ -n "$selected" ]; then154 COMPREPLY=("$selected")155 return 0156 fi157 else158 shift159 _fzf_handle_dynamic_completion "$cmd" "$@"160 fi161}162163_fzf_all_completion() {164 _fzf_path_completion \165 "-name .git -prune -o -name .svn -prune -o -type d -print -o -type f -print -o -type l -print" \166 "-m" "" "$@"167}168169_fzf_file_completion() {170 _fzf_path_completion \171 "-name .git -prune -o -name .svn -prune -o -type f -print -o -type l -print" \172 "-m" "" "$@"173}174175_fzf_dir_completion() {176 _fzf_path_completion \177 "-name .git -prune -o -name .svn -prune -o -type d -print" \178 "" "/" "$@"179}180181_fzf_kill_completion() {182 [ -n "${COMP_WORDS[COMP_CWORD]}" ] && return 1183184 local selected fzf185 [ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"186 tput sc187 selected=$(ps -ef | sed 1d | $fzf -m $FZF_COMPLETION_OPTS | awk '{print $2}' | tr '\n' ' ')188 tput rc189190 if [ -n "$selected" ]; then191 COMPREPLY=( "$selected" )192 return 0193 fi194}195196_fzf_telnet_completion() {197 _fzf_list_completion '+m' "$@" << "EOF"

[zsh-completion] Allow custom completion functionJunegunn Choibefore adoption8fa9e85

line 198why, one step back
198 \grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0' | awk '{if (length($2) > 0) {print $2}}' | sort -u

Update READMEJunegunn Choibefore adoptionf4fe933

lines 199–203why, one step back
199EOF
200}201202_fzf_ssh_completion() {203 _fzf_list_completion '+m' "$@" << "EOF"

[zsh/bash-completion] Avoid caret expansionJunegunn Choibefore adoptionc14aa99

line 204why, one step back
204 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 -u

Update READMEJunegunn Choibefore adoptionf4fe933

lines 205–209why, one step back
205EOF
206}207208_fzf_env_var_completion() {209 _fzf_list_completion '-m' "$@" << "EOF"

[zsh-completion] Allow custom completion functionJunegunn Choibefore adoption8fa9e85

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

Update READMEJunegunn Choibefore adoptionf4fe933

lines 211–215why, one step back
211EOF
212}213214_fzf_alias_completion() {215 _fzf_list_completion '-m' "$@" << "EOF"

[zsh-completion] Allow custom completion functionJunegunn Choibefore adoption8fa9e85

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

Update READMEJunegunn Choibefore adoptionf4fe933

lines 217–220why, one step back
217EOF
218}219220# fzf options

Add support for search historyJunegunn Choibefore adoption3b52811

line 221why, one step back
221complete -o default -F _fzf_opts_completion fzf

Update READMEJunegunn Choibefore adoptionf4fe933

lines 222–236why, one step back
222
223d_cmds="cd pushd rmdir"224f_cmds="225 awk cat diff diff3226 emacs ex file ftp g++ gcc gvim head hg java227 javac ld less more mvim patch perl python ruby228 sed sftp sort source tail tee uniq vi view vim wc"229a_cmds="230 basename bunzip2 bzip2 chmod chown curl cp dirname du231 find git grep gunzip gzip hg jar232 ln ls mv open rm rsync scp233 svn tar unzip zip"234x_cmds="kill ssh telnet unset unalias export"235236# Preserve existing completion

0.9.12Junegunn Choibefore adoption34946b7

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

Update READMEJunegunn Choibefore adoptionf4fe933

lines 238–240why, one step back
238 # Really wish I could use associative array but OSX comes with bash 3.2 :(
239 eval $(complete | \grep '\-F' | \grep -v _fzf_ |240 \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 241why, one step back
241 export _fzf_completion_loaded=0.9.12

Update READMEJunegunn Choibefore adoptionf4fe933

lines 242–275why, one step back
242fi
243244if type _completion_loader > /dev/null 2>&1; then245 _fzf_completion_loader=1246fi247248# Directory249for cmd in $d_cmds; do250 complete -F _fzf_dir_completion -o nospace -o plusdirs $cmd251done252253# File254for cmd in $f_cmds; do255 complete -F _fzf_file_completion -o default -o bashdefault $cmd256done257258# Anything259for cmd in $a_cmds; do260 complete -F _fzf_all_completion -o default -o bashdefault $cmd261done262263# Kill completion264complete -F _fzf_kill_completion -o nospace -o default -o bashdefault kill265266# Host completion267complete -F _fzf_ssh_completion -o default -o bashdefault ssh268complete -F _fzf_telnet_completion -o default -o bashdefault telnet269270# Environment variables / Aliases271complete -F _fzf_env_var_completion -o default -o bashdefault unset272complete -F _fzf_env_var_completion -o default -o bashdefault export273complete -F _fzf_alias_completion -o default -o bashdefault unalias274275unset cmd d_cmds f_cmds a_cmds x_cmds