-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
40 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
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,31 @@ | ||
# Usage: __rg_contains_opt LONG [SHORT] | ||
function __rg_contains_opt --description 'Specialized __fish_contains_opt' | ||
# Cache the config file because this function is called many times per | ||
# completion attempt. | ||
# The cache will persist for the entire shell session (even if the | ||
# variable or the file contents change). | ||
if not set -q __rg_config | ||
set -g __rg_config | ||
if set -qx RIPGREP_CONFIG_PATH | ||
set __rg_config ( | ||
cat -- $RIPGREP_CONFIG_PATH 2>/dev/null \ | ||
| string trim \ | ||
| string match -rv '^$|^#' | ||
) | ||
end | ||
end | ||
|
||
set -l commandline (commandline -cpo) (commandline -ct) $__rg_config | ||
|
||
if contains -- "--$argv[1]" $commandline | ||
return 0 | ||
end | ||
|
||
if set -q argv[2] | ||
if string match -qr -- "^-[^-]*$argv[2]" $commandline | ||
return 0 | ||
end | ||
end | ||
|
||
return 1 | ||
end |