drajc
drajc

Reputation: 115

List directories of different location in fish tab-completion

I would like to create a fish function that acts as a shortcut into a directory.

The function looks like this:

function mydir -d "Navigate to mydir and its subdirectories from anywhere"
    cd $HOME/some/path/mydir/$argv
end

The function works well, but I would like to add tab-completion. I currently have this for tab-completion:

complete --no-files --exclusive --command mydir --arguments "(__fish_complete_directories)"

The problem is that this will tab-complete to the directories in the current working directory. I would instead like it to tab-complete to the directories in $HOME/some/path/mydir/. I cannot find an example or flag in the documentation that would help me do this.

I do not know fish very well, but I thought one way to do this would be to manually loop over those directories and add them as options, but it doesn't feel right and I am struggling with that implementation anyway.

Upvotes: 2

Views: 674

Answers (1)

NotTheDr01ds
NotTheDr01ds

Reputation: 20638

Honestly, your "looping over those directories" seems like the most "fish-like" way to me, but given that someone has already gone through the trouble of creating and debugging the existing __fish_complete_directories (Github link), I think I'd just use it as a starting point for your own completion function.

It seems to me that you could just add a pushd $HOME/some/path/mydir before the "non-existent command hack" and then popd at the end.

Upvotes: 3

Related Questions