-
Notifications
You must be signed in to change notification settings - Fork 3
/
autocomplete.bash
230 lines (199 loc) · 10.1 KB
/
autocomplete.bash
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# AUTOMATICALLY GENERATED by `shtab`
_shtab_musescore_manager_option_strings=('-h' '--help' '--print-completion' '-C' '--config-file' '-b' '--backup' '-d' '--dry-run' '--catch-errors' '-m' '--mscore' '--save-in-mscore' '-e' '--executable' '-E' '--export' '--compress' '--remove-origin' '-V' '--version' '-v' '--verbose' '-k' '--color' '--no-color' '--diff' '--print-xml' '-c' '--clean-meta' '-D' '--delete-duplicates' '-i' '--distribute-fields' '-j' '--json' '-l' '--log' '-y' '--synchronize' '-S' '--set-field' '--metatag' '--metatag-meta' '--vbox' '--vbox-meta' '--title' '--subtitle' '--composer' '--lyricist' '-x' '--extract' '--extract-lyrics' '-r' '--remap' '--remap-lyrics' '-F' '--fix' '--fix-lyrics' '--rename' '-t' '--target' '--only-filename' '-A' '--alphanum' '-a' '--ascii' '-n' '--no-whitespace' '-K' '--skip-if-empty' '--list-fields' '--list-functions' '-L' '--list-files' '-g' '--glob' '--mscz' '--mscx' '-s' '--style' '--clean' '-Y' '--style-file' '--s3' '--styles-v3' '--s4' '--styles-v4' '--reset-small-staffs' '--list-fonts' '--text-font' '--title-font' '--musical-symbol-font' '--musical-text-font' '--staff-space' '--page-size' '--a4' '--din-a4' '--letter' '--margin' '--show-header' '--no-show-header' '--header-first-page' '--no-header-first-page' '--different-odd-even-header' '--no-different-odd-even-header' '--header' '--header-odd-even' '--show-footer' '--no-show-footer' '--footer-first-page' '--no-footer-first-page' '--different-odd-even-footer' '--no-different-odd-even-footer' '--footer' '--footer-odd-even')
_shtab_musescore_manager_pos_0_COMPGEN=_shtab_compgen_files
_shtab_musescore_manager__C_COMPGEN=_shtab_compgen_files
_shtab_musescore_manager___config_file_COMPGEN=_shtab_compgen_files
_shtab_musescore_manager__e_COMPGEN=_shtab_compgen_files
_shtab_musescore_manager___executable_COMPGEN=_shtab_compgen_files
_shtab_musescore_manager__Y_COMPGEN=_shtab_compgen_files
_shtab_musescore_manager___style_file_COMPGEN=_shtab_compgen_files
_shtab_musescore_manager___print_completion_choices=('bash' 'zsh' 'tcsh')
_shtab_musescore_manager__E_choices=('mscz' 'mscx' 'spos' 'mpos' 'pdf' 'svg' 'png' 'wav' 'mp3' 'ogg' 'flac' 'mid' 'midi' 'kar' 'musicxml' 'xml' 'mxl' 'brf' 'mei')
_shtab_musescore_manager___export_choices=('mscz' 'mscx' 'spos' 'mpos' 'pdf' 'svg' 'png' 'wav' 'mp3' 'ogg' 'flac' 'mid' 'midi' 'kar' 'musicxml' 'xml' 'mxl' 'brf' 'mei')
_shtab_musescore_manager___musical_symbol_font_choices=('Leland' 'Bravura' 'Emmentaler' 'Gonville' 'MuseJazz' 'Petaluma' 'Finale Maestro' 'Finale Broadway')
_shtab_musescore_manager___musical_text_font_choices=('Leland Text' 'Bravura Text' 'Emmentaler Text' 'Gonville Text' 'MuseJazz Text' 'Petaluma Text' 'Finale Maestro Text' 'Finale Broadway Text')
_shtab_musescore_manager_pos_0_nargs=*
_shtab_musescore_manager__h_nargs=0
_shtab_musescore_manager___help_nargs=0
_shtab_musescore_manager__b_nargs=0
_shtab_musescore_manager___backup_nargs=0
_shtab_musescore_manager__d_nargs=0
_shtab_musescore_manager___dry_run_nargs=0
_shtab_musescore_manager___catch_errors_nargs=0
_shtab_musescore_manager__m_nargs=0
_shtab_musescore_manager___mscore_nargs=0
_shtab_musescore_manager___save_in_mscore_nargs=0
_shtab_musescore_manager___compress_nargs=0
_shtab_musescore_manager___remove_origin_nargs=0
_shtab_musescore_manager__V_nargs=0
_shtab_musescore_manager___version_nargs=0
_shtab_musescore_manager__v_nargs=0
_shtab_musescore_manager___verbose_nargs=0
_shtab_musescore_manager__k_nargs=0
_shtab_musescore_manager___color_nargs=0
_shtab_musescore_manager___no_color_nargs=0
_shtab_musescore_manager___diff_nargs=0
_shtab_musescore_manager___print_xml_nargs=0
_shtab_musescore_manager__D_nargs=0
_shtab_musescore_manager___delete_duplicates_nargs=0
_shtab_musescore_manager__i_nargs=2
_shtab_musescore_manager___distribute_fields_nargs=2
_shtab_musescore_manager__j_nargs=0
_shtab_musescore_manager___json_nargs=0
_shtab_musescore_manager__l_nargs=2
_shtab_musescore_manager___log_nargs=2
_shtab_musescore_manager__y_nargs=0
_shtab_musescore_manager___synchronize_nargs=0
_shtab_musescore_manager__S_nargs=2
_shtab_musescore_manager___set_field_nargs=2
_shtab_musescore_manager___metatag_nargs=2
_shtab_musescore_manager___metatag_meta_nargs=2
_shtab_musescore_manager___vbox_nargs=2
_shtab_musescore_manager___vbox_meta_nargs=2
_shtab_musescore_manager__F_nargs=0
_shtab_musescore_manager___fix_nargs=0
_shtab_musescore_manager___fix_lyrics_nargs=0
_shtab_musescore_manager___only_filename_nargs=0
_shtab_musescore_manager__A_nargs=0
_shtab_musescore_manager___alphanum_nargs=0
_shtab_musescore_manager__a_nargs=0
_shtab_musescore_manager___ascii_nargs=0
_shtab_musescore_manager__n_nargs=0
_shtab_musescore_manager___no_whitespace_nargs=0
_shtab_musescore_manager___list_fields_nargs=0
_shtab_musescore_manager___list_functions_nargs=0
_shtab_musescore_manager__L_nargs=0
_shtab_musescore_manager___list_files_nargs=0
_shtab_musescore_manager___mscz_nargs=0
_shtab_musescore_manager___mscx_nargs=0
_shtab_musescore_manager__s_nargs=2
_shtab_musescore_manager___style_nargs=2
_shtab_musescore_manager___clean_nargs=0
_shtab_musescore_manager___s3_nargs=0
_shtab_musescore_manager___styles_v3_nargs=0
_shtab_musescore_manager___s4_nargs=0
_shtab_musescore_manager___styles_v4_nargs=0
_shtab_musescore_manager___reset_small_staffs_nargs=0
_shtab_musescore_manager___list_fonts_nargs=0
_shtab_musescore_manager___page_size_nargs=2
_shtab_musescore_manager___a4_nargs=0
_shtab_musescore_manager___din_a4_nargs=0
_shtab_musescore_manager___letter_nargs=0
_shtab_musescore_manager___show_header_nargs=0
_shtab_musescore_manager___no_show_header_nargs=0
_shtab_musescore_manager___header_first_page_nargs=0
_shtab_musescore_manager___no_header_first_page_nargs=0
_shtab_musescore_manager___different_odd_even_header_nargs=0
_shtab_musescore_manager___no_different_odd_even_header_nargs=0
_shtab_musescore_manager___header_nargs=3
_shtab_musescore_manager___header_odd_even_nargs=6
_shtab_musescore_manager___show_footer_nargs=0
_shtab_musescore_manager___no_show_footer_nargs=0
_shtab_musescore_manager___footer_first_page_nargs=0
_shtab_musescore_manager___no_footer_first_page_nargs=0
_shtab_musescore_manager___different_odd_even_footer_nargs=0
_shtab_musescore_manager___no_different_odd_even_footer_nargs=0
_shtab_musescore_manager___footer_nargs=3
_shtab_musescore_manager___footer_odd_even_nargs=6
# $1=COMP_WORDS[1]
_shtab_compgen_files() {
compgen -f -- $1 # files
}
# $1=COMP_WORDS[1]
_shtab_compgen_dirs() {
compgen -d -- $1 # recurse into subdirs
}
# $1=COMP_WORDS[1]
_shtab_replace_nonword() {
echo "${1//[^[:word:]]/_}"
}
# set default values (called for the initial parser & any subparsers)
_set_parser_defaults() {
local subparsers_var="${prefix}_subparsers[@]"
sub_parsers=${!subparsers_var-}
local current_option_strings_var="${prefix}_option_strings[@]"
current_option_strings=${!current_option_strings_var}
completed_positional_actions=0
_set_new_action "pos_${completed_positional_actions}" true
}
# $1=action identifier
# $2=positional action (bool)
# set all identifiers for an action's parameters
_set_new_action() {
current_action="${prefix}_$(_shtab_replace_nonword $1)"
local current_action_compgen_var=${current_action}_COMPGEN
current_action_compgen="${!current_action_compgen_var-}"
local current_action_choices_var="${current_action}_choices[@]"
current_action_choices="${!current_action_choices_var-}"
local current_action_nargs_var="${current_action}_nargs"
if [ -n "${!current_action_nargs_var-}" ]; then
current_action_nargs="${!current_action_nargs_var}"
else
current_action_nargs=1
fi
current_action_args_start_index=$(( $word_index + 1 ))
current_action_is_positional=$2
}
# Notes:
# `COMPREPLY`: what will be rendered after completion is triggered
# `completing_word`: currently typed word to generate completions for
# `${!var}`: evaluates the content of `var` and expand its content as a variable
# hello="world"
# x="hello"
# ${!x} -> ${hello} -> "world"
_shtab_musescore_manager() {
local completing_word="${COMP_WORDS[COMP_CWORD]}"
local completed_positional_actions
local current_action
local current_action_args_start_index
local current_action_choices
local current_action_compgen
local current_action_is_positional
local current_action_nargs
local current_option_strings
local sub_parsers
COMPREPLY=()
local prefix=_shtab_musescore_manager
local word_index=0
_set_parser_defaults
word_index=1
# determine what arguments are appropriate for the current state
# of the arg parser
while [ $word_index -ne $COMP_CWORD ]; do
local this_word="${COMP_WORDS[$word_index]}"
if [[ -n $sub_parsers && " ${sub_parsers[@]} " == *" ${this_word} "* ]]; then
# valid subcommand: add it to the prefix & reset the current action
prefix="${prefix}_$(_shtab_replace_nonword $this_word)"
_set_parser_defaults
fi
if [[ " ${current_option_strings[@]} " == *" ${this_word} "* ]]; then
# a new action should be acquired (due to recognised option string or
# no more input expected from current action);
# the next positional action can fill in here
_set_new_action $this_word false
fi
if [[ "$current_action_nargs" != "*" ]] && \
[[ "$current_action_nargs" != "+" ]] && \
[[ "$current_action_nargs" != *"..." ]] && \
(( $word_index + 1 - $current_action_args_start_index >= \
$current_action_nargs )); then
$current_action_is_positional && let "completed_positional_actions += 1"
_set_new_action "pos_${completed_positional_actions}" true
fi
let "word_index+=1"
done
# Generate the completions
if [[ "${completing_word}" == -* ]]; then
# optional argument started: use option strings
COMPREPLY=( $(compgen -W "${current_option_strings[*]}" -- "${completing_word}") )
else
# use choices & compgen
local IFS=$'\n' # items may contain spaces, so delimit using newline
COMPREPLY=( $([ -n "${current_action_compgen}" ] \
&& "${current_action_compgen}" "${completing_word}") )
unset IFS
COMPREPLY+=( $(compgen -W "${current_action_choices[*]}" -- "${completing_word}") )
fi
return 0
}
complete -o filenames -F _shtab_musescore_manager musescore-manager