fix(editor): handle editor/visual/configured editor with arguments (#1587)
* fix(editor): handle editor/visual/configured editor with arguments * style(fmt): rustfmt
This commit is contained in:
parent
72ed0e98cf
commit
50dd47c2e0
1 changed files with 24 additions and 1 deletions
|
|
@ -162,6 +162,24 @@ fn handle_terminal(
|
|||
}
|
||||
}
|
||||
|
||||
// this is a utility method to separate the arguments from a pathbuf before we turn it into a
|
||||
// Command. eg. "/usr/bin/vim -e" ==> "/usr/bin/vim" + "-e" (the latter will be pushed to args)
|
||||
fn separate_command_arguments(command: &mut PathBuf, args: &mut Vec<String>) {
|
||||
if let Some(file_name) = command
|
||||
.file_name()
|
||||
.and_then(|f_n| f_n.to_str())
|
||||
.map(|f_n| f_n.to_string())
|
||||
{
|
||||
let mut file_name_parts = file_name.split_ascii_whitespace();
|
||||
if let Some(first_part) = file_name_parts.next() {
|
||||
command.set_file_name(first_part);
|
||||
for part in file_name_parts {
|
||||
args.push(String::from(part));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// If a [`TerminalAction::OpenFile(file)`] is given, the text editor specified by environment variable `EDITOR`
|
||||
/// (or `VISUAL`, if `EDITOR` is not set) will be started in the new terminal, with the given
|
||||
/// file open.
|
||||
|
|
@ -191,11 +209,16 @@ pub fn spawn_terminal(
|
|||
"No Editor found, consider setting a path to one in $EDITOR or $VISUAL",
|
||||
);
|
||||
}
|
||||
let command = default_editor.unwrap_or_else(|| {
|
||||
|
||||
let mut command = default_editor.unwrap_or_else(|| {
|
||||
PathBuf::from(env::var("EDITOR").unwrap_or_else(|_| env::var("VISUAL").unwrap()))
|
||||
});
|
||||
|
||||
let mut args = vec![];
|
||||
|
||||
if !command.is_dir() {
|
||||
separate_command_arguments(&mut command, &mut args);
|
||||
}
|
||||
let file_to_open = file_to_open
|
||||
.into_os_string()
|
||||
.into_string()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue