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, 2017 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, 2017 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, 2017 by anonymous

Thanks for the help. Works like a charm

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.