Skip to content

Commit

Permalink
fix(dotfiles): fish alias import (#1972)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellie authored Apr 22, 2024
1 parent bbf8380 commit 18f33b8
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion crates/atuin-dotfiles/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 18f33b8

Please sign in to comment.