aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/parse/mod.rs2
-rw-r--r--src/run/builtin.rs28
-rw-r--r--src/run/mod.rs9
3 files changed, 27 insertions, 12 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs
index e197000..e9cb4bf 100644
--- a/src/parse/mod.rs
+++ b/src/parse/mod.rs
@@ -1,4 +1,4 @@
-use crate::{BString, bstr, PushAll};
+use crate::{BString, PushAll, bstr};
#[cfg(test)]
mod test;
diff --git a/src/run/builtin.rs b/src/run/builtin.rs
index d00c140..335d07d 100644
--- a/src/run/builtin.rs
+++ b/src/run/builtin.rs
@@ -7,7 +7,7 @@ use pish_derive::FromArgs;
use super::{Builtin, BuiltinError as Error, BuiltinResult as Result};
use crate::parse::CmdDisplay;
-use crate::run::AliasAge;
+use crate::run::{AliasAge, AliasBody};
use crate::*;
#[allow(unused)]
@@ -187,9 +187,11 @@ impl Builtin for _type {
) -> Result {
let session = session.lock().unwrap();
for arg in args {
- 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))?;
+ if let Some((_, a)) = session.aliases.get(arg, AliasAge::MAX) {
+ stdout.write_all(&arg)?;
+ stdout.write_all(b" is aliased to ")?;
+ stdout.write_all(&a.unparsed)?;
+ stdout.write_all(b"\n")?;
continue;
}
@@ -496,11 +498,19 @@ impl Builtin for alias {
return Err(Error::Exit(-1));
}
- session
- .lock()
- .unwrap()
- .aliases
- .insert(alias_name.clone(), alias_args);
+ session.lock().unwrap().aliases.insert(
+ alias_name.clone(),
+ AliasBody {
+ unparsed: args.iter().fold(BString::new(), |mut a, b| {
+ if !a.is_empty() {
+ a.push(b' ');
+ }
+ a.push_all(&b);
+ a
+ }),
+ parsed: alias_args,
+ },
+ );
Ok(())
}
diff --git a/src/run/mod.rs b/src/run/mod.rs
index b3ed851..52d3925 100644
--- a/src/run/mod.rs
+++ b/src/run/mod.rs
@@ -529,12 +529,17 @@ impl parse::Expander for Executor {
.lock()
.unwrap()
.aliases
- .get(cmd, older_than.unwrap_or(AliasAge::MAX)))
+ .get(cmd, older_than.unwrap_or(AliasAge::MAX))
+ .map(|(age, body)| (age, body.parsed)))
}
}
type AliasAge = u32;
-type AliasBody = Vec<ExpString>;
+#[derive(Clone)]
+pub struct AliasBody {
+ pub unparsed: BString,
+ pub parsed: Vec<ExpString>,
+}
type AliasSet = Vec<(AliasAge, AliasBody)>;
pub struct Aliases {