knqyf263 / pet

Simple command-line snippet manager
MIT License
4.41k stars 222 forks source link

Add autocompletion for Pet #289

Open RamiAwar opened 6 months ago

RamiAwar commented 6 months ago

This is not greatly useful for pet users yet, but in doing this I'll gather up some more knowledge about autocompletion and will then be able to judge whether or not it's possible to build autocompletions that rely on dynamic output from pet.

Couldn't tell from basic research, and this is a nice to have anyways.

RamiAwar commented 6 months ago

Still need to look into this, but I have something working.

ZSH autocompletion template:



# Define completion function for the 'pet' command
_pet_complete() {
    local -a pet_commands=("new" "edit" "search" "exec")

    _arguments -C \
        '1: :->command' \
        '*::arg:->args'

    case $state in
        (command)
            # Complete the command based on the list of commands
            _describe 'command' pet_commands
            ;;
        (args)
            # Do nothing for now, you can add additional completions for command arguments here
            ;;
    esac
}

# Register completion function
_zstyle ':completion:*:pet:*' completer _pet_complete

# Call the completion function
_pet_complete "$@"```