Fix path normalization on Windows
This commit is contained in:
parent
fa66bb486b
commit
290da7c363
5 changed files with 37 additions and 2 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -214,6 +214,7 @@ dependencies = [
|
|||
"directories",
|
||||
"enable-ansi-support",
|
||||
"indexmap",
|
||||
"normpath",
|
||||
"palette",
|
||||
"regex",
|
||||
"serde",
|
||||
|
@ -324,6 +325,15 @@ version = "2.7.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[package]]
|
||||
name = "normpath"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5831952a9476f2fed74b77d74182fa5ddc4d21c72ec45a333b250e3ed0272804"
|
||||
dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nu-ansi-term"
|
||||
version = "0.46.0"
|
||||
|
|
|
@ -22,6 +22,7 @@ deranged = { version = "0.3.11", default-features = false }
|
|||
directories = { version = "5.0.1", default-features = false }
|
||||
enable-ansi-support = { version = "0.2.1", default-features = false }
|
||||
indexmap = { version = "2.2.6", default-features = false }
|
||||
normpath = { version = "1.2.0", default-features = false }
|
||||
palette = { version = "0.7.6", default-features = false }
|
||||
regex = { version = "1.10.5", default-features = false }
|
||||
serde = { version = "1.0.203", default-features = false }
|
||||
|
|
|
@ -38,6 +38,7 @@ unicode-normalization = { workspace = true, features = ["std"] }
|
|||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
enable-ansi-support = { workspace = true, features = [] }
|
||||
normpath = { workspace = true, features = [] }
|
||||
|
||||
[features]
|
||||
default = ["autocomplete", "color"]
|
||||
|
|
|
@ -16,7 +16,9 @@ use tracing::debug;
|
|||
|
||||
fn main() -> Result<()> {
|
||||
#[cfg(windows)]
|
||||
enable_ansi_support::enable_ansi_support();
|
||||
if let Err(err) = enable_ansi_support::enable_ansi_support() {
|
||||
debug!(err, "could not enable ANSI escape code support");
|
||||
}
|
||||
|
||||
let options = options().run();
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ use std::{env, fmt};
|
|||
use aho_corasick::AhoCorasick;
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use indexmap::IndexMap;
|
||||
#[cfg(windows)]
|
||||
use normpath::PathExt as _;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tempfile::NamedTempFile;
|
||||
use tracing::debug;
|
||||
|
@ -223,7 +225,13 @@ pub fn get_command_path() -> Result<PathBuf> {
|
|||
let path = path.join("neofetch");
|
||||
match path.try_exists() {
|
||||
Ok(true) => {
|
||||
#[cfg(not(windows))]
|
||||
return path.canonicalize().context("failed to canonicalize path");
|
||||
#[cfg(windows)]
|
||||
return path
|
||||
.normalize()
|
||||
.map(|p| p.into())
|
||||
.context("failed to normalize path");
|
||||
},
|
||||
Ok(false) => {
|
||||
Err(anyhow!("{path:?} does not exist or is not readable"))?;
|
||||
|
@ -245,7 +253,13 @@ pub fn get_command_path() -> Result<PathBuf> {
|
|||
if !path.is_file() {
|
||||
continue;
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
return path.canonicalize().context("failed to canonicalize path");
|
||||
#[cfg(windows)]
|
||||
return path
|
||||
.normalize()
|
||||
.map(|p| p.into())
|
||||
.context("failed to normalize path");
|
||||
}
|
||||
|
||||
Err(anyhow!("neofetch command not found"))
|
||||
|
@ -259,7 +273,14 @@ pub fn ensure_git_bash() -> Result<PathBuf> {
|
|||
let git_bash_path = {
|
||||
// Bundled git bash
|
||||
let current_exe_path = env::current_exe()
|
||||
.and_then(|p| p.canonicalize())
|
||||
.and_then(|p| {
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
p.canonicalize()
|
||||
}
|
||||
#[cfg(windows)]
|
||||
p.normalize().map(|p| p.into())
|
||||
})
|
||||
.context("failed to get path of current running executable")?;
|
||||
let bash_path = current_exe_path.join("git/bin/bash.exe");
|
||||
if bash_path.is_file() {
|
||||
|
|
Loading…
Reference in a new issue