Now reading aliases and hotkeys
This commit is contained in:
parent
344f14c86f
commit
6abe6d886d
10
sqishrc.yaml
10
sqishrc.yaml
@ -24,3 +24,13 @@
|
||||
#For example $RGB|108|84|30_ gives you an ugly shade of brown
|
||||
prompt: "$COLORLBLACK_ !$HISTNUMBER_$COLORCYAN_[$USER_@$HOSTNAME_]$RGB|125|0|125_$DIR_> $COLORRESET_"
|
||||
|
||||
#Classic aliases
|
||||
aliases:
|
||||
gcl: git clone
|
||||
gpl: git pull
|
||||
|
||||
#Hotkeys : When pressing Alt + the letter (a, b... up to y), enters the text inside the command
|
||||
#Alt + Z Cancels last hotkey
|
||||
hotkeys:
|
||||
a: "| less"
|
||||
b: "exit"
|
||||
|
@ -7,7 +7,7 @@ use regex::Regex;
|
||||
extern crate dirs;
|
||||
|
||||
extern crate yaml_rust;
|
||||
use yaml_rust::{YamlLoader};
|
||||
use yaml_rust::{YamlLoader, Yaml};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SqishConf {
|
||||
@ -44,13 +44,23 @@ impl SqishConf {
|
||||
let sqishrc = &sqishrc[0];
|
||||
let out_str = String::from(sqishrc["prompt"].as_str().unwrap());
|
||||
|
||||
//Loading hotkeys and aliases from yaml
|
||||
//They can be empty, be careful...
|
||||
let aliases_yaml = &sqishrc["aliases"];
|
||||
let aliases = Self::yaml_dict2hashmap(aliases_yaml);
|
||||
|
||||
let hotkeys_yaml = &sqishrc["hotkeys"];
|
||||
let hotkeys = Self::yaml_dict2hashmap(hotkeys_yaml);
|
||||
|
||||
let mut out_conf = SqishConf {
|
||||
promptline: out_str.clone(),
|
||||
promptline_base: out_str,
|
||||
aliases: HashMap::new(),
|
||||
hotkeys: HashMap::new(),
|
||||
aliases: aliases,
|
||||
hotkeys: hotkeys,
|
||||
};
|
||||
|
||||
println!("{:?}", out_conf);
|
||||
|
||||
out_conf.handle_rgb();
|
||||
out_conf.handle_colors();
|
||||
|
||||
@ -164,5 +174,18 @@ impl SqishConf {
|
||||
}
|
||||
}
|
||||
|
||||
///Takes a YAML dict and converts it into an hashmap.
|
||||
fn yaml_dict2hashmap(yaml_dict: &Yaml) -> HashMap<String, String> {
|
||||
let mut my_hashmap = HashMap::new();
|
||||
|
||||
if let Yaml::Hash(h) = yaml_dict {
|
||||
for (k, v) in h.iter() {
|
||||
if let (Yaml::String(k), Yaml::String(v)) = (k, v) {
|
||||
my_hashmap.insert(k.clone(), v.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
return my_hashmap;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user