fix: use ; as delimiter on windows for _PR_LIB (github #37)

Co-authored-by: iff <iff@ik.me>
This commit is contained in:
Cody Duong 2025-03-05 16:34:29 -06:00 committed by GitHub
parent 737440869c
commit d76a244a1a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 5 deletions

View file

@ -1,5 +1,7 @@
use pay_respects_utils::evals::split_command;
use pay_respects_utils::files::get_path_files;
use pay_respects_utils::files::path_env_sep;
use std::process::{exit, Stdio};
use std::collections::HashMap;
@ -7,6 +9,9 @@ use std::sync::mpsc::channel;
use std::thread;
use std::time::Duration;
#[cfg(windows)]
use pay_respects_utils::files::path_convert;
pub const PRIVILEGE_LIST: [&str; 2] = ["sudo", "doas"];
#[derive(PartialEq)]
@ -112,8 +117,12 @@ impl Data {
}
}
let path = lib_dir.split(':').collect::<Vec<&str>>();
let path = lib_dir.split(path_env_sep()).collect::<Vec<&str>>();
for p in path {
#[cfg(windows)]
let p = path_convert(p);
let files = match std::fs::read_dir(p) {
Ok(files) => files,
Err(_) => continue,

View file

@ -51,7 +51,7 @@ Expose your module as executable (`chmod u+x`) in `PATH`, and done!
## `LIB` directories
If exposing modules in `PATH` annoys you, you can set the `_PR_LIB` environment variable to specify directories to find the modules, separated by `:` (analogous to `PATH`):
If exposing modules in `PATH` annoys you, you can set the `_PR_LIB` environment variable to specify directories to find the modules, separated by `:` or `;` (analogous to `PATH`):
Example in a [FHS 3.0 compliant system](https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch04s06.html):
```shell
@ -60,6 +60,14 @@ export _DEF_PR_LIB="/usr/lib"
# runtime
export _PR_LIB="/usr/lib:$HOME/.local/share"
```
Example in Windows/DOS compliant systems
```pwsh
$env:_PR_LIB = @(
(Join-Path $env:APPDATA "pay-respects" "modules"),
(Join-Path $env:USERPROFILE ".cargo" "bin")
) -join ';'
```
This is not the default as there is no general way to know its value and depends on distribution (`/usr/lib`, `/usr/libexec`, or NixOS which isn't FHS compliant at all). System programs usually have a hard-coded path looking for `lib`. If you are a package maintainer for a distribution, setting this value when compiling, so it fits into your distribution standard.
If you installed the module with `cargo install`, the binary will be placed in `bin` subdirectory under Cargo's home which should be in the `PATH` anyway. Cargo has no option to place in subdirectories with other names.

View file

@ -123,7 +123,7 @@ fn path_env() -> String {
}
#[cfg(windows)]
fn path_env_sep() -> &'static str {
pub fn path_env_sep() -> &'static str {
if is_msystem() {
":"
} else {
@ -132,7 +132,7 @@ fn path_env_sep() -> &'static str {
}
#[cfg(windows)]
fn path_convert(path: &str) -> String {
pub fn path_convert(path: &str) -> String {
if is_msystem() {
msys2_conv_path(path).expect("Failed to convert path for msys")
} else {
@ -164,6 +164,6 @@ fn path_env() -> String {
}
#[cfg(not(windows))]
fn path_env_sep() -> &'static str {
pub fn path_env_sep() -> &'static str {
":"
}