Welcome to Vifm Q&A, where you can ask questions about Vifm usage. Registration is optional, anonymous posts are moderated. GitHub or Google logins are enabled.

How can I call a fish function from a filetype command?

0 votes
asked Apr 16 in vifm by Wizhi

Using fish shell, I've defined the following function in ~/.config/fish/functions/foo.fish:

function foo
    echo $argv

Quick test in a new fish shell shows that fish has picked up the function:

$ foo bar

In my vifmrc file, I've defined the following filetype handler:

filetype *.txt foo %f | less 

If I now attempt to open a test.txt, I'd expect less to open with the contents test.txt since I've used the %f macro.

I found an old zsh issue regarding aliases, but the shellcmdflag option wont do me much good since the following works just fine:

$ fish -c 'foo test'

Or am I misunderstanding how vifm invokes commands in the context of filetype handlers?

1 Answer

0 votes
answered Apr 16 by xaizek
selected Apr 17 by xaizek
Best answer

Use this instead:

filetype *.txt echo -n; foo %f | less 

vifm attempts to be smart and check for existence of commands, which works fine unless it's something like an alias. A way to control this behaviour will need to be added eventually, to avoid such situations.

commented Apr 16 by Wizhi

Works great, thanks.

Don't think I can mark this answer as accepted since I posted without an account, sadly.

If you would like to make a bug report or feature request consider using GitHub, SourceForge or e-mail. Posting such things here is acceptable, but this is not a perfect place for them.