|
2 | 2 |
|
3 | 3 | # zsh completion for beets music library manager and MusicBrainz tagger: http://beets.radbox.org/
|
4 | 4 |
|
5 |
| -# IMPORTANT: You need to change the $completionsdir variable defined below to point to the directory where your completion files |
6 |
| -# are stored. |
7 |
| -# It will be very slow the first time you try to complete in a zsh shell (especially if you've enable many plugins), |
8 |
| -# but a cache file (_beet_cached) will be created after the first completion which will make subsequent calls much |
9 |
| -# faster. |
10 |
| -# If you enable new plugins or fields you should update the cache file by deleting it, entering the following commands: |
11 |
| -# unfunction _beet |
12 |
| -# autoload -z _beet |
13 |
| -# and then performing another completion in a new shell. |
14 |
| - |
15 |
| -# If cache file exists, use that |
16 |
| -local completionsdir="$HOME/.oh-my-zsh/custom/completions" |
17 |
| -local cachefile=$completionsdir/_beet_cached |
18 |
| -if [[ -r "$cachefile" ]]; then |
19 |
| - source "$cachefile" |
20 |
| - _beet "$@" |
21 |
| - return |
22 |
| -fi |
| 5 | +# NOTE: it will be very slow the first time you try to complete in a zsh shell (especially if you've enable many plugins) |
| 6 | +# You can make it faster in future by creating a cached version: |
| 7 | +# 1) perform a query completion with this file (_beet), e.g. do: beet list artist:"<TAB> |
| 8 | +# to create the completion function (takes a few seconds) |
| 9 | +# 2) save a copy of the completion function: which _beet > _beet_cached |
| 10 | +# 3) save a copy of the query completion function: which _beet_query > _beet_query_cached |
| 11 | +# 4) copy the contents of _beet_query_cached to the top of _beet_cached |
| 12 | +# 5) copy and paste the _beet_field_values function from _beet to the top of _beet_cached |
| 13 | +# 6) add the following line to the top of _beet_cached: #compdef beet |
| 14 | +# 7) add the following line to the bottom of _beet_cached: _beet "$@" |
| 15 | +# 8) save _beet_cached to your completions directory (e.g. /usr/share/zsh/functions/Completion) |
| 16 | +# 9) add the following line to your .zshrc file: compdef _beet_cached beet |
| 17 | +# You will need to repeat this proceedure each time you enable new plugins if you want them to complete properly. |
23 | 18 |
|
24 | 19 | # useful: argument to _regex_arguments for matching any word
|
25 | 20 | local matchany=/$'[^\0]##\0'/
|
@@ -73,7 +68,8 @@ queryelem="_values -S : 'query field (add an extra : to match by regexp)' '::' $
|
73 | 68 | # store call to _values function for completing modify terms (no need to complete field values)
|
74 | 69 | modifyelem="_values -S = 'modify field (replace = with ! to remove field)' $(echo "'${^fields[@]}:: '")"
|
75 | 70 | # Create completion function for queries
|
76 |
| -_regex_arguments _beet_query "$matchany" \# \( "$matchquery" ":query:query string:$queryelem" \) \( "$matchquery" ":query:query string:$queryelem" \) \# |
| 71 | +_regex_arguments _beet_query "$matchany" \# \( "$matchquery" ":query:query string:$queryelem" \) \ |
| 72 | + \( "$matchquery" ":query:query string:$queryelem" \) \# |
77 | 73 | # store regexps for completing lists of queries and modifications
|
78 | 74 | local -a query modify
|
79 | 75 | query=( \( "$matchquery" ":query:query string:{_beet_query}" \) \( "$matchquery" ":query:query string:{_beet_query}" \) \# )
|
@@ -265,17 +261,6 @@ _regex_arguments _beet "$matchany" \( "${globalopts[@]}" \# \) "${subcmds[@]}"
|
265 | 261 | # Set tag-order so that options are completed separately from arguments
|
266 | 262 | zstyle ":completion:${curcontext}:" tag-order '! options'
|
267 | 263 |
|
268 |
| -# Save completion functions to _beet_cached |
269 |
| -echo "# Cached completion file for beet\n# Note: this was created from _beet, and should be regenerated when new fields or plugins are added.\n# To regenerate this file just delete it, open a new zshell and try completing beet.\n\n" > $cachefile |
270 |
| -which _beet_field_values >> $cachefile |
271 |
| -echo "\n\n" >> $cachefile |
272 |
| -which _beet_query >> $cachefile |
273 |
| -echo "\n\n" >> $cachefile |
274 |
| -which _beet >> $cachefile |
275 |
| -echo "\n\n" >> $cachefile |
276 |
| -echo zstyle \":completion:\${curcontext}:\" tag-order \'! options\' >> $cachefile |
277 |
| -echo "\n\n_beet \"\$@\"\n" >> $cachefile |
278 |
| - |
279 | 264 | # Execute the completion function
|
280 | 265 | _beet "$@"
|
281 | 266 |
|
|
0 commit comments