aboutsummaryrefslogtreecommitdiffstats
path: root/completions/_rsp
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-06-06 19:48:22 +0300
committersalmonik <raisersoft@proton.me>2026-06-06 19:48:22 +0300
commitd347d89dfeef54d648ffdea054897617c0016509 (patch)
tree0ea0e25e2a8e9bcdd8c06ffadbe29721a7f07f77 /completions/_rsp
parentdirty, broken commit (diff)
downloadrsplayer-d347d89dfeef54d648ffdea054897617c0016509.tar.gz
rsplayer-d347d89dfeef54d648ffdea054897617c0016509.zip
correctly working auto completion for db
Diffstat (limited to 'completions/_rsp')
-rw-r--r--completions/_rsp67
1 files changed, 37 insertions, 30 deletions
diff --git a/completions/_rsp b/completions/_rsp
index 1ddc1fe..9bf0579 100644
--- a/completions/_rsp
+++ b/completions/_rsp
@@ -1,55 +1,62 @@
1# Dynamic completion overrides for rsp play/queue arguments.
2
3# Save clap-generated function so we can delegate non-dynamic cases. 1# Save clap-generated function so we can delegate non-dynamic cases.
4functions[_rsp_clap]=$functions[_rsp] 2functions[_rsp_clap]=$functions[_rsp]
5 3
6_rsp() { 4_rsp() {
7 case $words[2] in 5 case $words[2] in
8 play|queue) 6 play|queue)
9 _rsp_complete_args 7 if (( CURRENT > 2 )); then
10 ;; 8 _rsp_complete_args
11 *) 9 return 0
12 _rsp_clap "$@" 10 fi
13 ;; 11 ;;
14 esac 12 esac
13 _rsp_clap "$@"
15} 14}
16 15
17_rsp_complete_args() { 16_rsp_complete_args() {
18 setopt localoptions 17 setopt localoptions
19 setopt nobanghist 18 setopt nobanghist
20 # Reconstruct full query from all argument words after subcommand.
21 # This handles spaces in names (e.g. "Master of Puppets") that get
22 # split across multiple $words entries when backslash escaping breaks.
23 local -a args=("${(@)words[3,$CURRENT]}") 19 local -a args=("${(@)words[3,$CURRENT]}")
24 local cur="${(j: :)args}" 20 local cur="${(j: :)args}"
21 local cur_clean="${cur//\\/}"
25 local -a suggestions 22 local -a suggestions
26 local n_slashes=${#cur//[^\/]/} 23 suggestions=("${(@f)"$(rsp db-complete "$cur" 2>/dev/null)"}")
27 case $n_slashes in 24 # Filter out empty entries (e.g. from empty command output)
28 0) suggestions=(${(f)"$(rsp db-complete artists "$cur" 2>/dev/null)"}) ;; 25 local -a filtered=()
29 1) suggestions=(${(f)"$(rsp db-complete albums "$cur" 2>/dev/null)"}) ;;
30 *) suggestions=(${(f)"$(rsp db-complete tracks "$cur" 2>/dev/null)"}) ;;
31 esac
32 # display: what the user sees in the completion menu (raw values)
33 local -a display=("${suggestions[@]}")
34 # vals: what gets inserted (with ZSH backslash escaping + ! escape)
35 local -a vals=()
36 local slash_idx=$cur[(I)/]
37 local s
38 for s in "${suggestions[@]}"; do 26 for s in "${suggestions[@]}"; do
39 local esc="${(q)s:gs/\!/\\\!/}" 27 if [[ -n "$s" ]]; then
40 if (( slash_idx )); then 28 filtered+=("$s")
41 local dir_part=$cur[1,$slash_idx]
42 local edir="${(q)dir_part:gs/\!/\\\!/}"
43 vals+=("${edir}${esc}")
44 else
45 vals+=("${esc}")
46 fi 29 fi
47 done 30 done
31 suggestions=("${filtered[@]}")
48 if (( ${#suggestions} )); then 32 if (( ${#suggestions} )); then
33 local noslash="${cur_clean//\/}"
34 local n_slashes=$(( ${#cur_clean} - ${#noslash} ))
35 local -a display=()
36 local -a vals=()
37 for s in "${suggestions[@]}"; do
38 vals+=("$s")
39 if [[ "$cur_clean" == */ ]]; then
40 local stripped="$s"
41 local i=0
42 while (( i < n_slashes )); do
43 stripped="${stripped#*/}"
44 (( i++ ))
45 done
46 display+=("$stripped")
47 else
48 display+=("$s")
49 fi
50 done
51 if (( ${#suggestions} > 1 )); then
52 compstate[insert]=menu
53 fi
49 if [[ ${vals[1]} == */ ]]; then 54 if [[ ${vals[1]} == */ ]]; then
50 compadd -U -S '' -d display -- "${vals[@]}" 55 compadd -U -S '' -M 'm:{a-z}={A-Z} l:|=*' -d display -- "${vals[@]}"
51 else 56 else
52 compadd -U -d display -- "${vals[@]}" 57 compadd -U -M 'm:{a-z}={A-Z} l:|=*' -d display -- "${vals[@]}"
53 fi 58 fi
59 else
60 compadd -U -S ''
54 fi 61 fi
55} 62}