Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zsh completion: use paths from specific dir, not the current one

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"
like image 528
Maciej Konieczny Avatar asked Dec 20 '25 07:12

Maciej Konieczny


1 Answers

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
like image 140
Frost Avatar answered Dec 23 '25 20:12

Frost



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!