mirror of https://github.com/sgoudham/neovide.git
fix for macos finder issue (#1162)
* attempt fix for finder issue * pull command creation functions out and implement macos exists and which * remove macos hack * refactor platform specific startup code * fix wsl command issue Co-authored-by: Keith Simmons <keithsim@microsoft.com>macos-click-through
parent
db53e94db9
commit
dd74ff4239
@ -0,0 +1,121 @@
|
|||||||
|
use std::{
|
||||||
|
env,
|
||||||
|
path::Path,
|
||||||
|
process::{Command as StdCommand, Stdio},
|
||||||
|
};
|
||||||
|
|
||||||
|
use log::{error, info, warn};
|
||||||
|
use tokio::process::Command as TokioCommand;
|
||||||
|
|
||||||
|
use crate::{cmd_line::CmdLineSettings, settings::*};
|
||||||
|
|
||||||
|
pub fn create_nvim_command() -> TokioCommand {
|
||||||
|
let mut cmd = build_nvim_cmd();
|
||||||
|
|
||||||
|
info!("Starting neovim with: {:?}", cmd);
|
||||||
|
|
||||||
|
#[cfg(not(debug_assertions))]
|
||||||
|
cmd.stderr(Stdio::piped());
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
cmd.stderr(Stdio::inherit());
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
set_windows_creation_flags(&mut cmd);
|
||||||
|
|
||||||
|
dbg!(cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
fn set_windows_creation_flags(cmd: &mut TokioCommand) {
|
||||||
|
cmd.creation_flags(0x0800_0000); // CREATE_NO_WINDOW
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_nvim_cmd() -> TokioCommand {
|
||||||
|
if let Some(path) = SETTINGS.get::<CmdLineSettings>().neovim_bin {
|
||||||
|
if platform_exists(&path) {
|
||||||
|
return build_nvim_cmd_with_args(&path);
|
||||||
|
} else {
|
||||||
|
warn!("NEOVIM_BIN is invalid falling back to first bin in PATH");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(path) = platform_which("nvim") {
|
||||||
|
build_nvim_cmd_with_args(&path)
|
||||||
|
} else {
|
||||||
|
error!("nvim not found!");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Creates a shell command if needed on this platform (wsl or macos)
|
||||||
|
fn create_platform_shell_command(command: String) -> Option<StdCommand> {
|
||||||
|
if cfg!(target_os = "windows") && SETTINGS.get::<CmdLineSettings>().wsl {
|
||||||
|
let mut result = StdCommand::new("wsl");
|
||||||
|
result.args(&["$SHELL", "-lic"]);
|
||||||
|
result.arg(command);
|
||||||
|
|
||||||
|
Some(result)
|
||||||
|
} else if cfg!(target_os = "macos") {
|
||||||
|
let shell = env::var("SHELL").unwrap();
|
||||||
|
let mut result = StdCommand::new(shell);
|
||||||
|
result.args(&["-lic"]);
|
||||||
|
result.arg(command);
|
||||||
|
Some(result)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn platform_exists(bin: &str) -> bool {
|
||||||
|
if let Some(mut exists_command) = create_platform_shell_command(format!("exists -x {}", bin)) {
|
||||||
|
if let Ok(output) = exists_command.output() {
|
||||||
|
output.status.success()
|
||||||
|
} else {
|
||||||
|
error!("Exists failed");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Path::new(&bin).exists()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn platform_which(bin: &str) -> Option<String> {
|
||||||
|
if let Some(mut which_command) = create_platform_shell_command(format!("which {}", bin)) {
|
||||||
|
if let Ok(output) = which_command.output() {
|
||||||
|
if output.status.success() {
|
||||||
|
let nvim_path = String::from_utf8(output.stdout).unwrap();
|
||||||
|
return Some(nvim_path.trim().to_owned());
|
||||||
|
} else {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Platform command failed, fallback to which crate
|
||||||
|
if let Ok(path) = which::which(bin) {
|
||||||
|
path.into_os_string().into_string().ok()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_nvim_cmd_with_args(bin: &str) -> TokioCommand {
|
||||||
|
let mut args = vec!["--embed".to_string()];
|
||||||
|
args.extend(SETTINGS.get::<CmdLineSettings>().neovim_args);
|
||||||
|
let args_str = args.join(" ");
|
||||||
|
|
||||||
|
if cfg!(target_os = "windows") && SETTINGS.get::<CmdLineSettings>().wsl {
|
||||||
|
let mut cmd = TokioCommand::new("wsl");
|
||||||
|
cmd.args(&["$SHELL", "-lc", &format!("{} {}", bin, args_str)]);
|
||||||
|
cmd
|
||||||
|
} else if cfg!(target_os = "macos") {
|
||||||
|
let shell = env::var("SHELL").unwrap();
|
||||||
|
let mut cmd = TokioCommand::new(shell);
|
||||||
|
cmd.args(&["-lc", &format!("{} {}", bin, args_str)]);
|
||||||
|
cmd
|
||||||
|
} else {
|
||||||
|
let mut cmd = TokioCommand::new(bin);
|
||||||
|
cmd.arg(args_str);
|
||||||
|
cmd
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue