-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os: add .homedir() #1670
os: add .homedir() #1670
Conversation
In almost every cli-client that I write I need the current homedir at a certain point. While we have a function for getting the directory for storing temporary files (callled `tmpdir`), a function for receiving the location of the home directory is still missing.
What happens if |
I think this could be useful if there is a reliable and robust implementation. |
See also user-home |
oh good points, i just took a look at maybe it makes sense to take the code from https://github.com/sindresorhus/user-home/blob/master/index.js and add a notice t our LICENSE file (it is MIT) |
Then again, if userland can do this fine, why should it be in core? |
I am definitely +1 on including something like this, although indeed it seems this might not be robust enough of an implementation. |
Should it not throw an |
I don't think this should be done using environment variables. There are existing C APIs for this, right? |
prior discussion: #682 |
I strongly feel this should have a robust implementation in libuv instead of just checking The ecosystem use the home dir for so many different things, but the current userland ways of inferring it are just too fragile. |
As per the previous discussion in #682 (my comment specifically: #682 (comment)) and echoing @sindresorhus' comment above; I'm -1 on this unless we can come up with a solid cross-platform implementation that doesn't involve a lot of guesswork. The main reason the previous 2 persistent-history for REPL PRs didn't make it in is because they came bundled with implementations like this and @chrisdickinson found a good compromise of just removing the need for a homedir completely--it'd be nice if we could move to using a homedir but the current solution(s) are unsatisfactory. When we expose an API like this to users we are suggesting that it's reliable, but it's absolutely not (sadly!). |
I think an API to retrieve the home directory would be an acceptable addition to libuv. The implementation is also not that hard - on unix the proper way would be to to call getpwnam(3) and return the On Windows the implementation would use SHGetKnowFolderPath and to retrieve the |
@piscisaureus I have already done that. Would you mind looking over https://github.com/cjihrig/userinfo and letting me know if that would be suitable for libuv? |
That looks pretty good in general. |
OK, thanks. I'll work on something for libuv. |
@piscisaureus What if the home directory doesn't exist? |
Well I think the precedent for other |
Landed in libuv: libuv/libuv@a62c2d5 \o/ |
I'll work on the io.js bits soon and PR it once it's in |
i'll just keep this open for reference / further discussion, please close it once @cjihrig has a superseeding PR |
Closing in favor of #1791 |
In almost every cli-client that I write I need the current homedir
at a certain point.
While we have a function for getting the directory for storing
temporary files (callled
tmpdir
), a function for receiving thelocation of the home directory is still missing.