This repository was archived by the owner on Feb 10, 2022. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompletions
More file actions
74 lines (67 loc) · 2.09 KB
/
completions
File metadata and controls
74 lines (67 loc) · 2.09 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
# Custom completion rules
_dirs() {
local dir
dir=`basename $1`
find $1 -type d -maxdepth 1 | xargs -II basename I | grep -v $dir
}
_list_apps() {
# Maintains a list of apps in our system
_dirs $HIREIQ_ROOT/py/toomah/djangoapps
}
_list_assessments() {
# Maintains a list of apps in our system
_dirs $HIREIQ_ROOT/py/toomah/assessments
}
_list_pois() {
# All points of interest in our system
_list_apps | sed 's|^|apps/|'
_list_assessments | sed 's|^|assessments/|'
_dirs $HIREIQ_ROOT/py/toomah/djangoprojects | sed 's|^|projects/|'
echo root
echo lib
echo django
}
_poi_completion() {
APPS=`_list_pois`
prefix="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "$APPS" -- $prefix) )
return 0
}
_manage_completion() {
local choices APPS SUBCOMMANDS exe cmd first
# This function is not remotely complete. Add more as needed
exe=$COMP_WORDS
APPS=`_list_apps`
# This could probably be better but my awk foo just isn't that strong
if [ -z "$_manage_subcommands" ]; then
export _manage_subcommands="`$exe help 2>/dev/null | awk '/.*Available.*/,/END/' | grep -v "Available" | grep -v '\['`"
fi
SUBCOMMANDS="$_manage_subcommands"
SUBCOMMANDS="$SUBCOMMANDS -p" # Allow -p flag MUST BE BEFORE SUBCOMMAND
prefix="${COMP_WORDS[COMP_CWORD]}"
cmd=1
if [ "-p" == "${COMP_WORDS[1]}" -a "3" -le "$COMP_CWORD" ]; then
cmd=3
fi
first="${COMP_WORDS[$cmd]}"
# If its the first choice, just use commands
if [ "$cmd" -eq "$COMP_CWORD" ]; then
choices=$SUBCOMMANDS
else
case $first in
'test') choices=$APPS ;;
'shell') choices='--plain' ;;
'-p')
if [ "2" -eq "$COMP_CWORD" ]; then # Hack to see if -p needs arg
choices=`_dirs $HIREIQ_ROOT/py/toomah/djangoprojects`
fi
;;
*) ;;
esac
fi
COMPREPLY=( $(compgen -W "$choices" -- $prefix) )
return 0
}
complete -F _poi_completion gt
complete -F _poi_completion edit
complete -F _manage_completion m