pathexpand

Crates.iopathexpand
lib.rspathexpand
version0.1.1
created_at2025-01-27 20:48:18.617214+00
updated_at2025-03-22 22:28:52.660699+00
descriptionsimple and lightweight crate for expanding homedirs and env variables in paths
homepagehttps://git.gay/tauon/pathexpand
repositoryhttps://git.gay/tauon/pathexpand
max_upload_size
id1532857
size14,150
lily celeste newton (TheAwesome98-Real)

documentation

README

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 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

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.

Commit count: 0

cargo fmt