scriptlike icon indicating copy to clipboard operation
scriptlike copied to clipboard

Path("~") should extend to home directory

Open WebFreak001 opened this issue 8 years ago • 3 comments

  • [ ] Path("~") -> Path("/home/user")
  • [ ] Path("~/.config/foo") -> Path("/home/user/.config/foo")
  • [ ] Path("~user2") -> Path("/home/user2")
  • [ ] Path("~custom_home_user") -> Path("/var/www")

see std.path.expandTilde and reading /etc/passwd or using the functions from the core.sys module thingy on windows its a bit more complicated

WebFreak001 avatar Aug 31 '16 16:08 WebFreak001

For my own (and others) future reference, the two-way mapping between posix/windows home directories is:

Purpose Posix Windows
The user's own files ~ %USERPROFILE%/Documents
Your program's clutter and other crap ~/.config %APPDATA% (or if data is large or machine-specific: %LOCALAPPDATA%)

Although on windows, it's probably better to read the KNOWNFOLDERID (somehow) than to use those envvars, since the envvars can be changed.

However, I'm leaning more towards creating new interfaces for accessing a user's home directories, rather than re-using and encouraging the ~ syntax and trying to interpret that on Windows. This is partly to avoid any confusion from doing what looks like a posix-specifc way but make it magically, and surprisingly, work on win (which would get weird mainly because of ~/.config). But much, much more than that, it's to dissuade people from always reaching straight for ~ whether its correct or not, pretending ~/.config/%APPDATA% doesn't exist, and then abusing the "user's documents" directory by cluttering it up with random app-internal crap (uhhhh....yea....major pet peeve of mine on both OS's).

Abscissa avatar Jan 31 '17 05:01 Abscissa

Come to think of it, Path is intended to keep a path as canonical/normalized as possible (except for resolving symlinks), to keep path comparisons as reliable as possible, so this really should be implemented.

But it should do nothing on Windows, largely because ~ doesn't mean "home directory" in that environment. (Plus, I still don't want to encourage developers using ~. Instead, they should be encouraged to make a conscious choice between "directory for user-created files" vs "directory for the prog to dump all its user-specific internal crap")

Abscissa avatar Mar 02 '18 04:03 Abscissa

If I use scriptlike, I use it for scripting, and normally I don't share my scripts and just want to have it as convenient as possible for the one or two platforms I'm writing them on right now

WebFreak001 avatar Mar 02 '18 13:03 WebFreak001