mirror of
https://github.com/atuinsh/atuin.git
synced 2025-06-25 12:21:55 +02:00
fix(dotfiles): fish alias import (#1972)
This commit is contained in:
parent
bbf83801e6
commit
18f33b81f6
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user