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 { - 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; @@ -110,6 +124,13 @@ mod tests { 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] fn test_parse_with_fortune() { // Because we run the alias command in an interactive subshell