2

I created my own zsh completion function for audtool. Here's a sample:-

#compdef audtool

_audtool() { 
    local state

_arguments \
    '1: :->csi'\

case $state in
csi)
    _arguments '1::(
    --current-song
    --current-song-filename 
    --help
    --playlist-addurl)'
;;
esac
}

_audtool "$@"

The above function runs just fine except for one small glitch i.e., after the autocomplete when I try to add a path to a file the path doesn't expand. What I want to ask is that why doesn't

audtool --playlist-addurl /h

expand to

audtool --playlist-addurl /home/ 

after pressing Tab.

If anybody can help me with this. Thank you!

1

I solved it. To add an argument such that it displays full path all I had to do is add these lines:

_arguments '*:filename:_files'

So, the final function looks like:

#compdef audtool

_audtool() { 
    local curcontext="$curcontext" state line
    typeset -A opt_args

    _arguments \
        '1: :->csi'\
        '2: :->file'

    case $state in
    csi)
        _arguments '1: :(
            --current-song
            --current-song-filename 
            --current-song-length
            --playlist-addurl)'
    ;;
    file)
        _arguments '*:filename:_files'
    ;;
    esac
}

_audtool "$@"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.