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
|
#compdef arename
# Z-Shell completion function for arename.
# <http://ft.bewatermyfriend.org/comp/arename.html>
#
# Note: The first time this function is called may take longer than the
# others. The reason for this is that the function asks `arename'
# about it's supported file types and extensions. These are kept in
# memory in later calls, so later invocations are instantaneous.
#
# Written by Frank Terbeck <ft@bewatermyfriend.org>.
#
# Distributed with arename, under the same terms as arename itself
# (2-clause BSD); See the LICENCE file which is included in the
# arename distribution.
local line
typeset -ga _arename_types
typeset -ga _arename_extensions
_arename_types=( )
_arename_extensions=( )
arename --list-file-types | while read line; do
_arename_types+=( "$line" )
done
arename --list-exts-for-type "${(j@,@)_arename_types}" | while read line; do
_arename_extensions+=( "$line" )
done
function _arename_files() {
_path_files -g "(#i)*.(${(j:|:)_arename_extensions})(.)" -g "*(-/)"
}
function _arename_comma() {
local expl tag
local -a already
tag="$1"
shift
compset -P '*,'
already=(${(s<,>)IPREFIX})
_wanted list expl "$tag" compadd -S, -F already -q ${expl} -- "$@"
}
function _arename_types() {
_arename_comma 'file type' ${_arename_types}
}
function _arename_profiles() {
_arename_comma 'profile' ${(f)"$(arename --list-profiles)"}
}
function _arename() {
local -a arguments
arguments=(
'--ambiguous-use-first[if a tag has multiple values, use the 1st]:'
'--compare-versions[compare versions of script and module]:'
'(--copy -c)'{--copy,-c}'[copy files, rather than rename]'
'(--debug -D)'{--debug,-D}'[enable debugging output]'
'(--disable-hooks -H)'{--disable-hooks,-H}'[disable all hooks]'
'(--disable-profiles -N)'{--disable-profiles,-N}'[disable all profiles]'
'(--dryrun -d)'{--dryrun,-d}'[go into dry-run mode]'
'--enable-hooks[enable hooks, if they are disabled in the configuration]'
'(--force -f)'{--force,-f}'[overwrite file(s) if needed]'
'(--help -h)'{--help,-h}'[display help information]:'
'(--list-cfg -L)'{--list-cfg,-L}'[list current configuration]:'
'--list-file-types[list file types]:'
'--list-exts-for-type[list extensions for a file type]:file type:_arename_types'
'(--list-profiles -S)'{--list-profiles,-S}'[list all profiles in active configuration]:'
'(--read-local -l)'{--read-local,-l}'[read local config file]'
'(--stdin -s)'{--stdin,-s}'[read filenames from stdin]'
'(--suppress-skips -Q)'{--suppress-skips,-Q}'[Don'\''t display data of skipped files]'
'(--verbosity -v)'{--verbosity,-v}'[set verbosity]:verbosity value:_guard "[0-9]#" "numeric value"'
'(--version -V)'{--version,-V}'[display version infomation]:'
'--rc[read a file instead of ~/.arenamerc]:config file:_files'
'--post-rc[read a file in addition to ~/.arenamerc]:config file:_files'
'(--prefix -p)'{--prefix,-p}'[define a directory prefix for destination file(s)]:directory prefix:_path_files -g '\''*(-/)'\'
'(--profile -P)'{--profile,-P}'[force the use of certain profile(s)]:profile(s):_arename_profiles'
'(--compilation-template -T)'{--compilation-template,-T}'[define a compilation template]:compilation template:'
'(--template -t)'{--template,-t}'[define a generic template]:template:'
'*'{--userset,-u}'[set a user variable]:user variable (format var=value):'
'*:audio files:_arename_files'
)
_arguments -s "${arguments[@]}"
}
_arename "$@"
|