From 4725697fa7e46ab5cd4c087dfc894d1095a9466a Mon Sep 17 00:00:00 2001 From: Ian Henry Date: Sat, 26 Feb 2022 14:32:54 -0800 Subject: [PATCH] complete arguments for scripts When completion reaches a script, it will continue trying to complete positional arguments with the standard _files completer. It will also complete the built-in flags understood by sd, but only if you begin with a hyphen. It will also complete --new if you enter a script path that does not exist yet. --- _sd | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/_sd b/_sd index 4a27cd9..042b58a 100644 --- a/_sd +++ b/_sd @@ -31,12 +31,23 @@ function __list_commands { subcmds=($subcmds "$command:\"$help\"") done - _arguments -C ": :(($subcmds))" \ - "*::arg:->args" + _arguments -C ": :(($subcmds))" "*::arg:->args" next="$dir/$line[1]" if [[ ! -z $line[1] && -d "$next" ]]; then __list_commands "$next" + elif [[ ! -z $line[1] && -x "$next" ]]; then + # You could imagine wanting to customize the '*:file:_files' fallback + # at some point, but I'm not going to worry about that for now. + _arguments -A '-*' \ + '--help[print help text]' \ + '--cat[print script contents]' \ + '--which[print script path]' \ + '--edit[open script for editing]' \ + '--really[suppress special argument handling]' \ + '*:file:_files' + elif [[ ! -z $line[1] && ! -f "$next" ]]; then + _arguments "--new[create a new script]" fi }