120 lines
7.6 KiB
Plaintext
120 lines
7.6 KiB
Plaintext
#compdef beet
|
|
|
|
# completion for beets music library manager and MusicBrainz tagger: http://beets.radbox.org/
|
|
|
|
local matchany queryelem modifyelem newfields
|
|
local matchquery matchmodify
|
|
local -a reply files dirs query modify fields
|
|
fields=(acoustid_fingerprint acoustid_id added album album_id albumartist albumartist_credit albumartist_sort albumdisambig albumstatus albumtype artist artist_credit artist_sort artpath asin bitdepth bitrate bpm catalognum channels comments comp composer country day disc disctitle disctotal encoder format genre grouping id initial_key label language length lyrics mb_albumartistid mb_albumid mb_artistid mb_releasegroupid mb_trackid media month mtime original_day original_month original_year path rg_album_gain rg_album_peak rg_track_gain rg_track_peak samplerate script title track tracktotal year)
|
|
# matches any word
|
|
matchany=/$'[^\0]##\0'/
|
|
# Put the fields into a format for use in the _values function
|
|
newfields=$(echo "'${^fields[@]}::'")
|
|
matchquery=/"(${(j/|/)fields[@]})"$':[^\0]##\0'/
|
|
matchmodify=/"(${(j/|/)fields[@]})"$'(=[^\0]##|!)\0'/
|
|
# complete a query term
|
|
queryelem="_values -S : 'query field (add an extra : to match by regexp)' '::' $newfields"
|
|
# complete a modify term
|
|
modifyelem="_values -S = 'modify field (replace = with ! to remove field)' $newfields"
|
|
# complete lists of queries and modifications (at least one query/modify string is needed in each case)
|
|
query=( \( "$matchquery" ":query:query string:$queryelem" \) \( "$matchquery" ":query:query string:$queryelem" \) \# )
|
|
modify=( \( "$matchmodify" ":modify:modify string:$modifyelem" \) \( "$matchmodify" ":modify:modify string:$modifyelem" \) \# )
|
|
# complete files and directories
|
|
files=("$matchany" ':type:type:_files')
|
|
dirs=("$matchany" ':type:type:_dirs')
|
|
# Individual options used by subcommands, and global options (must be single quoted).
|
|
local helpopt formatopt albumopt dontmoveopt writeopt nowriteopt pretendopt pathopt destopt copyopt nocopyopt
|
|
local inferopt noinferopt resumeopt noresumeopt nopromptopt logopt individualopt confirmopt retagopt skipopt noskipopt
|
|
local flatopt groupopt editopt defaultopt noconfirmopt exactopt removeopt configopt debugopt
|
|
helpopt='-h:show this help message and exit'
|
|
formatopt='-f:print with custom format:$matchany'
|
|
albumopt='-a:match albums instead of tracks'
|
|
dontmoveopt='-M:dont move files in library'
|
|
writeopt='-w:write new metadata to files tags (default)'
|
|
nowriteopt='-W:dont write metadata (opposite of -w)'
|
|
pretendopt='-p:show all changes but do nothing'
|
|
pathopt='-p:print paths for matched items or albums'
|
|
destopt='-d:destination music directory:$dirs'
|
|
copyopt='-c:copy tracks into library directory (default)'
|
|
nocopyopt='-C:dont copy tracks (opposite of -c)'
|
|
inferopt='-a:infer tags for imported files (default)'
|
|
noinferopt='-A:dont infer tags for imported files (opposite of -a)'
|
|
resumeopt='-p:resume importing if interrupted'
|
|
noresumeopt='-P:do not try to resume importing'
|
|
nopromptopt='-q:never prompt for input, skip albums instead'
|
|
logopt='-l:file to log untaggable albums for later review:$files'
|
|
individualopt='-s:import individual tracks instead of full albums'
|
|
confirmopt='-t:always confirm all actions'
|
|
retagopt='-L:retag items matching a query:${query[@]}'
|
|
skipopt='-i:skip already-imported directories'
|
|
noskipopt='-I:do not skip already-imported directories'
|
|
flatopt='--flat:import an entire tree as a single album'
|
|
groupopt='-g:group tracks in a folder into seperate albums'
|
|
editopt='-e:edit user configuration with $EDITOR'
|
|
defaultopt='-d:include the default configuration'
|
|
copynomoveopt='-c:copy instead of moving'
|
|
noconfirmopt='-y:skip confirmation'
|
|
exactopt='-e:get exact file sizes'
|
|
removeopt='-d:also remove files from disk'
|
|
configopt='-c:path to configuration file:$files'
|
|
debugopt='-v:print debugging information'
|
|
libopt='-l:library database file to use:$files'
|
|
# Option lists for different subcommands
|
|
local -a moveopts configopts writeopts modifyopts statsopts removeopts updateopts importopts listopts globalopts
|
|
_regex_words options "move options" "$helpopt" "$albumopt" "$destopt" "$copynomoveopt"
|
|
moveopts=( "${reply[@]}" \# "${query[@]}")
|
|
_regex_words options "config options" "$helpopt" "$pathopt" "$editopt" "$defaultopt"
|
|
configopts=("${reply[@]}")
|
|
_regex_words options "write options" "$helpopt" "$pretendopt"
|
|
writeopts=( "${reply[@]}" \# "${query[@]}")
|
|
_regex_words options "modify options" "$helpopt" "$dontmoveopt" "$writeopt" "$nowriteopt" "$albumopt" "$noconfirmopt" "$formatopt"
|
|
modifyopts=( "${reply[@]}" \# "${query[@]}" "${modify[@]}" )
|
|
_regex_words options "stats options" "$helpopt" "$exactopt"
|
|
statsopts=( "${reply[@]}" \# "${query[@]}" )
|
|
_regex_words options "remove options" "$helpopt" "$albumopt" "$removeopt"
|
|
removeopts=( "${reply[@]}" \# "${query[@]}" )
|
|
_regex_words options "update options" "$helpopt" "$albumopt" "$dontmoveopt" "$pretendopt" "$formatopt"
|
|
updateopts=( "${reply[@]}" \# "${query[@]}" )
|
|
_regex_words options "import options" "$helpopt" "$writeopt" "$nowriteopt" "$copyopt" "$nocopyopt" "$inferopt" \
|
|
"$noinferopt" "$resumeopt" "$noresumeopt" "$nopromptopt" "$logopt" "$individualopt" "$confirmopt" "$retagopt" \
|
|
"$skipopt" "$noskipopt" "$flatopt" "$groupopt"
|
|
importopts=( "${reply[@]}" \# "${files[@]}" \# )
|
|
_regex_words options "list options" "$helpopt" "$pathopt" "$albumopt" "$formatopt"
|
|
listopts=( "$reply[@]" \# "${query[@]}" )
|
|
_regex_words options "global options" "$configopt" "$debugopt" "$libopt" "$helpopt" "$destopt"
|
|
globalopts=( "${reply[@]}" )
|
|
# Subcommands (must be single quoted).
|
|
local fieldscmd importcmd listcmd updatecmd removecmd statscmd versioncmd
|
|
local modifycmd movecmd writecmd configcmd migratecmd helpcmd
|
|
fieldscmd='fields:show fields available for queries and format strings'
|
|
importcmd='import:import new music:$importopts'
|
|
listcmd='list:query the library:${listopts[@]}'
|
|
updatecmd='update:update all tracks in the library that match a query:${updateopts[@]}'
|
|
removecmd='remove:remove matching items from the library:${removeopts[@]}'
|
|
statscmd='stats:show statistics about the library or a query:${statsopts[@]}'
|
|
versioncmd='version:output version information'
|
|
modifycmd='modify:change metadata fields:${modifyopts[@]}'
|
|
movecmd='move:move or copy items:${moveopts[@]}'
|
|
writecmd='write:write tag information to files:${writeopts[@]}'
|
|
configcmd='config:show or edit the user configuration:${configopts[@]}'
|
|
migratecmd='migrate:convert legacy config'
|
|
helpcmd='help:give detailed help on a specific sub-command:${beet_help_args[@]}'
|
|
# Help completion
|
|
local -a beet_help_args subcmds
|
|
beet_help_args=(/$'(fields|import|list|update|remove|stats|version|modify|move|write|config|migrate)\0'/ ':cmd:command:((fields\:show\ fields\ available\ for\ queries\ and\ format\ strings import\:import\ new\ music list\:query\ the\ library update\:update\ all\ tracks\ in\ the\ library\ that\ match\ a\ query remove\:remove\ matching\ items\ from\ the\ library stats\:show\ statistics\ about\ the\ library\ or\ a\ query version\:output\ version\ information modify\:change\ metadata\ fields move\:move\ or\ copy\ items write\:write\ tag\ information\ to\ files config\:show\ or\ edit\ the\ user\ configuration migrate\:convert\ legacy\ config))')
|
|
# Subcommands
|
|
_regex_words subcmds "subcommands" "$fieldscmd" "$importcmd" "$listcmd" "$updatecmd" "$removecmd" "$statscmd" \
|
|
"$versioncmd" "$modifycmd" "$movecmd" "$writecmd" "$configcmd" "$migratecmd" "$helpcmd"
|
|
subcmds=("$reply[@]")
|
|
# Create main completion function
|
|
_regex_arguments _beet "$matchany" \( "${globalopts[@]}" \# \) "${subcmds[@]}"
|
|
# Set tag-order - complete options separately from arguments
|
|
zstyle ":completion:${curcontext}:" tag-order '! options'
|
|
|
|
# Execute the completion function
|
|
_beet "$@"
|
|
|
|
# Local Variables:
|
|
# mode:shell-script
|
|
# End:
|