-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_complete_alias
53 lines (47 loc) · 1.38 KB
/
bash_complete_alias
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash ### source me ###
function make-completion-wrapper-1 () {
local function_name="$2"
local arg_count=$(($#-2))
local comp_function_name="$(complete -pr $1|sed -e 's/^\(.* -F \)\([^ ]*\) [^ ]*$/\2/')"
[ -z "$comp_function_name" ] && return
shift 2
local function="
function $function_name {
((COMP_CWORD+=$arg_count))
echo $COMP_POINT
((COMP_POINT+=${#1}+1-${#2}))
echo $COMP_POINT
COMP_WORDS=( "$@" \${COMP_WORDS[@]:1} )
"$comp_function_name"
return 0
}"
echo "$function"
eval "$function"
}
function make-completion-wrapper-2 () {
local function_name="$1"
local alias_name="$2"
local comp_function_base="$(complete -pr $3|sed -e 's/^\(.* -F\)\( [^ ]*\) [^ ]*$/\1/')"
[ -z "$comp_function_name" ] && return
echo "$comp_function_base $function_name $alias_name"
eval "$comp_function_base $function_name $alias_name"
}
[ -e ~/.cache/bash_alias_complete ] && rm ~/.cache/bash_alias_complete
alias | \
sed \
-e 's/^alias //' \
-e '/^\([^=]\+\)='\''\1 /d' \
-e '/[^0-9A-Za-z -]/d' \
-e h \
-e "s/.*='\([^ ]*\)\( .*\)'$/\1! \1\2/" \
-e 'y/ -!/__ /' -eG -e 's!\n[^=]*='\''\(.*\)'\''! \1!' \
-e 's/^/make-completion-wrapper-1 /p' \
-e 's/^[^ ]* [^ ]* \([^ ]*\) .*$/\1/' \
-e x \
-e 's!='\''\([^ ]*\) .*$! \1!' \
-e x \
-e 's!^!make-completion-wrapper-2 !' \
-e G \
-e 'y/\n/ /' \
> ~/.cache/bash_alias_complete
. ~/.cache/bash_alias_complete