From 4ac442d6fbd440a86b0179c0c8e4237115424d56 Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 12 Jun 2026 13:32:40 +0300 Subject: improved ZSH autocompletion script --- completions/_rsp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'completions') diff --git a/completions/_rsp b/completions/_rsp index 9bf0579..89d122b 100644 --- a/completions/_rsp +++ b/completions/_rsp @@ -2,9 +2,17 @@ functions[_rsp_clap]=$functions[_rsp] _rsp() { + setopt nobanghist case $words[2] in play|queue) if (( CURRENT > 2 )); then + local cur="${words[$CURRENT]}" + if [[ "$words[2]" == "play" && "$cur" == -* ]]; then + local -a flags + flags=('-i' '--now' '-n' '--next' '-a' '--album') + _describe 'flags' flags + return 0 + fi _rsp_complete_args return 0 fi @@ -14,14 +22,14 @@ _rsp() { } _rsp_complete_args() { - setopt localoptions setopt nobanghist local -a args=("${(@)words[3,$CURRENT]}") local cur="${(j: :)args}" + # No completion if this is a flag (handled above) + [[ "$words[2]" == "play" && "$cur" == -* ]] && return 1 local cur_clean="${cur//\\/}" local -a suggestions suggestions=("${(@f)"$(rsp db-complete "$cur" 2>/dev/null)"}") - # Filter out empty entries (e.g. from empty command output) local -a filtered=() for s in "${suggestions[@]}"; do if [[ -n "$s" ]]; then @@ -49,7 +57,7 @@ _rsp_complete_args() { fi done if (( ${#suggestions} > 1 )); then - compstate[insert]=menu + compstate[insert]= fi if [[ ${vals[1]} == */ ]]; then compadd -U -S '' -M 'm:{a-z}={A-Z} l:|=*' -d display -- "${vals[@]}" -- cgit v1.2.3