#home #path #env #expand #env-var #home-dir

pathexpand

rust crate for expanding homedirs and env variables in paths

1 unstable release

new 0.1.0 Jan 27, 2025

#4 in #home-dir

Custom license

8KB
142 lines

pathexpand

simple crate to expand homedirs and env variables in paths.

features

can expand:

  • the current user's home directory: ~
  • other users' home directories: ~user is user'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

the only unsafe thing in this crate is running the getuid syscall. this can be toggled off by disabling the getuid feature. if you do so, just ~ will no longer work.

Dependencies

~2.4–4MB
~73K SLoC