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.
0 votes
in vifm by

Hi xaizek,

First of all, let me thank you for making, sharing and maintaining this wonderful piece of software! VIFM has made my life so much easier and faster ... thank you.

Secondly, my apologies for posting this question here, as it is really quite an irrelevant one. However, in this forum xaizek has always been so insightful in his/her(?) feedback that I am interested to hear his/her opinion about the following question: Is it possible for an external script (but called from within vifm) to echo to the vifm build-in command line?

In the past I have built up a small library of helper scripts that I can very easily include in vifm by binding them to keys:
nnoremap <key> :/path/to/helper/script %macro &<CR>
The helper scripts typically are bash or python scripts. Some of them can start processes that take time to finalize, and so I would like to echo notifications about the progress or finalization of these processes. So far I have happily used notify-send and/or zenity on my system (ubuntu), but now I would like to find a way to echo such feedback when only a terminal interface is available (e.g. when ssh-ing from another system). Any message displayed with an echo (bash) or print (python) statement is piped to the shell and so is only seen when vifm is exited or when a subshell is launched. One way out would be to pause the script progress and require the user to e.g. press Enter for continuation. This will force vifm to go to the shell where the feedback will then be visible. However, a less intrusive method seems preferable, certainly when only trying to echo progress feedback that does not require feedback from the user. Therefore I wonder if it is possible for an external script to e.g. echo to the vifm build-in command line? Or, perhaps, do you know of another text-based (TUI) only method of providing feedback to the vifm user through an external script?

Kind regards,
a fan

1 Answer

0 votes
by

Hello there,

First of all, let me thank you for making, sharing and maintaining this wonderful piece of software! VIFM has made my life so much easier and faster ... thank you.

Thanks for the gratitude! However, Ken Steen is the one who should be credited with making and sharing it, I took over about a decade ago.

Secondly, my apologies for posting this question here, as it is really quite an irrelevant one.

I think it's a relevant question. You're trying to integrate your scripts with Vifm.

his/her(?)

his

Is it possible for an external script (but called from within vifm) to echo to the vifm build-in command line?

Yes, and in this case multiple ways are available.

In general you can use client-server interaction to pass :echo commands to Vifm's instance. For example, do let $VIFM_SERVER = v:servername in vifmrc and echo using vifm --server-name "$VIFM_SERVER" --remote +'echo "msg"' in scripts.

However, this will require escaping of messages and changing of the scripts which can be avoided.

Given that your scripts already print output and you run them in background, you can abuse Vim's mechanism of reporting errors from background applications. Basically do

nnoremap <key> :/path/to/helper/script %macro 2>&1 &<CR>

To redirect output to error stream and dialogs with that output will pop up when available. You can add %i to ignore the output (or press Ctrl+C to silence an annoying process) and check the status in :jobs (press e to see all previous messages from that process). If you need to read the output, then don't ignore it, because when the process is done it's output is discarded.

by

Hi xaizek,

Thank you for the extensive answer!! The second method (redirecting to stderr) was already starting to take shape in my mind. Nice to see it confirmed here ;). The other technique (client-server) may be a bit more work, but it sounds like it may be worth the effort. I will try out both methods when I get the opportunity.

In case that you know of additional methods then please share the knowledge. I am interested in learning about all possibilities!

I would like to thank xaizek and Ken Steen for making/maintaining the file manager that makes all other file managers redundant.

With kind regards,
a fan

...