Adding ~user tilde recognition in file paths#5251
Adding ~user tilde recognition in file paths#5251fdncred merged 29 commits intonushell:mainfrom merelymyself:main
Conversation
From: // Extend this to work with "~user" style of home paths
|
Can you please explain what this is supposed to do? I don't understand from your description. Also, maybe it's just me but, I really have an aversion to things that only work on one platform. At a minimum, one would think things like this would work on MacOS. |
|
I'm trying to make '~user' expand to the home path for the user in question... except it doesn't seem to be working at the moment. I'm not very experienced at this. It should be working for MacOS without many changes, and I also hope to get it working for Windows soon. |
|
The Your code has a lot of Also, ideally, it should be cross-platform since we do not want Nushell to behave differently on different OSes. |
|
Yeah, I think this could be handy. I was thinking - for crossplatform logic could we use the home path and then substitute the user's name for what is given after the |
|
@jntrnr Yeah, I was thinking the same but on Linux the |
…ome path of current user, and replace the username.
…ther with no conversions to string
…"/" - it was not relative. Removing the / makes it a relative path again.
|
How is this supposed to work? I have 2 users on my Mac. Am I supposed to be able to do |
|
|
|
ok, thanks for the clarification. i couldn't get |
|
@fdncred - previously the function wasn't being called at all because |
ya, maybe instead of looking in the passwd file to get the home dir, maybe there's a better way to do it using a cross platform crate. |
|
@merelymyself Instead of panicking, you can just return the un-expanded path. |
|
Seems like this is working now. Let's see if anything breaks. Thanks! |
* 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.

Description
Attempts to add ~user recognition for linux only.
Apologies for the previous PR. I swear clippy threw no errors when I ran it on my own machine...
Tests
Make sure you've run and fixed any issues with these commands:
cargo fmt --all -- --checkto check standard code formatting (cargo fmt --allapplies these changes)cargo clippy --all --all-features -- -D warnings -D clippy::unwrap_used -A clippy::needless_collectto check that you're using the standard code stylecargo build; cargo test --all --all-featuresto check that all the tests pass