From 09217fb17940df1091cbe57081e4f1ee194366f8 Mon Sep 17 00:00:00 2001 From: iff Date: Tue, 8 Apr 2025 20:40:58 +0200 Subject: [PATCH] fix: builtin commands --- Cargo.lock | 1 + core/Cargo.toml | 1 + core/src/shell.rs | 22 +++++++++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index bc0b35e..d87c5c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -967,6 +967,7 @@ dependencies = [ "askama", "colored", "inquire", + "itertools 0.14.0", "pay-respects-parser", "pay-respects-utils", "regex-lite", diff --git a/core/Cargo.toml b/core/Cargo.toml index b35a002..c4d28b0 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -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 = [ diff --git a/core/src/shell.rs b/core/src/shell.rs index 6701368..ce70678 100644 --- a/core/src/shell.rs +++ b/core/src/shell.rs @@ -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 { + // 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 {