Skip to content

Commit 0e1543b

Browse files
committed
Improve fish file completion
1 parent 9afa25c commit 0e1543b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

completions/xh.fish

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Complete paths after @ in options:
2+
function __xh_complete_data
3+
string match -qr '^(?<prefix>.*@)(?<path>.*)' -- (commandline -ct)
4+
printf '%s\n' -- $prefix(__fish_complete_path $path)
5+
end
6+
complete -c xh -n 'string match -qr "@" -- (commandline -ct)' -kxa "(__xh_complete_data)"
7+
18
complete -c xh -l raw -d 'Pass raw request data without extra processing' -r
29
complete -c xh -l pretty -d 'Controls output processing' -r -f -a "all\t'(default) Enable both coloring and formatting'
310
colors\t'Apply syntax highlighting to output'

src/generation.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,23 @@ pub fn generate(bin_name: &str, generate: Generate) {
1919
clap_complete::generate(Shell::Elvish, &mut app, bin_name, &mut io::stdout());
2020
}
2121
Generate::CompleteFish => {
22-
clap_complete::generate(Shell::Fish, &mut app, bin_name, &mut io::stdout());
22+
use std::io::Write;
23+
let mut buf = Vec::new();
24+
clap_complete::generate(Shell::Fish, &mut app, bin_name, &mut buf);
25+
let mut stdout = io::stdout();
26+
let preamble = format!(
27+
r#"# Complete paths after @ in options:
28+
function __xh_complete_data
29+
string match -qr '^(?<prefix>.*@)(?<path>.*)' -- (commandline -ct)
30+
printf '%s\n' -- $prefix(__fish_complete_path $path)
31+
end
32+
complete -c {bin_name} -n 'string match -qr "@" -- (commandline -ct)' -kxa "(__xh_complete_data)"
33+
34+
"#,
35+
bin_name = bin_name,
36+
);
37+
stdout.write_all(preamble.as_bytes()).unwrap();
38+
stdout.write_all(&buf).unwrap();
2339
}
2440
Generate::CompleteNushell => {
2541
clap_complete::generate(Nushell, &mut app, bin_name, &mut io::stdout());

0 commit comments

Comments
 (0)