summaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-03-07 01:54:56 -0500
committerJesse Luehrs <doy@tozt.net>2022-03-07 01:54:56 -0500
commit3c478958c77eb00367513b21200d432333a887aa (patch)
treeafd626281f58e5b3a13686981c449140d19c2542 /src/config.rs
parent0a36ee5f441260f13beda17eb5482e6bd0f9eb8c (diff)
downloadnbsh-3c478958c77eb00367513b21200d432333a887aa.tar.gz
nbsh-3c478958c77eb00367513b21200d432333a887aa.zip
basic implementation of aliases
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
new file mode 100644
index 0000000..08fa002
--- /dev/null
+++ b/src/config.rs
@@ -0,0 +1,25 @@
+use crate::prelude::*;
+
+#[derive(serde::Deserialize, Default, Debug)]
+pub struct Config {
+ aliases:
+ std::collections::HashMap<std::path::PathBuf, crate::parse::ast::Exe>,
+}
+
+impl Config {
+ pub fn load() -> Result<Self> {
+ let file = crate::dirs::config_file();
+ if std::fs::metadata(&file).is_ok() {
+ Ok(toml::from_slice(&std::fs::read(&file)?)?)
+ } else {
+ Ok(Self::default())
+ }
+ }
+
+ pub fn alias_for(
+ &self,
+ path: &std::path::Path,
+ ) -> Option<&crate::parse::ast::Exe> {
+ self.aliases.get(path)
+ }
+}