Newer
Older
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
function ispresent() {
for item in $2
do
if [ $item = $1 ]; then
return 0
fi
done
return 1
}
function _curl-inau()
{
local h options dirname basename
h=inau.elettra.eu
dirname=$(dirname "${COMP_WORDS[COMP_CWORD]}")
basename=$(basename "${COMP_WORDS[COMP_CWORD]}")
# echo -e "\n$dirname#$basename"
case "$dirname#$basename" in
//$h/v2/cs/facilities/*/hosts/*/files#*)
local facility=$(basename $(dirname $(dirname $(dirname $dirname))))
local host=$(basename $(dirname $dirname))
local files="$(curl -s https://$h/v2/cs/facilities/$facility/hosts/$host/files | tail -n +3 | cut -d" " -f1)"
options="$(for elem in $files; do echo //$h/v2/cs/facilities/$facility/hosts/$host/files/$elem; done)"
;;
//$h/v2/cs/facilities/*/hosts/*#files)
local facility=$(basename $(dirname $(dirname $dirname)))
local host=$(basename $dirname)
local files="$(curl -s https://$h/v2/cs/facilities/$facility/hosts/$host/files | tail -n +3 | cut -d" " -f1)"
options="$(for elem in $files; do echo //$h/v2/cs/facilities/$facility/hosts/$host/files/$elem; done)"
;;
//$h/v2/cs/facilities/*/hosts/*#*)
local facility=$(basename $(dirname $(dirname $dirname)))
local host=$(basename $dirname)
options="//$h/v2/cs/facilities/$facility/hosts/$host/files
//$h/v2/cs/facilities/$facility/hosts/$host/installations"
;;
//$h/v2/cs/facilities/*/hosts#*)
local facility=$(basename $(dirname $dirname))
local hosts="$(curl -s https://$h/v2/cs/facilities/$facility/hosts | tail -n +3 | cut -d" " -f1)"
ispresent $basename "$hosts"
if [ $? -eq 0 ]; then
options="//$h/v2/cs/facilities/$facility/hosts/$basename/installations
//$h/v2/cs/facilities/$facility/hosts/$basename/files"
else
options="//$h/v2/cs/facilities/$facility/hosts/installations
$(for elem in $hosts; do echo //$h/v2/cs/facilities/$facility/hosts/$elem; done)"
fi;;
//$h/v2/cs/facilities/*#hosts)
local facility=$(basename $dirname)
local hosts="$(curl -s https://$h/v2/cs/facilities/$facility/hosts | tail -n +3 | cut -d" " -f1)"
options="//$h/v2/cs/facilities/$facility/hosts/installations
$(for elem in $hosts; do echo //$h/v2/cs/facilities/$facility/hosts/$elem; done)"
;;
//$h/v2/cs/facilities/*#*)
local facility=$(basename $dirname)
options="//$h/v2/cs/facilities/$facility/hosts
//$h/v2/cs/facilities/$facility/installations"
;;
//$h/v2/cs/facilities#*)
local facilities="$(curl -s https://$h/v2/cs/facilities | tail -n +3)"
ispresent $basename "$facilities"
if [ $? -eq 0 ]; then
options="//$h/v2/cs/facilities/$basename/hosts/
//$h/v2/cs/facilities/$basename/installations"
else
options="//$h/v2/cs/facilities/installations
$(for elem in $facilities; do echo //$h/v2/cs/facilities/$elem/; done)"
fi
;;
//$h/v2/cs#facilities)
local facilities="$(curl -s https://$h/v2/cs/facilities | tail -n +3)"
options="//$h/v2/cs/facilities/installations
$(for elem in $facilities; do echo //$h/v2/cs/facilities/$elem/; done)"
;;
//$h/v2#cs | //$h/v2/cs#*)
local subpaths="$(curl -s https://$h/v2/cs | tail -n +3)"
options="//$h/v2/cs/installations
$(for elem in $subpaths; do echo //$h/v2/cs/$elem/; done)"
;;
/#$h | //$h#* | //$h/v2#*)
options="//$h/v2/cs/"
;;
esac
COMPREPLY=($(compgen -W "${options}" -- "${COMP_WORDS[COMP_CWORD]}"))
compopt -o nospace
}
complete -F _curl-inau curl