Skip to content

Commit

Permalink
Merge pull request #5081 from mthies-unibi/zsh-completion-fixes
Browse files Browse the repository at this point in the history
Fixes zsh completion dependency on specific awk/sed/sqlite3 versions and settings
  • Loading branch information
Serene-Arc authored Jan 17, 2024
2 parents 5c964ce + 35af8d3 commit ddb34de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
7 changes: 4 additions & 3 deletions extra/_beet
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ddb34de

Please sign in to comment.