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:
Alexsander Falcucci 2026-04-02 02:17:25 +02:00 committed by GitHub
parent 4a954a4958
commit 4ca822524e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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")))
);
}
}