complete/fish: Take RIPGREP_CONFIG_PATH into account
The fish completions now also pay attention to the configuration file to determine whether to suggest negation options and not just to the current command line. This doesn't cover all edge cases. For example the config file is cached, and so changes may not take effect until the next shell session. But the cases it doesn't cover are hopefully very rare. Closes #2708
This commit is contained in:
committed by
Andrew Gallant
parent
90a680ab45
commit
f722268814
@@ -6,11 +6,15 @@ use crate::flags::{defs::FLAGS, CompletionType};
|
||||
|
||||
const TEMPLATE: &'static str = "complete -c rg !SHORT! -l !LONG! -d '!DOC!'";
|
||||
const TEMPLATE_NEGATED: &'static str =
|
||||
"complete -c rg -l !NEGATED! -n '__fish_contains_opt !SHORT! !LONG!' -d '!DOC!'\n";
|
||||
"complete -c rg -l !NEGATED! -n '__rg_contains_opt !LONG! !SHORT!' -d '!DOC!'\n";
|
||||
|
||||
/// Generate completions for Fish.
|
||||
///
|
||||
/// Reference: <https://fishshell.com/docs/current/completions.html>
|
||||
pub(crate) fn generate() -> String {
|
||||
let mut out = String::new();
|
||||
out.push_str(include_str!("prelude.fish"));
|
||||
out.push('\n');
|
||||
for flag in FLAGS.iter() {
|
||||
let short = match flag.name_short() {
|
||||
None => "".to_string(),
|
||||
@@ -55,6 +59,10 @@ pub(crate) fn generate() -> String {
|
||||
out.push_str(&completion);
|
||||
|
||||
if let Some(negated) = flag.name_negated() {
|
||||
let short = match flag.name_short() {
|
||||
None => "".to_string(),
|
||||
Some(byte) => char::from(byte).to_string(),
|
||||
};
|
||||
out.push_str(
|
||||
&TEMPLATE_NEGATED
|
||||
.replace("!NEGATED!", &negated)
|
||||
|
||||
Reference in New Issue
Block a user