This repository was archived by the owner on Mar 31, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathpythonz_completion.sh
More file actions
162 lines (137 loc) · 4.18 KB
/
pythonz_completion.sh
File metadata and controls
162 lines (137 loc) · 4.18 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
declare -A _pythonz_context
_pythonz_complete(){
local option command commands type types types_regex command_option
local available_versions installed_versions unique_versions installed_regex known_versions
local logfile
COMPREPLY=()
types="cpython stackless pypy pypy3 jython"
commands="cleanup help install list locate uninstall update version"
if [ $COMP_CWORD -eq 1 ]; then
_pythonz_context["pythonz"]="-h"
_pythonz_compreply $commands ${_pythonz_context["pythonz"]}
elif [ $COMP_CWORD -eq 2 ]; then
_pythonz_context["type"]="cpython"
_pythonz_context["install"]="-t -f -v -h --run-tests --framework --universal --shared --file --url --reinstall -C --configure"
_pythonz_context["uninstall"]="-t -h"
_pythonz_context["cleanup"]="-a -h"
_pythonz_context["list"]="-a -h"
_pythonz_context["locate"]="-t -h"
_pythonz_context["update"]="--dev -h"
_pythonz_context["version"]="-h"
command=${COMP_WORDS[COMP_CWORD-1]}
_pythonz_handle_command $command
elif [ $COMP_CWORD -ge 3 ]; then
command=${COMP_WORDS[1]}
command_option=${COMP_WORDS[COMP_CWORD-1]}
_pythonz_handle_command_option $command_option
fi
return 0
}
_pythonz_handle_command(){
command=$*
case "$command" in
help|-h)
commands=$( echo $commands | sed -e "s/help\|-h//g" )
_pythonz_compreply $commands
;;
install)
_pythonz_install
;;
uninstall)
_pythonz_uninstall
;;
locate)
_pythonz_locate
;;
list|cleanup|update|version)
_pythonz_compreply ${_pythonz_context["$command"]}
;;
*)
;;
esac
}
_pythonz_handle_command_option(){
option=$1
case "$option" in
-h)
;;
-t)
_pythonz_update_command_options
_pythonz_compreply $types
;;
cpython|stackless|pypy|pypy3|jython)
_pythonz_context["type"]=$option
_pythonz_handle_command $command
;;
--file)
_pythonz_update_command_options
_pythonz_handle_file
;;
--url)
_pythonz_update_command_options
_pythonz_handle_url
;;
*)
_pythonz_update_command_options
_pythonz_handle_command $command
;;
esac
}
_pythonz_handle_file(){
COMPREPLY=( $(compgen -f -- ${COMP_WORDS[COMP_CWORD]} ) )
compopt -o plusdirs
}
_pythonz_handle_url(){
COMPREPLY=( $(compgen -W "http:// https:// file:// ftp://" -- ${COMP_WORDS[COMP_CWORD]} ) )
compopt -o nospace
}
_pythonz_update_command_options(){
if [[ $option == -* ]];then
_pythonz_context["$command"]=$( echo ${_pythonz_context["$command"]} |sed -e "s/ /\n/g" |sed -e "s/^$option/ /" )
fi
}
_pythonz_install(){
_pythonz_available_versions
_pythonz_compreply ${_pythonz_context["install"]} $available_versions
}
_pythonz_uninstall(){
_pythonz_installed_versions
_pythonz_compreply ${_pythonz_context["uninstall"]} $installed_versions
}
_pythonz_locate(){
_pythonz_installed_versions
_pythonz_compreply ${_pythonz_context["locate"]} $installed_versions
}
_pythonz_available_versions(){
_pythonz_installed_regex
_pythonz_known_versions
if [ -n "$installed_regex" ];then
available_versions=$( echo $known_versions | sed -e "s/$installed_regex/ /g" )
else
available_versions=$known_versions
fi
}
_pythonz_installed_versions(){
type=${_pythonz_context["type"]}
if [ -n "$type" ]; then
installed_versions=$( pythonz list |egrep -i $type | awk '{print tolower($0)}' | sed -e "s/^.*$type-//g" )
fi
}
_pythonz_installed_regex(){
_pythonz_installed_versions
installed_regex=""
if [ -n "$installed_versions" ];then
unique_versions=$( echo $installed_versions | sed -e 's/ /\n/g'| sed -e 's/\(.*\)/ \1 /g' )
installed_regex=$( echo $unique_versions |sed -e "s/ /|/g" -e "s/|$//" -e "s/|/ \\\| /g" -e "s/^/ /" -e "s/$/ /")
fi
}
_pythonz_known_versions(){
type=${_pythonz_context["type"]}
if [ -n "$type" ]; then
known_versions=$( pythonz list -a |sed -n -e "/$type/,/#.*:/p" |sed -e "/#.*:/d" |awk '{print $1}' )
fi
}
_pythonz_compreply(){
COMPREPLY=( $( compgen -W "$*" -- ${COMP_WORDS[COMP_CWORD]}) )
}
complete -F _pythonz_complete pythonz