-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhumans_completion
90 lines (81 loc) · 2.34 KB
/
humans_completion
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
#!/bin/bash
# Author: Guillermo Robles
#
# Gives completion to the humans suite
_humans () {
local cur prev
DB_LOCATION="/usr/share/humans/humans.db"
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts='nip name dni subject bachelor all query schema'
short_opts='nip name dni bachelor all'
case "${prev}" in
"humans")
COMPREPLY=( $(compgen -W "${opts} -s -h" -- "${cur}") )
return 0
;;
"-s")
COMPREPLY=( $(compgen -W "${short_opts}" -- "${cur}") )
return 0
;;
"-h")
COMPREPLY=()
return 0
;;
"nip")
local nips=$(sqlite3 "${DB_LOCATION}" "SELECT nip FROM STUDENT")
COMPREPLY=( $(compgen -W "${nips}" -- "${cur}") )
return 0
;;
"name")
local names=$(sqlite3 "${DB_LOCATION}" "SELECT name FROM STUDENT")
COMPREPLY=( $(compgen -W "${names}" -- "${cur}") )
return 0
;;
"dni")
local nips=$(sqlite3 "${DB_LOCATION}" "SELECT dni FROM STUDENT")
COMPREPLY=( $(compgen -W "${nips}" -- "${cur}") )
return 0
;;
"subject")
local subjects=$(sqlite3 "${DB_LOCATION}" "SELECT name FROM SUBJECT" | tr "A-Z" "a-z")
COMPREPLY=( $(compgen -W "${subjects}" -- "${cur}") )
return 0
;;
"bachelor")
local bachelors=$(sqlite3 "${DB_LOCATION}" "SELECT name FROM BACHELOR" | tr "A-Z" "a-z")
COMPREPLY=( $(compgen -W "${bachelors}" -- "${cur}") )
return 0
;;
"all")
COMPREPLY=()
return 0
;;
"query")
COMPREPLY=()
return 0
;;
"schema")
COMPREPLY=()
return 0
;;
esac
}
_humans-load () {
COMPREPLY=()
return 0
}
_humans-get-sources () {
COMPREPLY=()
return 0
}
_humans-process-usernames () {
local cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -o filenames -A file -- "${cur}") )
return 0
}
complete -F _humans humans
complete -F _humans-load humans-load
complete -F _humans-get-sources humans-get-sources
complete -F _humans-process-usernames humans-process-usernames