mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-11 22:10:09 +01:00
feat: custom lib directories
This commit is contained in:
parent
443460a81e
commit
3c4e2b06bd
4 changed files with 108 additions and 27 deletions
|
|
@ -5,6 +5,13 @@ All notable changes to components of this project since 0.5.14 will be documente
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Compile-time and runtime environment variable `_PR_LIB` specifying `lib` directories for storing modules, separated by `:`
|
||||||
|
- When not provided, it will search in `PATH`
|
||||||
|
|
||||||
## [0.6.2] - 2024-12-10
|
## [0.6.2] - 2024-12-10
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
|
|
@ -54,35 +54,95 @@ impl Data {
|
||||||
let command = last_command(&shell).trim().to_string();
|
let command = last_command(&shell).trim().to_string();
|
||||||
let alias = alias_map(&shell);
|
let alias = alias_map(&shell);
|
||||||
let mode = run_mode();
|
let mode = run_mode();
|
||||||
let (executables, modules, fallbacks) = {
|
let (executables, modules, fallbacks);
|
||||||
let path_executables = get_path_files();
|
let lib_dir = {
|
||||||
let mut executables = vec![];
|
if let Ok(lib_dir) = std::env::var("_PR_LIB") {
|
||||||
let mut modules = vec![];
|
Some(lib_dir)
|
||||||
let mut fallbacks = vec![];
|
} else {
|
||||||
for exe in path_executables {
|
option_env!("_PR_LIB").map(|dir| dir.to_string())
|
||||||
if exe.starts_with("_pay-respects-module-") {
|
|
||||||
modules.push(exe.to_string());
|
|
||||||
} else if exe.starts_with("_pay-respects-fallback-") {
|
|
||||||
fallbacks.push(exe.to_string());
|
|
||||||
} else {
|
|
||||||
executables.push(exe.to_string());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
modules.sort_unstable();
|
|
||||||
fallbacks.sort_unstable();
|
|
||||||
if alias.is_some() {
|
|
||||||
let alias = alias.as_ref().unwrap();
|
|
||||||
for command in alias.keys() {
|
|
||||||
if executables.contains(command) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
executables.push(command.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(executables, modules, fallbacks)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
eprintln!("lib_dir: {:?}", lib_dir);
|
||||||
|
|
||||||
|
if lib_dir.is_none() {
|
||||||
|
(executables, modules, fallbacks) = {
|
||||||
|
let path_executables = get_path_files();
|
||||||
|
let mut executables = vec![];
|
||||||
|
let mut modules = vec![];
|
||||||
|
let mut fallbacks = vec![];
|
||||||
|
for exe in path_executables {
|
||||||
|
if exe.starts_with("_pay-respects-module-") {
|
||||||
|
modules.push(exe.to_string());
|
||||||
|
} else if exe.starts_with("_pay-respects-fallback-") {
|
||||||
|
fallbacks.push(exe.to_string());
|
||||||
|
} else {
|
||||||
|
executables.push(exe.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
modules.sort_unstable();
|
||||||
|
fallbacks.sort_unstable();
|
||||||
|
if alias.is_some() {
|
||||||
|
let alias = alias.as_ref().unwrap();
|
||||||
|
for command in alias.keys() {
|
||||||
|
if executables.contains(command) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
executables.push(command.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(executables, modules, fallbacks)
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
(executables, modules, fallbacks) = {
|
||||||
|
let mut modules = vec![];
|
||||||
|
let mut fallbacks = vec![];
|
||||||
|
let lib_dir = lib_dir.unwrap();
|
||||||
|
let mut executables = get_path_files();
|
||||||
|
if alias.is_some() {
|
||||||
|
let alias = alias.as_ref().unwrap();
|
||||||
|
for command in alias.keys() {
|
||||||
|
if executables.contains(command) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
executables.push(command.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let path = lib_dir.split(':').collect::<Vec<&str>>();
|
||||||
|
for p in path {
|
||||||
|
let files = match std::fs::read_dir(p) {
|
||||||
|
Ok(files) => files,
|
||||||
|
Err(_) => continue,
|
||||||
|
};
|
||||||
|
for file in files {
|
||||||
|
let file = file.unwrap();
|
||||||
|
let file_name = file.file_name().into_string().unwrap();
|
||||||
|
let file_path = file.path();
|
||||||
|
|
||||||
|
if file_name.starts_with("_pay-respects-module-") {
|
||||||
|
modules.push(file_path.to_string_lossy().to_string());
|
||||||
|
} else if file_name.starts_with("_pay-respects-fallback-") {
|
||||||
|
fallbacks.push(file_path.to_string_lossy().to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
modules.sort_unstable();
|
||||||
|
fallbacks.sort_unstable();
|
||||||
|
|
||||||
|
(executables, modules, fallbacks)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
{
|
||||||
|
eprintln!("modules: {:?}", modules);
|
||||||
|
eprintln!("fallbacks: {:?}", fallbacks);
|
||||||
|
}
|
||||||
|
|
||||||
let mut init = Data {
|
let mut init = Data {
|
||||||
shell,
|
shell,
|
||||||
command,
|
command,
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,10 @@ use crate::shell::{add_candidates_no_dup, module_output, shell_evaluated_command
|
||||||
use crate::style::highlight_difference;
|
use crate::style::highlight_difference;
|
||||||
|
|
||||||
pub fn suggest_candidates(data: &mut Data) {
|
pub fn suggest_candidates(data: &mut Data) {
|
||||||
let executable = &data.split[0].rsplit(std::path::MAIN_SEPARATOR).next().unwrap();
|
let executable = &data.split[0]
|
||||||
|
.rsplit(std::path::MAIN_SEPARATOR)
|
||||||
|
.next()
|
||||||
|
.unwrap();
|
||||||
let command = &data.command;
|
let command = &data.command;
|
||||||
let privilege = &data.privilege;
|
let privilege = &data.privilege;
|
||||||
let mut suggest_candidates = vec![];
|
let mut suggest_candidates = vec![];
|
||||||
|
|
|
||||||
11
modules.md
11
modules.md
|
|
@ -42,3 +42,14 @@ Your module should print:
|
||||||
|
|
||||||
Expose your module as executable (`chmod u+x`) in `PATH`, and done!
|
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`). The variable can be set either runtime or compile-time.
|
||||||
|
|
||||||
|
Example would be:
|
||||||
|
```shell
|
||||||
|
export _PR_LIB_DIR="/usr/lib:$HOME/.local/bin"
|
||||||
|
```
|
||||||
|
This is not the default as there is no general standard about where the `lib` directories are located and depends on distribution (`/usr/lib`, `/usr/libexec`, `/data/data/com.termux/files/usr/libexec`, etc.). 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 `~/.cargo/bin` which should be in the `PATH` anyway.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue