Skip to content

Commit

Permalink
Complete recipe names in fish completion script (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyehle authored May 4, 2020
1 parent dc7210b commit fef69a3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions completions/just.fish
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
function __fish_just_complete_recipes
just --summary 2> /dev/null | tr " " "\n" || echo ""
end

# don't suggest files right off
complete -c just -n "__fish_is_first_arg" --no-files

# complete recipes
complete -c just -a '(__fish_just_complete_recipes)'

# autogenerated completions
complete -c just -n "__fish_use_subcommand" -l color -d 'Print colorful output' -r -f -a "auto always never"
complete -c just -n "__fish_use_subcommand" -s f -l justfile -d 'Use <JUSTFILE> as justfile.'
complete -c just -n "__fish_use_subcommand" -l set -d 'Override <VARIABLE> with <VALUE>'
Expand Down
17 changes: 17 additions & 0 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ pub(crate) enum Subcommand {
Variables,
}

const FISH_RECIPE_COMPLETIONS: &str = r#"function __fish_just_complete_recipes
just --summary 2> /dev/null | tr " " "\n" || echo ""
end
# don't suggest files right off
complete -c just -n "__fish_is_first_arg" --no-files
# complete recipes
complete -c just -a '(__fish_just_complete_recipes)'
# autogenerated completions
"#;

const ZSH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[
(
r#" _arguments "${_arguments_options[@]}" \"#,
Expand Down Expand Up @@ -127,6 +140,10 @@ impl Subcommand {
}
}

if let clap::Shell::Fish = shell {
script.insert_str(0, FISH_RECIPE_COMPLETIONS);
}

println!("{}", script.trim());

Ok(())
Expand Down

0 comments on commit fef69a3

Please sign in to comment.