mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-28 07:46:28 +00:00
build: bump path-slash from 0.1.4 to 0.2.0 (#4155)
* build: bump path-slash from 0.1.4 to 0.2.0 Bumps [path-slash](https://github.com/rhysd/path-slash) from 0.1.4 to 0.2.0. - [Release notes](https://github.com/rhysd/path-slash/releases) - [Changelog](https://github.com/rhysd/path-slash/blob/master/CHANGELOG.md) - [Commits](https://github.com/rhysd/path-slash/compare/v0.1.4...v0.2.0) --- updated-dependencies: - dependency-name: path-slash dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * fix errors in code after path-slash bump to 0.2.0 * fmt * refactor contract_path to return Cow<str> * update contract_windows_style_root_directory test Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
parent
784d671d5e
commit
f56955084b
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1356,9 +1356,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "path-slash"
|
||||
version = "0.1.4"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3cacbb3c4ff353b534a67fb8d7524d00229da4cb1dc8c79f4db96e375ab5b619"
|
||||
checksum = "c54014ba3c1880122928735226f78b6f5bf5bd1fed15e41e92cf7aa20278ce28"
|
||||
|
||||
[[package]]
|
||||
name = "pathdiff"
|
||||
|
@ -53,7 +53,7 @@ notify-rust = { version = "4.5.8", optional = true }
|
||||
once_cell = "1.13.0"
|
||||
open = "3.0.1"
|
||||
os_info = "3.4.0"
|
||||
path-slash = "0.1.4"
|
||||
path-slash = "0.2.0"
|
||||
pest = "2.1.3"
|
||||
pest_derive = "2.1.0"
|
||||
quick-xml = "0.23.0"
|
||||
|
@ -5,6 +5,7 @@ use super::utils::directory_win as directory_utils;
|
||||
use super::utils::path::PathExt as SPathExt;
|
||||
use indexmap::IndexMap;
|
||||
use path_slash::{PathBufExt, PathExt};
|
||||
use std::borrow::Cow;
|
||||
use std::iter::FromIterator;
|
||||
use std::path::{Path, PathBuf};
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
@ -63,8 +64,8 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
let mut is_truncated = dir_string.is_some();
|
||||
|
||||
// the home directory if required.
|
||||
let dir_string =
|
||||
dir_string.unwrap_or_else(|| contract_path(display_dir, &home_dir, &home_symbol));
|
||||
let dir_string = dir_string
|
||||
.unwrap_or_else(|| contract_path(display_dir, &home_dir, &home_symbol).to_string());
|
||||
|
||||
#[cfg(windows)]
|
||||
let dir_string = remove_extended_path_prefix(dir_string);
|
||||
@ -89,7 +90,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
let contracted_home_dir = contract_path(display_dir, &home_dir, &home_symbol);
|
||||
to_fish_style(
|
||||
config.fish_style_pwd_dir_length as usize,
|
||||
contracted_home_dir,
|
||||
contracted_home_dir.to_string(),
|
||||
&dir_string,
|
||||
)
|
||||
} else {
|
||||
@ -204,13 +205,17 @@ fn is_readonly_dir(path: &Path) -> bool {
|
||||
///
|
||||
/// Replaces the `top_level_path` in a given `full_path` with the provided
|
||||
/// `top_level_replacement`.
|
||||
fn contract_path(full_path: &Path, top_level_path: &Path, top_level_replacement: &str) -> String {
|
||||
fn contract_path<'a>(
|
||||
full_path: &'a Path,
|
||||
top_level_path: &'a Path,
|
||||
top_level_replacement: &'a str,
|
||||
) -> Cow<'a, str> {
|
||||
if !full_path.normalised_starts_with(top_level_path) {
|
||||
return full_path.to_slash_lossy();
|
||||
}
|
||||
|
||||
if full_path.normalised_equals(top_level_path) {
|
||||
return top_level_replacement.to_string();
|
||||
return Cow::from(top_level_replacement);
|
||||
}
|
||||
|
||||
// Because we've done a normalised path comparison above
|
||||
@ -221,12 +226,12 @@ fn contract_path(full_path: &Path, top_level_path: &Path, top_level_replacement:
|
||||
.strip_prefix(top_level_path.without_prefix())
|
||||
.unwrap_or(full_path);
|
||||
|
||||
format!(
|
||||
Cow::from(format!(
|
||||
"{replacement}{separator}{path}",
|
||||
replacement = top_level_replacement,
|
||||
separator = "/",
|
||||
path = sub_path.to_slash_lossy()
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
/// Contract the root component of a path based on the real path
|
||||
@ -424,7 +429,7 @@ mod tests {
|
||||
let top_level_path = Path::new("C:\\Users\\astronaut");
|
||||
|
||||
let output = contract_path(full_path, top_level_path, "~");
|
||||
assert_eq!(output, "C:");
|
||||
assert_eq!(output, "C:/");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -789,7 +794,7 @@ mod tests {
|
||||
})
|
||||
.path(&dir)
|
||||
.collect();
|
||||
let dir_str = dir.to_slash_lossy();
|
||||
let dir_str = dir.to_slash_lossy().to_string();
|
||||
let expected = Some(format!(
|
||||
"{} ",
|
||||
Color::Cyan.bold().paint(convert_path_sep(
|
||||
@ -819,7 +824,7 @@ mod tests {
|
||||
"{} ",
|
||||
Color::Cyan.bold().paint(convert_path_sep(&to_fish_style(
|
||||
100,
|
||||
dir.to_slash_lossy(),
|
||||
dir.to_slash_lossy().to_string(),
|
||||
""
|
||||
)))
|
||||
));
|
||||
@ -870,7 +875,7 @@ mod tests {
|
||||
"{} ",
|
||||
Color::Cyan.bold().paint(convert_path_sep(&format!(
|
||||
"{}/thrusters/rocket",
|
||||
to_fish_style(1, dir.to_slash_lossy(), "/thrusters/rocket")
|
||||
to_fish_style(1, dir.to_slash_lossy().to_string(), "/thrusters/rocket")
|
||||
)))
|
||||
));
|
||||
|
||||
@ -992,7 +997,7 @@ mod tests {
|
||||
"{} ",
|
||||
Color::Cyan.bold().paint(convert_path_sep(&format!(
|
||||
"{}/above-repo/rocket-controls/src/meters/fuel-gauge",
|
||||
to_fish_style(1, tmp_dir.path().to_slash_lossy(), "")
|
||||
to_fish_style(1, tmp_dir.path().to_slash_lossy().to_string(), "")
|
||||
)))
|
||||
));
|
||||
|
||||
@ -1023,7 +1028,15 @@ mod tests {
|
||||
"{} ",
|
||||
Color::Cyan.bold().paint(convert_path_sep(&format!(
|
||||
"{}/rocket-controls/src/meters/fuel-gauge",
|
||||
to_fish_style(1, tmp_dir.path().join("above-repo").to_slash_lossy(), "")
|
||||
to_fish_style(
|
||||
1,
|
||||
tmp_dir
|
||||
.path()
|
||||
.join("above-repo")
|
||||
.to_slash_lossy()
|
||||
.to_string(),
|
||||
""
|
||||
)
|
||||
)))
|
||||
));
|
||||
|
||||
@ -1198,7 +1211,7 @@ mod tests {
|
||||
"{} ",
|
||||
Color::Cyan.bold().paint(convert_path_sep(&format!(
|
||||
"{}/above-repo/rocket-controls-symlink/src/meters/fuel-gauge",
|
||||
to_fish_style(1, tmp_dir.path().to_slash_lossy(), "")
|
||||
to_fish_style(1, tmp_dir.path().to_slash_lossy().to_string(), "")
|
||||
)))
|
||||
));
|
||||
|
||||
@ -1235,7 +1248,15 @@ mod tests {
|
||||
"{} ",
|
||||
Color::Cyan.bold().paint(convert_path_sep(&format!(
|
||||
"{}/rocket-controls-symlink/src/meters/fuel-gauge",
|
||||
to_fish_style(1, tmp_dir.path().join("above-repo").to_slash_lossy(), "")
|
||||
to_fish_style(
|
||||
1,
|
||||
tmp_dir
|
||||
.path()
|
||||
.join("above-repo")
|
||||
.to_slash_lossy()
|
||||
.to_string(),
|
||||
""
|
||||
)
|
||||
)))
|
||||
));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user