Frage

I have a custom function and zsh gives me default tab completion for it. It completes paths from current working directory. That's great, but I'd like the completion (only for this particular function) to behave a little bit differently: as if I was always in a specific directory.

Can this be achieved with very little work? I'd love something like compdef myfunc="cd /my/dir"...

To add some context, my function looks like this:

play() {
    (
        cd ~/Music/mp3 &&
        do-sth $1 &&
        open -a itunes $1
    )
}

and I would like to be able to do things like:

$ ls ~/Music/mp3
Slayer
$ cd ~
$ play S<tab>  # expands to "Slayer"
War es hilfreich?

Lösung

I have a similar solution for switching directories to my code projects. Something like this might do the trick for you:

play() { open -a itunes ~/Music/mp3/$@; }
compctl -/ -W ~/Music/mp3 play
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top