From c153f72e47c56cdc8e566c7f425a7be1d654995d Mon Sep 17 00:00:00 2001 From: Michael Thies Date: Mon, 15 Jan 2024 09:58:39 +0100 Subject: [PATCH 1/2] zsh completion script for the beet command is more portable now: - avoids the mawk-specific {,n} regex operator - a directly usable sqlite3 output format is selected explicitly, when retrieving suggestions for field values; this avoids the previously used GNU-sed-specific post-processing of the sqlite3 output - completion caching is enabled for the beet command and its parameter contexts, even if not enabled globally by the user; caching is required for field value suggestions --- extra/_beet | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/extra/_beet b/extra/_beet index c6121651d..c7b90749b 100644 --- a/extra/_beet +++ b/extra/_beet @@ -8,7 +8,8 @@ local BEETS_LIBRARY=~/.config/beets/library.db local BEETS_CONFIG=~/.config/beets/config.yaml # Use separate caches for file locations, command completions, and query completions. # This allows the use of different rules for when to update each one. -zstyle ":completion:${curcontext}:" cache-policy _beet_check_cache +zstyle ":completion:${curcontext%:*}:*" cache-policy _beet_check_cache +zstyle ":completion:${curcontext%:*}:*" use-cache true _beet_check_cache () { local cachefile="$(basename ${1})" if [[ ! -a "${1}" ]] || [[ "${1}" -ot =beet ]]; then @@ -51,7 +52,7 @@ if ! _retrieve_cache beetscmds || _cache_invalid beetscmds; then # Useful function for joining grouped lines of output into single lines (taken from _completion_helpers) _join_lines() { awk -v SEP="$1" -v ARG2="$2" -v START="$3" -v END2="$4" 'BEGIN {if(START==""){f=1}{f=0}; - if(ARG2 ~ "^[0-9]+"){LINE1 = "^[[:space:]]{,"ARG2"}[^[:space:]]"}else{LINE1 = ARG2}} + if(ARG2 ~ "^[0-9]+"){LINE1 = "^[[:space:]]{0,"ARG2"}[^[:space:]]"}else{LINE1 = ARG2}} ($0 ~ END2 && f>0 && END2!="") {exit} ($0 ~ START && f<1) {f=1; if(length(START)!=0){next}} ($0 ~ LINE1 && f>0) {if(f<2){f=2; printf("%s",$0)}else{printf("\n%s",$0)}; next} @@ -109,7 +110,7 @@ _beet_field_values() { if [[ "$(sqlite3 ${~BEETS_LIBRARY} ${sqlcmd} 2>&1)" =~ "no such column" ]]; then sqlcmd="select distinct value from item_attributes where key=='$1' and value!='';" fi - output="$(sqlite3 ${~BEETS_LIBRARY} ${sqlcmd} 2>/dev/null | sed -rn '/^-+$/,${{/^[- ]+$/n};p}')" + output="$(sqlite3 -list -noheader ${~BEETS_LIBRARY} ${sqlcmd} 2>/dev/null)" fieldvals=("${(f)output[@]}") ;; esac From 35af8d363a7e3b518365e13f4b838a1de38b8766 Mon Sep 17 00:00:00 2001 From: Michael Thies Date: Wed, 17 Jan 2024 10:36:56 +0100 Subject: [PATCH 2/2] added changelog entry --- docs/changelog.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index b3b63f1c2..810a5b85f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -281,6 +281,10 @@ Bug fixes: displayed unless the detail configuration is enabled. * :doc:`/plugins/web`: Fix range request support, allowing to play large audio/ opus files using e.g. a browser/firefox or gstreamer/mopidy directly. +* Fix bug where `zsh` completion script made assumptions about the specific + variant of `awk` installed and required specific settings for `sqlite3` + and caching in `zsh`. + :bug:`3546` For plugin developers: