-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvmw.complete
74 lines (71 loc) · 1.93 KB
/
vmw.complete
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
_temp_bind() { ## temporarily change a bunch of bind terminal settings
set -o emacs
bind "set completion-display-width 0"
bind "set history-preserve-point on"
bind "set show-all-if-ambiguous on"
bind "set show-all-if-unmodified on"
bind "set colored-completion-prefix on"
bind "set colored-stats on"
bind "set page-completions off"
bind "set completion-query-items 0"
bind "set skip-completed-text on"
CLIBIND=1 ## flag shell enable
}
_temp_base_complete() {
local CMDFILE=$1
local CUR PRV
local ARRAY=()
COMPREPLY=()
CUR="${COMP_WORDS[COMP_CWORD]}"
PRV="${COMP_WORDS[COMP_CWORD-1]}"
CYAN='\033[0;36m' # cyan
NC='\033[0m' # no colour
BB='\u001B[94m' # blueBright
BBC='\u001B[39m' # close
if [[ -z ${CLIBIND} ]]; then
_temp_bind ## don't set repeatedly set this as it freezes shell
fi
local IFS=$'\n'
local PARAMLIST
local CURPARAM
local CURKEY
if [[ ${#COMP_WORDS[@]} -le 2 ]]; then
ARRAY=($(vmw-cli ac 2>/dev/null | tr -d '\r')) # handle CRLF in tty
else # resolve params
if [[ ${#COMP_WORDS[@]} -eq 3 ]]; then
case ${PRV} in
"ls")
ARRAY=($(vmw-cli ac ls 2>/dev/null | tr -d '\r')) # handle CRLF in tty
;;
"cp")
ARRAY=($(vmw-cli ac ls . 2>/dev/null | tr -d '\r')) # handle CRLF in tty
;;
esac
fi
fi
local HEADER="${ARRAY[0]}"
local VALUES=("${ARRAY[@]:1}")
local SUGGESTIONS=($(compgen -W "${VALUES[*]}" -- "${CUR}"))
if [ "${#SUGGESTIONS[@]}" -ge "2" ]; then # print header/values
if [[ -n ${CURKEY} ]]; then
printf "${BB}<${CURKEY}>${BBC}" 1>&2
#_get_params
fi
printf "\n${BB}${HEADER}${BBC}" 1>&2
#for I in "${!SUGGESTIONS[@]}"; do
# SUGGESTIONS[$I]="$(printf '%*s' "-$COLUMNS" "${SUGGESTIONS[$I]}")"
#done
COMPREPLY=("${SUGGESTIONS[@]}")
else
if [ "${#SUGGESTIONS[@]}" == "1" ]; then
local ID="${SUGGESTIONS[0]%%\ *}"
COMPREPLY=("$ID")
fi
fi
return 0
}
_vmw_complete() {
_temp_base_complete
}
complete -o nosort -F _vmw_complete vmw-cli