Commit 65e89d96 authored by Frank Terbeck's avatar Frank Terbeck

Initialise atag with the first call to atag

Doing it in the init-atag call takes somewhere between 10 and 15ms, which is a
lot if you try to cut down startup times by as much as you can.
Signed-off-by: Frank Terbeck's avatarFrank Terbeck <ft@bewatermyfriend.org>
parent b1f86e86
......@@ -8,18 +8,6 @@
# from audio files. See the `ATAG__licence()' function below for
# licensing information.
emulate -L zsh
setopt warn_create_global no_ksh_arrays
local bin
zstyle -s ':atag:-init-:-all-' backend bin || bin='amded'
[[ ${bin} != /* ]] && bin=${commands[$bin]}
if [[ -z ${bin} ]] || [[ ! -x ${bin} ]]; then
if [[ $1 != '-q' ]]; then
printf 'Cannot find `amded'\''; atag needs it, abort.\n'
fi
return 1
fi
typeset -gA ATAG__mapping
ATAG__mapping=(
# General file information:
......@@ -58,38 +46,6 @@ ATAG__mapping=(
track-number-padded tnp
)
local line
typeset -ga ATAG__setables
while IFS= read -r line; do
ATAG__setables+=( "$line" )
done < <( command "$bin" -s tags )
typeset -ga ATAG__extensions
while IFS= read -r line; do
ATAG__extensions+=( "$line" )
done < <( command "$bin" -s file-extensions )
unset bin
local tag name
for tag in $ATAG__setables; do
if ! (( ${+ATAG__mapping[$tag]} )); then
printf 'atag: `%s'\'' is missing an abbreviated version.\n' "$tag"
fi
done
typeset -ga ATAG__descriptions
for tag in $ATAG__setables; do
name=${tag//-/ }
ATAG__descriptions+=( "${tag}=:Set $name tag" )
if (( ${+ATAG__mapping[$tag]} )); then
ATAG__descriptions+=( "${ATAG__mapping[$tag]}=:Set $name tag" )
fi
done
unset tag name
function ATAG__licence() {
emulate -L zsh
cat << __EOF__
......@@ -433,40 +389,89 @@ function ATAG__set_variables() {
return 0
}
function atag() {
function atag () {
emulate -L zsh
setopt extendedglob nullglob noksharrays
local file
local -i retval
local -a tags
local -A opts
opts=( pad 2 )
if (( $# < 1 )); then
printf 'Try "atag -h" for help.\n'
return 1
fi
ATAG__pre_file_options "$@" || return $retval
if (( $# > 0 )); then
file="$1"
shift
else
printf 'Need a file to work on. See "atag -h" for details.\n'
return 1
fi
if [[ -n ${file} ]] && [[ ! -e ${file} ]] ; then
printf 'Cannot access `%s'\'': file does not exist.\n' "$file"
setopt warn_create_global no_ksh_arrays
local bin
zstyle -s ':atag:-init-:-all-' backend bin || bin='amded'
[[ ${bin} != /* ]] && bin=${commands[$bin]}
if [[ -z ${bin} ]] || [[ ! -x ${bin} ]]; then
if [[ $1 != '-q' ]]; then
printf 'Cannot find `amded'\''; atag needs it, abort.\n'
fi
return 1
fi
ATAG__post_file_options "$@" || return 1
(( retval > 0 )) && shift ${retval}
if (( ${opts[setvars]} > 0 )) ; then
ATAG__set_variables ${file}
local line
typeset -ga ATAG__setables
while IFS= read -r line; do
ATAG__setables+=( "$line" )
done < <( command "$bin" -s tags )
typeset -ga ATAG__extensions
while IFS= read -r line; do
ATAG__extensions+=( "$line" )
done < <( command "$bin" -s file-extensions )
unset bin
local tag name
for tag in $ATAG__setables; do
if ! (( ${+ATAG__mapping[$tag]} )); then
printf 'atag: `%s'\'' is missing an abbreviated version.\n' "$tag"
fi
done
typeset -ga ATAG__descriptions
for tag in $ATAG__setables; do
name=${tag//-/ }
ATAG__descriptions+=( "${tag}=:Set $name tag" )
if (( ${+ATAG__mapping[$tag]} )); then
ATAG__descriptions+=( "${ATAG__mapping[$tag]}=:Set $name tag" )
fi
done
unset tag name
function atag() {
emulate -L zsh
setopt extendedglob nullglob noksharrays
local file
local -i retval
local -a tags
local -A opts
opts=( pad 2 )
if (( $# < 1 )); then
printf 'Try "atag -h" for help.\n'
return 1
fi
ATAG__pre_file_options "$@" || return $retval
if (( $# > 0 )); then
file="$1"
shift
else
printf 'Need a file to work on. See "atag -h" for details.\n'
return 1
fi
if [[ -n ${file} ]] && [[ ! -e ${file} ]] ; then
printf 'Cannot access `%s'\'': file does not exist.\n' "$file"
return 1
fi
ATAG__post_file_options "$@" || return 1
(( retval > 0 )) && shift ${retval}
if (( ${opts[setvars]} > 0 )) ; then
ATAG__set_variables ${file}
return $?
fi
ATAG__set_tags "$@" || return 1
ATAG__amded_tag ${file}
return $?
fi
}
ATAG__set_tags "$@" || return 1
ATAG__amded_tag ${file}
atag "$@"
return $?
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment