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.

Using :cd with stdout from external command

0 votes
asked Mar 11 in vifm by anonymous

I try to create a command to change directory in active window:

command <cmd> :cd <stdout of external_command>

Tried with :cd {<external_command>} and :execute '<external_command>' :cd %u without success. An example will be helpful.

1 Answer

0 votes
answered Mar 11 by xaizek

Using :execute was correct idea, but you also need to use system() function to get the output of an external command:

command! gohome :execute 'cd' system('echo $HOME')

For paths that have spaces this should be better:

command! gohome :execute "cd '".system('echo $HOME')."'"
commented Mar 12 by anonymous

Thanks for the help. Works like a charm

When asking, English language is preferred, but Russian, Ukrainian and maybe German can be used as well (in the last case answers might be in bad German).

If you would like to make a bug report or feature request consider using GitHub, SourceForge or e-mail. Posting such things here won't be considered as a spam, but this is not a perfect place for it.
...