diff options
author | Ellie Huxtable <ellie@elliehuxtable.com> | 2024-04-22 14:27:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-22 14:27:38 +0100 |
commit | 18f33b81f68e4a49552441f6417a3d53933faded (patch) | |
tree | b6174f01eeb993c8609b5e612792ccb507feb9fa | |
parent | bbf83801e6222618a4e160687c214cb4ee2421d5 (diff) |
fix(dotfiles): fish alias import (#1972)
-rw-r--r-- | crates/atuin-dotfiles/src/shell.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/crates/atuin-dotfiles/src/shell.rs b/crates/atuin-dotfiles/src/shell.rs index 8220ee9c..fba0a27f 100644 --- a/crates/atuin-dotfiles/src/shell.rs +++ b/crates/atuin-dotfiles/src/shell.rs @@ -17,7 +17,21 @@ pub struct 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 { return None; @@ -111,6 +125,13 @@ mod tests { } #[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] fn test_parse_with_fortune() { // Because we run the alias command in an interactive subshell // there may be other output. |