I’d like to launch the user’s preferred editor with Command::new, to edit a string and return the edited string. (I haven’t found a crate to do that, so I’m looking to build one.) For the last fallback of that, after trying a configured editor and the standard environment variables ($VISUAL
, $EDITOR
), I need to try execing editor
(common on Debian and derived systems), and then try launching vi
(the historical default) if that doesn’t exist.
Typically, programs do that kind of thing by calling fork
once, then calling execvp
multiple times. That also avoids the need to do any post-fork pre-exec setup multiple times.
How can I do that with Rust’s Command::new
or similar?
And if Command::new
doesn’t support this, should I propose adding it? Perhaps a .fallbacks
method that provides a series of fallback commands to try if the first doesn’t work?