Skip to content

Commit

Permalink
complete arguments for scripts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ianthehenry committed Feb 26, 2022
1 parent 9bd3325 commit 4725697
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions _sd
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 4725697

Please sign in to comment.