Skip to content
Myr

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 file

Take 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 back
1#!/bin/bash
2# ____ ____3# / __/___ / __/4# / /_/_ / / /_5# / __/ / /_/ __/6# /_/ /___/_/-completion.bash7#

FZF_TMUX and FZF_TMUX_HEIGHT for fuzzy completionJunegunn Choibefore adoption3ec83ba

lines 8–9why, one step back
8# - $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 back
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() {

Prepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c

line 19why, one step back
19 local cur prev opts

Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0

lines 20–21why, one step back
20 COMPREPLY=()
21 cur="${COMP_WORDS[COMP_CWORD]}"

Prepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c

line 22why, one step back
22 prev="${COMP_WORDS[COMP_CWORD-1]}"

Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0

lines 23–30why, one step back
23 opts="
24 -x --extended25 -e --extended-exact26 -i +i27 -n --nth28 -d --delimiter29 +s --no-sort30 --tac

Prepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c

line 31why, one step back
31 --tiebreak

0.9.12Junegunn Choibefore adoption34946b7

line 32why, one step back
32 --bind

Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0

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

Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0

lines 36–37why, one step back
36 --black
37 --reverse

Prepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c

line 38why, one step back
38 --no-hscroll

Update completion for fzf itselfJunegunn Choibefore adoption22ae7ad

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

Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0

lines 40–45why, one step back
40 --prompt
41 -q --query42 -1 --select-143 -0 --exit-044 -f --filter45 --print-query

Prepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c

lines 46–47why, one step back
46 --expect
47 --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

0.10.0Junegunn Choibefore adoptiona336494

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

Prepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c

lines 52–55why, one step back
52
53 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 back
56 return 0
57 ;;58 --color)59 COMPREPLY=( $(compgen -W "dark light 16 bw" -- ${cur}) )

Prepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c

lines 60–61why, one step back
60 return 0
61 ;;

Add support for search historyJunegunn Choibefore adoption3b52811

lines 62–65why, one step back
62 --history)
63 COMPREPLY=()64 return 065 ;;

Prepare for 0.9.9 releaseJunegunn Choibefore adoptiond08542c

line 66why, one step back
66 esac

Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0

lines 67–76why, one step back
67
68 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 back
77 local cmd orig ret orig_cmd

Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0

lines 78–79why, one step back
78 cmd="$1"
79 shift

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

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

Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0

lines 81–87why, one step back
81
82 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 back
88 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 back
89 source $BASH_SOURCE
90 return $ret91 fi92}9394_fzf_path_completion() {

Fuzzy completion using fzf-tmuxJunegunn Choibefore adoptiona4f3d09

line 95why, one step back
95 local cur base dir leftover matches trigger cmd fzf

FZF_TMUX and FZF_TMUX_HEIGHT for fuzzy completionJunegunn Choibefore adoption3ec83ba

line 96why, one step back
96 [ ${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 back
97 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 back
99 trigger=${FZF_COMPLETION_TRIGGER-'**'}

Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0

lines 100–111why, one step back
100 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 sc

Fuzzy completion using fzf-tmuxJunegunn Choibefore adoptiona4f3d09

line 112why, one step back
112 matches=$(find -L "$dir"* $1 2> /dev/null | $fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read item; do

Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0

lines 113–135why, one step back
113 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 back
136 local cur selected trigger cmd src fzf

FZF_TMUX and FZF_TMUX_HEIGHT for fuzzy completionJunegunn Choibefore adoption3ec83ba

line 137why, one step back
137 [ ${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 back
138 read -r src
139 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 back
140 trigger=${FZF_COMPLETION_TRIGGER-'**'}

Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0

lines 141–145why, one step back
141 cur="${COMP_WORDS[COMP_CWORD]}"
142 if [[ ${cur} == *"$trigger" ]]; then143 cur=${cur:0:${#cur}-${#trigger}}144145 tput sc

Fuzzy completion using fzf-tmuxJunegunn Choibefore adoptiona4f3d09

line 146why, one step back
146 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 back
147 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 1180

Fuzzy completion using fzf-tmuxJunegunn Choibefore adoptiona4f3d09

line 181why, one step back
181 local selected fzf

FZF_TMUX and FZF_TMUX_HEIGHT for fuzzy completionJunegunn Choibefore adoption3ec83ba

line 182why, one step back
182 [ ${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 back
183 tput sc

Fuzzy completion using fzf-tmuxJunegunn Choibefore adoptiona4f3d09

line 184why, one step back
184 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 back
185 tput rc
186187 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 back
195 \grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0' | awk '{if (length($2) > 0) {print $2}}' | sort -u

Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0

lines 196–200why, one step back
196EOF
197}198199_fzf_ssh_completion() {200 _fzf_list_completion '+m' "$@" << "EOF"

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

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

Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0

lines 202–217why, one step back
202EOF
203}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 options

Add support for search historyJunegunn Choibefore adoption3b52811

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

Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0

lines 219–233why, one step back
219
220d_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 completion

0.9.12Junegunn Choibefore adoption34946b7

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

Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0

lines 235–237why, one step back
235 # 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 back
238 export _fzf_completion_loaded=0.9.12

Add man path only when the directory existsJunegunn Choibefore adoptioneb8fef0

lines 239–272why, one step back
239fi
240241if 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