From be12f7a72898164750b1b72c5a56de0c156e3996 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Wed, 20 Sep 2023 14:45:22 -0700 Subject: [PATCH] Make fish completion a bit smarter --- misc/completion/ocrmypdf.fish | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/misc/completion/ocrmypdf.fish b/misc/completion/ocrmypdf.fish index 20cd40e7..c279c6cb 100644 --- a/misc/completion/ocrmypdf.fish +++ b/misc/completion/ocrmypdf.fish @@ -139,4 +139,17 @@ end complete -c ocrmypdf -x -l color-conversion-strategy -a '(__fish_ocrmypdf_color_conversion_strategy)' -d "set color conversion strategy" -complete -c ocrmypdf -x -a "(__fish_complete_suffix .pdf; __fish_complete_suffix .PDF; __fish_complete_suffix .jpg; __fish_complete_suffix .png)" +function __fish_ocrmypdf_input_file_given + set -l tokens (commandline -opc) + for token in $tokens + if string match -q -r '^-' -- $token + continue + end + if test -f "$token" + return 0 + end + end + return 1 +end + +complete -c ocrmypdf -x -n 'not __fish_ocrmypdf_input_file_given' -a "(__fish_complete_suffix .pdf)" -d "input file"