forked from AbleOS/ableos
28 lines
717 B
Rust
28 lines
717 B
Rust
|
use hashbrown::HashMap;
|
||
|
|
||
|
lazy_static::lazy_static! {
|
||
|
pub static ref ALIAS_TABLE: spin::Mutex<AliasTable> = spin::Mutex::new(AliasTable::new());
|
||
|
}
|
||
|
/// A table of aliases
|
||
|
///
|
||
|
/// This is used to allow users to specify aliases for files and commands
|
||
|
pub struct AliasTable {
|
||
|
pub table: HashMap<String, String>,
|
||
|
}
|
||
|
|
||
|
impl AliasTable {
|
||
|
pub fn new() -> Self {
|
||
|
Self {
|
||
|
table: HashMap::new(),
|
||
|
}
|
||
|
}
|
||
|
pub fn add_alias(&mut self, alias: String, path: String) {
|
||
|
self.table.insert(alias, path);
|
||
|
}
|
||
|
|
||
|
pub fn get_alias(&self, alias: String) -> Option<String> {
|
||
|
let alias_table = ALIAS_TABLE.lock();
|
||
|
alias_table.table.get(&alias).map(|x| x.to_string())
|
||
|
}
|
||
|
}
|