-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//! Complete commands within fish | ||
|
||
// For fish the behaviour should match the default as close as possible | ||
// 1. grouping shorthand completions i.e. -a<TAB> should show other shorthands to end up with | ||
// -ams... | ||
// 2. only complete options when one - is typed | ||
// Due to https://github.com/fish-shell/fish-shell/issues/7943 we need to implement this our self | ||
// | ||
|
||
use std::ffi::OsString; | ||
|
||
use clap::Args; | ||
|
||
use super::Completer; | ||
|
||
/// Dynamic completion for Fish | ||
pub struct Fish; | ||
|
||
impl Completer for Fish { | ||
type CompleteArgs = CompleteArgs; | ||
|
||
fn completion_script(cmd: &mut clap::Command) -> Vec<u8> { | ||
let name = cmd.get_bin_name().unwrap_or_else(|| cmd.get_name()); | ||
format!( | ||
r#"complete -x -c {name} -a "{name} complete --commandline (commandline) --cursor (commandline -C)""# | ||
).into_bytes() | ||
} | ||
|
||
fn file_name(name: &str) -> String { | ||
format!("{name}.fish") | ||
} | ||
|
||
fn try_complete(args: &Self::CompleteArgs, cmd: &mut clap::Command) -> clap::error::Result<()> { | ||
todo!() | ||
} | ||
} | ||
|
||
#[derive(Args, Clone, Debug)] | ||
/// Arguments for Fish Completion | ||
pub struct CompleteArgs { | ||
/// current commandline | ||
#[arg(long)] | ||
commandline: OsString, | ||
/// cursor position | ||
#[arg(long)] | ||
cursor: usize, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters