aboutsummaryrefslogtreecommitdiffstats
path: root/src/run/builtin.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/run/builtin.rs')
-rw-r--r--src/run/builtin.rs34
1 files changed, 15 insertions, 19 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(())
}