Launch the user's preferred editor with the given file path. This function properly parses the EDITOR environment variable to handle editors that require arguments (e.g., "emacsclient -nw"). # Arguments `file_path` - Path to the file to open in the editor # Returns `Ok(())` if the editor was launched successfully and exited with success `Err` if the editor failed to launch or exited with an err
(file_path: &Path)
| 15 | /// * `Ok(())` if the editor was launched successfully and exited with success |
| 16 | /// * `Err` if the editor failed to launch or exited with an error |
| 17 | pub fn launch_editor(file_path: &Path) -> eyre::Result<()> { |
| 18 | let editor_cmd = get_editor(); |
| 19 | |
| 20 | // Parse the editor command to handle arguments |
| 21 | let mut parts = shlex::split(&editor_cmd).ok_or_else(|| eyre::eyre!("Failed to parse EDITOR command"))?; |
| 22 | |
| 23 | if parts.is_empty() { |
| 24 | eyre::bail!("EDITOR environment variable is empty"); |
| 25 | } |
| 26 | |
| 27 | let editor_bin = parts.remove(0); |
| 28 | |
| 29 | let mut cmd = Command::new(editor_bin); |
| 30 | for arg in parts { |
| 31 | cmd.arg(arg); |
| 32 | } |
| 33 | |
| 34 | let status = cmd.arg(file_path).status()?; |
| 35 | |
| 36 | if !status.success() { |
| 37 | eyre::bail!("Editor process did not exit with success"); |
| 38 | } |
| 39 | |
| 40 | Ok(()) |
| 41 | } |
nothing calls this directly
no test coverage detected