2 releases
Uses new Rust 2024
0.1.1 | Mar 22, 2025 |
---|---|
0.1.0 | Jan 27, 2025 |
#579 in Filesystem
124 downloads per month
9KB
151 lines
pathexpand
simple and lightweight rust crate to expand homedirs and env variables in paths.
features
can expand:
- the current user's home directory:
~
- other users' home directories:
~user
isuser
's home directory - environment variables:
${VAR}
or${VAR2:alternative if undefined}
. this is the only syntax,%VAR%
and$VAR
do not work.
syntax remains the same on all platforms. ~user
only works on systems where /etc/passwd
exists and is readable. (i.e., not windows)
note
this contains a crappy implementation of the pwd
crate (and similar crates) for now, because i want to use the least amount of unsafe code possible. i wrote this crate for doing a config dir in programs i write, because i couldn't find a library that expanded paths in the way i wanted, so i just wanted to get it done quickly. i'll eventually write a crate for users, groups, and passwords later, like a safe version of the users
crate.
on safety
unsafe code is required to determine what the current user is. unsafe code is forbidden if the unsafe-code
feature is disabled, but this means that expanding ~
in paths will no longer work. on linux, the getuid
syscall is used, and on other platforms, libc::getuid()
is used.
Dependencies
~2.3–4MB
~72K SLoC