aboutsummaryrefslogtreecommitdiffstats
path: root/completions/_rsp
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-06-04 00:21:46 +0200
committersalmonik <raisersoft@proton.me>2026-06-04 00:21:46 +0200
commit1e48765ab39a679abcc4eac6927ad3bb58f7b438 (patch)
tree5554f2a06bde693d4d9c39ed26f80677d61da991 /completions/_rsp
parentfix no metadata songs handling (diff)
downloadrsplayer-1e48765ab39a679abcc4eac6927ad3bb58f7b438.tar.gz
rsplayer-1e48765ab39a679abcc4eac6927ad3bb58f7b438.zip
dirty, broken commit
Diffstat (limited to '')
-rw-r--r--completions/_rsp55
1 files changed, 55 insertions, 0 deletions
diff --git a/completions/_rsp b/completions/_rsp
new file mode 100644
index 0000000..1ddc1fe
--- /dev/null
+++ b/completions/_rsp
@@ -0,0 +1,55 @@
1# Dynamic completion overrides for rsp play/queue arguments.
2
3# Save clap-generated function so we can delegate non-dynamic cases.
4functions[_rsp_clap]=$functions[_rsp]
5
6_rsp() {
7 case $words[2] in
8 play|queue)
9 _rsp_complete_args
10 ;;
11 *)
12 _rsp_clap "$@"
13 ;;
14 esac
15}
16
17_rsp_complete_args() {
18 setopt localoptions
19 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]}")
24 local cur="${(j: :)args}"
25 local -a suggestions
26 local n_slashes=${#cur//[^\/]/}
27 case $n_slashes in
28 0) suggestions=(${(f)"$(rsp db-complete artists "$cur" 2>/dev/null)"}) ;;
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
39 local esc="${(q)s:gs/\!/\\\!/}"
40 if (( slash_idx )); then
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
47 done
48 if (( ${#suggestions} )); then
49 if [[ ${vals[1]} == */ ]]; then
50 compadd -U -S '' -d display -- "${vals[@]}"
51 else
52 compadd -U -d display -- "${vals[@]}"
53 fi
54 fi
55}