1 | # Common functions fed to 'sh -i' by init_completion.sh.
|
2 |
|
3 | # OSH should have this built in
|
4 | if ! type -t _init_completion; then
|
5 | source testdata/completion/bash_completion
|
6 | fi
|
7 |
|
8 | argv() {
|
9 | python -c 'import sys; print(sys.argv[1:])' "$@"
|
10 | }
|
11 |
|
12 | argv1() {
|
13 | python -c 'import sys; print(repr(sys.argv[1]))' "$@"
|
14 | }
|
15 |
|
16 | comp_echo() {
|
17 | echo
|
18 | echo -n 'case["COMP_WORDS"] = '; argv "${COMP_WORDS[@]}"
|
19 | }
|
20 | complete -F comp_echo echo
|
21 |
|
22 | show_bash_api_vars() {
|
23 | echo -n 'case["func_argv"] = '; argv "$@"
|
24 | echo -n 'case["COMP_LINE"] = '; argv1 "${COMP_LINE}"
|
25 | echo -n 'case["COMP_POINT"] = '; argv1 "${COMP_POINT}"
|
26 | echo -n 'case["COMP_WORDS"] = '; argv "${COMP_WORDS[@]}"
|
27 | echo -n 'case["COMP_CWORD"] = '; argv1 "${COMP_CWORD}"
|
28 | }
|
29 |
|
30 | show_init_completion_vars() {
|
31 | echo -n 'case["words"] = '; argv "${words[@]}"
|
32 | echo -n 'case["cur"] = '; argv1 "$cur"
|
33 | echo -n 'case["prev"] = '; argv1 "$prev"
|
34 | echo -n 'case["cword"] = '; argv1 "$cword"
|
35 | echo -n 'case["split"] = '; argv1 "$split"
|
36 | }
|
37 |
|
38 | _comp_init_completion() {
|
39 | show_bash_api_vars "$@"
|
40 | local cur prev words cword split
|
41 |
|
42 | echo
|
43 | echo -n 'case["_init_completion_flags"] = '; argv "$@"
|
44 | _init_completion "$@"
|
45 |
|
46 | echo
|
47 | show_init_completion_vars
|
48 | }
|
49 |
|
50 | noflags() { echo; }
|
51 | comp_noflags() { _comp_init_completion; }
|
52 | complete -F comp_noflags noflags
|
53 |
|
54 | s() { echo; }
|
55 | comp_s() { _comp_init_completion -s ; }
|
56 | complete -F comp_s s
|
57 |
|
58 | n() { echo; }
|
59 | comp_n() { _comp_init_completion -n = ; }
|
60 | complete -F comp_n n
|
61 |
|
62 | n2() { echo; }
|
63 | comp_n2() { _comp_init_completion -n := ; }
|
64 | complete -F comp_n2 n2
|
65 |
|
66 | _reassemble_helper() {
|
67 | show_bash_api_vars "$@"
|
68 | local words cword # assigned
|
69 |
|
70 | echo
|
71 | echo -n 'case["_completion_reassemble_flags"] = '; argv "$@"
|
72 | #_completion_reassemble "$@"
|
73 | __reassemble_comp_words_by_ref "$@"
|
74 |
|
75 | echo
|
76 | echo -n 'case["words"] = '; argv "${words[@]}"
|
77 | echo -n 'case["cword"] = '; argv1 "$cword"
|
78 | }
|
79 | _reassemble() {
|
80 | _reassemble_helper : words cword
|
81 | }
|
82 | complete -F _reassemble reassemble
|
83 |
|
84 |
|
85 | _words_helper() {
|
86 | show_bash_api_vars "$@"
|
87 | local cur # assigned
|
88 |
|
89 | echo
|
90 | echo -n 'case["_completion_words_flags"] = '; argv "$@"
|
91 | #_completion_words "$@"
|
92 | _get_comp_words_by_ref "$@"
|
93 |
|
94 | echo
|
95 | echo -n 'case["cur"] = '; argv1 "$cur"
|
96 | }
|
97 | _words() {
|
98 | _words_helper cur
|
99 | }
|
100 | complete -F _words words
|