Skip to content

Commit

Permalink
Merge pull request #389 from pacak/fish
Browse files Browse the repository at this point in the history
Release 0.9.14
  • Loading branch information
pacak authored Sep 19, 2024
2 parents 0520085 + c65ee2a commit 8f349bb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bpaf"
version = "0.9.13"
version = "0.9.14"
edition = "2021"
categories = ["command-line-interface"]
description = "A simple Command Line Argument Parser with parser combinators"
Expand Down
6 changes: 5 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## bpaf [0.9.14], 2024-09-19
- add license files (#388)
thanks @davide
- fix fish completions - you'll need to regenerate completion files for them to work

## bpaf [0.9.13], bpaf_derive [0.5.13] - 2024-09-06
- You can now use `fallback_to_usage` in derive macro for options and subcommands (#376)
- Bugfixes related to shell completion and file masks
Expand Down Expand Up @@ -401,4 +406,3 @@ Migration guide:

## [0.2.0] - 2022-03-10
### First public release

18 changes: 12 additions & 6 deletions src/complete_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ source <(eval ${{line}})
);
}

fn dump_fish_completer(_name: &str) {
fn dump_fish_completer(name: &str) {
println!(
r#"set -l current (commandline --tokenize --current-process)
set -l tmpline $current[1] --bpaf-complete-rev=9 $current[2..]
if test (commandline --current-process) != (string trim (commandline --current-process))
set tmpline $tmpline ""
r#"function _bpaf_dynamic_completion
set -l current (commandline --tokenize --current-process)
set -l tmpline --bpaf-complete-rev=9 $current[2..]
if test (commandline --current-process) != (string trim (commandline --current-process))
set tmpline $tmpline ""
end
eval $current[1] \"$tmpline\"
end
source ( $tmpline | psub )"#
complete --no-files --command {name}--arguments '(_bpaf_dynamic_completion)'
"#,
name = name
);
}

Expand Down
21 changes: 8 additions & 13 deletions src/complete_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,27 +284,22 @@ pub(crate) fn render_fish(
items: &[ShowComp],
ops: &[ShellComp],
full_lit: &str,
app: &str,
_app: &str,
) -> Result<String, std::fmt::Error> {
use std::fmt::Write;
let mut res = String::new();
if items.is_empty() && ops.is_empty() {
return Ok(format!("complete -c {} --arguments={}", app, full_lit));
writeln!(res, "{}", full_lit)?;
}
let shared = if ops.is_empty() { "-f " } else { "" };

// skip things without substitutions, I think they
// are headers and such, and fish is a bit
for item in items.iter().rev().filter(|i| !i.subst.is_empty()) {
write!(res, "complete -c {} {}", app, shared)?;
if let Some(long) = item.subst.strip_prefix("--") {
write!(res, "--long-option {} ", long)?;
} else if let Some(short) = item.subst.strip_prefix('-') {
write!(res, "--short-option {} ", short)?;
} else {
write!(res, "-a {} ", item.subst)?;
}
if let Some(help) = item.extra.help.as_deref() {
write!(res, "-d {:?}", help)?;
writeln!(res, "{}\t{}", item.subst, help)?;
} else {
writeln!(res, "{}", item.subst)?;
}
writeln!(res)?;
}

Ok(res)
Expand Down

0 comments on commit 8f349bb

Please sign in to comment.