OILS / testdata / completion / bash_oracle_plugins.sh View on Github | oilshell.org

100 lines, 76 significant
1# Common functions fed to 'sh -i' by init_completion.sh.
2
3# OSH should have this built in
4if ! type -t _init_completion; then
5 source testdata/completion/bash_completion
6fi
7
8argv() {
9 python -c 'import sys; print(sys.argv[1:])' "$@"
10}
11
12argv1() {
13 python -c 'import sys; print(repr(sys.argv[1]))' "$@"
14}
15
16comp_echo() {
17 echo
18 echo -n 'case["COMP_WORDS"] = '; argv "${COMP_WORDS[@]}"
19}
20complete -F comp_echo echo
21
22show_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
30show_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
50noflags() { echo; }
51comp_noflags() { _comp_init_completion; }
52complete -F comp_noflags noflags
53
54s() { echo; }
55comp_s() { _comp_init_completion -s ; }
56complete -F comp_s s
57
58n() { echo; }
59comp_n() { _comp_init_completion -n = ; }
60complete -F comp_n n
61
62n2() { echo; }
63comp_n2() { _comp_init_completion -n := ; }
64complete -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}
82complete -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}
100complete -F _words words