mirror of
https://github.com/neovide/neovide.git
synced 2026-09-10 07:16:25 -04:00
fix: expand tilde in chdir on config (#3449)
the bug is that the common startup path that picks the child cwd was assuming that every caller had already normalized the path.
This commit is contained in:
parent
4a954a4958
commit
4ca822524e
|
|
@ -5,7 +5,10 @@ use std::path::PathBuf;
|
|||
use std::process::Command as StdCommand;
|
||||
use tokio::process::Command as TokioCommand;
|
||||
|
||||
use crate::{cmd_line::CmdLineSettings, utils::handle_wslpaths};
|
||||
use crate::{
|
||||
cmd_line::CmdLineSettings,
|
||||
utils::{expand_tilde, handle_wslpaths},
|
||||
};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
const FORKED_FROM_TTY_ENV_VAR: &str = "NEOVIDE_FORKED_FROM_TTY";
|
||||
|
|
@ -85,7 +88,11 @@ pub fn create_tokio_nvim_command(
|
|||
}
|
||||
|
||||
fn command_cwd(settings: &CmdLineSettings, cwd: Option<&Path>) -> Option<PathBuf> {
|
||||
cwd.map(Path::to_path_buf).or_else(|| settings.chdir.as_deref().map(PathBuf::from))
|
||||
cwd.map(Path::to_path_buf).or_else(|| {
|
||||
settings.chdir.as_deref().map(|dir| {
|
||||
if dir.starts_with('~') { PathBuf::from(expand_tilde(dir)) } else { PathBuf::from(dir) }
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn build_nvim_command_parts(
|
||||
|
|
@ -324,4 +331,22 @@ mod tests {
|
|||
|
||||
assert_eq!(command_cwd(&cmdline_settings, None), Some(PathBuf::from("/random/path")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn command_cwd_expands_tilde_in_cmdline_setting() {
|
||||
let cmdline_settings = parse_cmdline_settings(&["neovide", "--chdir", "~"]);
|
||||
|
||||
assert_eq!(command_cwd(&cmdline_settings, None), Some(PathBuf::from(expand_tilde("~"))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn command_cwd_expands_tilde_subpath_in_cmdline_setting() {
|
||||
let cmdline_settings =
|
||||
parse_cmdline_settings(&["neovide", "--chdir", "~/some/other/project"]);
|
||||
|
||||
assert_eq!(
|
||||
command_cwd(&cmdline_settings, None),
|
||||
Some(PathBuf::from(expand_tilde("~/some/other/project")))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue