-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.sh
executable file
·102 lines (90 loc) · 2.93 KB
/
shell.sh
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
#!/bin/bash
_sc_completions() {
local cur prev LASTCHAR=' ' IFS=$'\n'
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# If we are on the first argument, complete file and directory names
if [[ $COMP_CWORD -eq 1 ]]; then
COMPREPLY=( $(compgen -o plusdirs -f -- "${cur}") )
# Handle single completion case
if [ ${#COMPREPLY[@]} = 1 ]; then
local expanded="${COMPREPLY[0]/#\~/$HOME}"
[ -d "$expanded" ] && LASTCHAR='/'
COMPREPLY="${COMPREPLY[0]}${LASTCHAR}"
else
for ((i=0; i < ${#COMPREPLY[@]}; i++)); do
local expanded="${COMPREPLY[$i]/#\~/$HOME}"
[ -d "$expanded" ] && COMPREPLY[$i]="${COMPREPLY[$i]}/"
done
fi
return 0
fi
local js_file="${COMP_WORDS[1]}"
# Handle autocomplete for the 'calls-' prefix
if [[ $COMP_CWORD -eq 2 && $cur == calls-* ]]; then
local prefix="calls-"
local typed="${cur#calls-}"
local opts
opts=$(sc "${js_file}" -listCallees 2>/dev/null)
if [[ $? -eq 0 ]]; then
COMPREPLY=( $(compgen -W "${opts}" -- "${typed}") )
COMPREPLY=( "${COMPREPLY[@]/#/calls-}" )
else
COMPREPLY=("Error reading callees")
fi
return 0
fi
# Handle autocomplete for the 'by-' prefix
if [[ $COMP_CWORD -eq 2 && $cur == by-* ]]; then
local prefix="by-"
local typed="${cur#by-}"
local opts
opts=$(sc "${js_file}" -listCallers 2>/dev/null) # Assuming -listCallers would give us a list of functions
if [[ $? -eq 0 ]]; then
COMPREPLY=( $(compgen -W "${opts}" -- "${typed}") )
COMPREPLY=( "${COMPREPLY[@]/#/by-}" )
else
COMPREPLY=("Error reading callers")
fi
return 0
fi
# Handle autocomplete for function names that are called by the selected function
if [[ $COMP_CWORD -eq 3 && ${COMP_WORDS[2]} == by-* ]]; then
local caller="${COMP_WORDS[2]#by-}"
local typed="${cur}"
local opts
opts=$(sc "${js_file}" "by-${caller}" 2>/dev/null)
if [[ $? -eq 0 ]]; then
COMPREPLY=( $(compgen -W "${opts}" -- "${typed}") )
else
COMPREPLY=("Error reading callees")
fi
return 0
fi
# Handle autocomplete for function names that are called by the selected function
if [[ $COMP_CWORD -eq 3 && ${COMP_WORDS[2]} == calls-* ]]; then
local callee="${COMP_WORDS[2]#calls-}"
local typed="${cur}"
local opts
opts=$(sc "${js_file}" "calls-${callee}" 2>/dev/null)
if [[ $? -eq 0 ]]; then
COMPREPLY=( $(compgen -W "${opts}" -- "${typed}") )
else
COMPREPLY=("Error reading callers")
fi
return 0
fi
# If we are on the second argument, complete with items from the JS file
if [[ $COMP_CWORD -eq 2 && -n ${js_file} ]]; then
local opts
opts=$(sc "${js_file}" 2>/dev/null)
if [[ $? -eq 0 ]]; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
else
COMPREPLY=("Error reading items")
fi
fi
}
complete -r sc &>/dev/null
complete -o nospace -F _sc_completions sc