fix: builtin commands

This commit is contained in:
iff 2025-04-08 20:40:58 +02:00
parent 8acb40af95
commit 09217fb179
3 changed files with 23 additions and 1 deletions

1
Cargo.lock generated
View file

@ -967,6 +967,7 @@ dependencies = [
"askama",
"colored",
"inquire",
"itertools 0.14.0",
"pay-respects-parser",
"pay-respects-utils",
"regex-lite",

View file

@ -24,6 +24,7 @@ inquire = "0.7"
pay-respects-parser = { version = "0.3", path = "../parser" }
pay-respects-utils = { version ="0.1", path = "../utils"}
itertools = "0.14.0"
[package.metadata.deb]
assets = [

View file

@ -3,6 +3,7 @@ use pay_respects_utils::files::get_path_files;
use pay_respects_utils::files::path_env_sep;
use askama::Template;
use itertools::Itertools;
use std::process::{exit, Stdio};
@ -63,7 +64,7 @@ impl Data {
let command = last_command(&shell).trim().to_string();
let alias = alias_map(&shell);
let mode = run_mode();
let (executables, modules, fallbacks);
let (mut executables, modules, fallbacks);
let lib_dir = {
if let Ok(lib_dir) = std::env::var("_PR_LIB") {
Some(lib_dir)
@ -150,6 +151,10 @@ impl Data {
};
}
let builtins = builtin_commands(&shell);
executables.extend(builtins.clone());
executables = executables.iter().unique().cloned().collect();
let mut init = Data {
shell,
env: None,
@ -612,6 +617,21 @@ pub fn get_shell() -> String {
}
}
fn builtin_commands(shell: &str) -> Vec<String> {
// TODO: add the commands for each shell
// these should cover most of the builtin commands
// (maybe with false positives)
let builtin = vec![
"alias", "bg", "bind", "break", "builtin", "case", "cd", "command", "compgen", "complete",
"continue", "declare", "dirs", "disown", "echo", "enable", "eval", "exec", "exit",
"export", "fc", "fg", "getopts", "hash", "help", "history", "if", "jobs", "kill", "let",
"local", "logout", "popd", "printf", "pushd", "pwd", "read", "readonly", "return", "set",
"shift", "shopt", "source", "suspend", "test", "times", "trap", "type", "typeset",
"ulimit", "umask", "unalias", "unset", "until", "wait", "while", "which",
];
builtin.iter().map(|&cmd| cmd.to_string()).collect()
}
pub fn shell_syntax(shell: &str, command: &str) -> String {
#[allow(clippy::single_match)]
match shell {