From 5c2bc73d7bcec1d45540d940752e30720fc2e929 Mon Sep 17 00:00:00 2001 From: merelymyself <88221256+merelymyself@users.noreply.github.com> Date: Mon, 25 Apr 2022 19:01:48 +0800 Subject: [PATCH] Allows cd (and other commands that depend on current working directory) to use path of type '~user' (#5323) * Added search terms to math commands * Attempts to add ~user. From: // Extend this to work with "~user" style of home paths * Clippy recommendation * clippy suggestions, again. * fixing non-compilation on windows and macos * fmt apparently does not like my imports * even more clippy issues. * less expect(), single conversion, match. Should work for MacOS too. * Attempted to add functionality for windows: all it does is take the home path of current user, and replace the username. * silly mistake in Windows version of user_home_dir() * Update tilde.rs * user_home_dir now returns a path instead of a string - should be smoother with no conversions to string * clippy warnings * clippy warnings 2 * Changed user_home_dir to return PathBuf now. * Changed user_home_dir to return PathBuf now. * forgot to fmt * fixed windows build errors from modifying pathbuf but not returning it * fixed windows clippy errors from returning () instead of pathbuf * forgot to fmt * borrowed path did not live long enough. * previously, path.push did not work because rest_of_path started with "/" - it was not relative. Removing the / makes it a relative path again. * Issue fixed. * Update tilde.rs * fmt. * There is now a zero chance of panic. All expect()s have been removed. * Patched join_path_relative to accommodate ~user paths. Previously, /some/path/~user might have been passed on; now, ~user is taken as absolute. * fmt * clippy errors --- crates/nu-path/src/expansions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/nu-path/src/expansions.rs b/crates/nu-path/src/expansions.rs index af931cf5c3..ffa202a3d2 100644 --- a/crates/nu-path/src/expansions.rs +++ b/crates/nu-path/src/expansions.rs @@ -18,8 +18,8 @@ where // more ugly - so we don't do anything, which should result in an equal // path on all supported systems. relative_to.into() - } else if path.starts_with("~") { - // do not end up with "/some/path/~" + } else if path.to_string_lossy().as_ref().starts_with('~') { + // do not end up with "/some/path/~" or "/some/path/~user" path.into() } else { relative_to.join(path)