aboutsummaryrefslogtreecommitdiffstats
path: root/src/run
diff options
context:
space:
mode:
authorJonas Maier <jonas@x77.dev>2026-05-12 21:59:30 +0200
committerJonas Maier <jonas@x77.dev>2026-05-12 21:59:30 +0200
commit78113ac6bc17546a91b4b597417184dc0f89eab1 (patch)
tree1f63dcec48f7f10c2546b9108b2c05ed1a261f9d /src/run
parent4c3736eb368fa106dfa6c29a1794aeb1d4c9a1de (diff)
downloadpish-78113ac6bc17546a91b4b597417184dc0f89eab1.tar.gz
clippy
Diffstat (limited to 'src/run')
-rw-r--r--src/run/builtin.rs34
-rw-r--r--src/run/mod.rs11
2 files changed, 22 insertions, 23 deletions
diff --git a/src/run/builtin.rs b/src/run/builtin.rs
index b731b10..044206d 100644
--- a/src/run/builtin.rs
+++ b/src/run/builtin.rs
@@ -187,7 +187,7 @@ impl Builtin for _type {
) -> Result {
let session = session.lock().unwrap();
for arg in args {
- if session.aliases.get(&arg, AliasAge::MAX).is_some() {
+ if session.aliases.get(arg, AliasAge::MAX).is_some() {
// TODO: tell what it is aliased to
writeln!(stdout, "{} is an alias", String::from_utf8_lossy(arg))?;
continue;
@@ -383,7 +383,7 @@ impl Builtin for completion {
stdout: &mut dyn Write,
) -> Result {
for arg in args {
- let c = crate::completion(session.clone(), &arg);
+ let c = crate::completion(session.clone(), arg);
write!(stdout, "{:?} ", c.kind)?;
stdout.write_all(&c.shared_prefix)?;
for s in c.suggestions {
@@ -581,7 +581,7 @@ impl bind {
fn is_interactive(args: &[BString]) -> bool {
matches!(
- args.get(0).map(|x| &x[..]),
+ args.first().map(|x| &x[..]),
Some(b"i" | b"interactive" | b"del" | b"delete")
)
}
@@ -616,7 +616,7 @@ impl Builtin for bind {
Err(Error::Exit(1))
};
- if args.len() == 0 {
+ if args.is_empty() {
let mut dump = |map: &HashMap<BString, crate::parse::Command<PostExpansion>>,
category: &str|
-> std::io::Result<()> {
@@ -639,10 +639,6 @@ impl Builtin for bind {
return Ok(());
}
- if args.len() < 1 {
- return usage();
- }
-
let kind = &args[0];
let mut se = session.lock().unwrap();
@@ -701,7 +697,7 @@ impl Builtin for bind {
// print what gets bound
write!(stdout, "bind {x} ")?;
for arg in args.iter().skip(1) {
- stdout.write(&arg[..])?;
+ stdout.write_all(&arg[..])?;
write!(stdout, " ")?;
}
writeln!(stdout)?;
@@ -728,22 +724,22 @@ impl Builtin for exit {
}
fn special(&mut self, _session: Arc<Mutex<Session>>, args: &[BString]) {
- let exit_code: i32 = loop {
- let Some(arg) = args.get(0) else {
- break 0;
+ fn parse_exit_code(x: Option<&BString>) -> i32 {
+ let Some(arg) = x else {
+ return 0;
};
let Ok(arg) = String::from_utf8(arg.clone()) else {
- break 1;
+ return 1;
};
let Ok(num) = arg.parse() else {
- break 1;
+ return 1;
};
- break num;
- };
+ num
+ }
println!("bye!\r");
- std::process::exit(exit_code);
+ std::process::exit(parse_exit_code(args.first()));
}
fn io(
@@ -772,7 +768,7 @@ impl Builtin for ct {
_stdin: &mut dyn Read,
_stdout: &mut dyn Write,
) -> Result {
- let Some(arg) = args.get(0) else {
+ let Some(arg) = args.first() else {
return Err(Error::Exit(-1));
};
@@ -933,7 +929,7 @@ impl Builtin for export {
) -> Result {
let mut session = session.lock().unwrap();
for v in args.iter() {
- session.vars.allow_export(&v, true);
+ session.vars.allow_export(v, true);
}
Ok(())
}
diff --git a/src/run/mod.rs b/src/run/mod.rs
index 8be5fca..b3ed851 100644
--- a/src/run/mod.rs
+++ b/src/run/mod.rs
@@ -562,10 +562,7 @@ impl Aliases {
}
fn get(&self, name: &bstr, older_than: AliasAge) -> Option<(AliasAge, AliasBody)> {
- let Some(alias_set) = self.aliases.get(name) else {
- return None;
- };
-
+ let alias_set = self.aliases.get(name)?;
alias_set.iter().rev().find(|e| e.0 < older_than).cloned()
}
@@ -574,6 +571,12 @@ impl Aliases {
}
}
+impl Default for Aliases {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
fn exec(se: Arc<Mutex<Session>>, ast: Ast<PreExpansion>) -> Result<(), ExecError> {
let mut exec = Executor::new(se.clone());
let ast = ast.expand(&mut exec)?;