fix(dotfiles): fish alias import (#1972)

This commit is contained in:
Ellie Huxtable 2024-04-22 14:27:38 +01:00 committed by GitHub
parent bbf83801e6
commit 18f33b81f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -17,7 +17,21 @@ pub struct Alias {
} }
pub fn parse_alias(line: &str) -> Option<Alias> { pub fn parse_alias(line: &str) -> Option<Alias> {
let parts: Vec<&str> = line.split('=').collect(); // consider the fact we might be importing a fish alias
// 'alias' output
// fish: alias foo bar
// posix: foo=bar
let is_fish = line.split(' ').next().unwrap_or("") == "alias";
let parts: Vec<&str> = if is_fish {
line.split(' ')
.enumerate()
.filter_map(|(n, i)| if n == 0 { None } else { Some(i) })
.collect()
} else {
line.split('=').collect()
};
if parts.len() <= 1 { if parts.len() <= 1 {
return None; return None;
@ -110,6 +124,13 @@ mod tests {
assert_eq!(alias.value, "'TERM=xterm-24bits emacs -nw --foo=bar'"); assert_eq!(alias.value, "'TERM=xterm-24bits emacs -nw --foo=bar'");
} }
#[test]
fn test_parse_fish() {
let alias = super::parse_alias("alias foo bar").expect("failed to parse alias");
assert_eq!(alias.name, "foo");
assert_eq!(alias.value, "bar");
}
#[test] #[test]
fn test_parse_with_fortune() { fn test_parse_with_fortune() {
// Because we run the alias command in an interactive subshell // Because we run the alias command in an interactive subshell