Skip to content

Commit 6af77fb

Browse files
committed
Enable to use command-not-found
1 parent 1350545 commit 6af77fb

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

.sushrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,7 @@ _colcon_comp () {
5757
} && complete -F _colcon_comp colcon
5858

5959
complete -u groups w
60+
61+
command_not_found_handle() {
62+
/usr/lib/command-not-found -- "$1"
63+
}

src/elements/command/simple.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
pub mod parser;
55

6-
use crate::ShellCore;
6+
use crate::{Feeder, Script, ShellCore};
77
use crate::utils::exit;
88
use super::{Command, Pipe, Redirect};
99
use crate::core::data::Value;
@@ -98,7 +98,17 @@ impl SimpleCommand {
9898
match unistd::execvp(&cargs[0], &cargs) {
9999
Err(Errno::E2BIG) => exit::arg_list_too_long(&self.args[0], core),
100100
Err(Errno::EACCES) => exit::permission_denied(&self.args[0], core),
101-
Err(Errno::ENOENT) => exit::not_found(&self.args[0], core),
101+
Err(Errno::ENOENT) => {
102+
if core.data.functions.contains_key("command_not_found_handle") {
103+
let s = "command_not_found_handle ".to_owned() + &self.args[0].clone();
104+
let mut f = Feeder::new(&s);
105+
match Script::parse(&mut f, core, false) {
106+
Some(mut script) => script.exec(core),
107+
_ => {},
108+
}
109+
}
110+
exit::not_found(&self.args[0], core)
111+
},
102112
Err(err) => {
103113
eprintln!("Failed to execute. {:?}", err);
104114
process::exit(127)

0 commit comments

Comments
 (0)