Fixes #8924 via __fish_complete_suffix overhaul

Before:
* hand write arg parse
* only accepts one suffix

After:
* use `arg_parse` to parse args
* accepts multi suffixes

Closes #9611.
This commit is contained in:
lengyijun 2023-02-24 10:18:08 +08:00 committed by Mahmoud Al-Qudsi
parent dea18b34aa
commit aa65856ee0
36 changed files with 74 additions and 208 deletions

View File

@ -1,12 +1,4 @@
complete -x -c asciidoctor -k -a "
(
__fish_complete_suffix .asciidoc
__fish_complete_suffix .adoc
__fish_complete_suffix .ad
__fish_complete_suffix .asc
__fish_complete_suffix .txt
)
"
complete -x -c asciidoctor -k -a "(__fish_complete_suffix .asciidoc .adoc .ad .asc .txt)"
# Security Settings
complete -c asciidoctor -s B -l base-dir -d "Base directory containing the document"

View File

@ -2,7 +2,7 @@
complete -f -c at -s V -d "Display version and exit"
complete -f -c at -s q -d "Use specified queue"
complete -f -c at -s m -d "Send mail to user"
complete -c at -s f -k -x -a "(__fish_complete_suffix (commandline -ct) '' 'At job')" -d "Read job from file"
complete -c at -s f -k -x -a "(__fish_complete_suffix --description='At job' '')" -d "Read job from file"
complete -f -c at -s l -d "Alias for atq"
complete -f -c at -s d -d "Alias for atrm"
complete -f -c at -s v -d "Show the time"

View File

@ -163,6 +163,4 @@ complete -c aura -n $sync -s y -l refresh -d 'Download fresh copy of the package
complete -c aura -n "$sync; and $argument" -xa "$listall $listgroups"
# Upgrade options
complete -c aura -n "$upgrade; and $argument" -k -xa '(__fish_complete_suffix pkg.tar.xz)' -d 'Package file'
complete -c aura -n "$upgrade; and $argument" -k -xa '(__fish_complete_suffix pkg.tar.gz)' -d 'Package file'
complete -c aura -n "$upgrade; and $argument" -k -xa '(__fish_complete_suffix pkg.tar.zst)' -d 'Package file'
complete -c aura -n "$upgrade; and $argument" -k -xa '(__fish_complete_suffix pkg.tar.xz pkg.tar.gz pkg.tar.zst)' -d 'Package file'

View File

@ -1,14 +1,4 @@
complete -c bunzip2 -k -x -a "(
__fish_complete_suffix .tbz
__fish_complete_suffix .tbz2
)
"
complete -c bunzip2 -k -x -a "(
__fish_complete_suffix .bz
__fish_complete_suffix .bz2
)
"
complete -c bunzip2 -k -x -a "(__fish_complete_suffix .tbz .tbz2 .bz2 .bz)"
complete -c bunzip2 -s c -l stdout -d "Decompress to stdout"
complete -c bunzip2 -s f -l force -d Overwrite

View File

@ -1,13 +1,3 @@
complete -c bzcat -k -x -a "(
__fish_complete_suffix .tbz
__fish_complete_suffix .tbz2
)
"
complete -c bzcat -k -x -a "(
__fish_complete_suffix .bz
__fish_complete_suffix .bz2
)
"
complete -c bzcat -k -x -a "(__fish_complete_suffix .tbz .tbz2 .bz .bz2)"
complete -c bzcat -s s -l small -d "Reduce memory usage"

View File

@ -1,15 +1,5 @@
complete -c bzip2 -s c -l stdout -d "Compress to stdout"
complete -c bzip2 -s d -l decompress -k -x -a "(
__fish_complete_suffix .tbz
__fish_complete_suffix .tbz2
)
"
complete -c bzip2 -s d -l decompress -k -x -a "(
__fish_complete_suffix .bz
__fish_complete_suffix .bz2
)
"
complete -c bzip2 -s d -l decompress -k -x -a "(__fish_complete_suffix .tbz .tbz2 .bz .bz2)"
complete -c bzip2 -s z -l compress -d "Compress file"
complete -c bzip2 -s t -l test -d "Check integrity"

View File

@ -1,11 +1,2 @@
complete -c bzip2recover -k -x -a "(
__fish_complete_suffix .tbz
__fish_complete_suffix .tbz2
)
"
complete -c bzip2recover -k -x -a "(__fish_complete_suffix .tbz .tbz2 .bz .bz2)"
complete -c bzip2recover -k -x -a "(
__fish_complete_suffix .bz
__fish_complete_suffix .bz2
)
"

View File

@ -6,10 +6,7 @@ set -l __fish_castnow_keys "space\tToggle\ between\ play\ and\ pause m\tToggle\
complete -c castnow -l tomp4 -d "Convert file to mp4 during playback"
complete -c castnow -l device -d "Specify name of Chromecast device to be used" -x
complete -c castnow -l address -d "Specify IP or hostname of Chromecast device" -x
complete -c castnow -l subtitles -d "Path or URL to SRT or VTT file" -k -x -a "(
__fish_complete_suffix .srt
__fish_complete_suffix .vtt
)"
complete -c castnow -l subtitles -d "Path or URL to SRT or VTT file" -k -x -a "(__fish_complete_suffix .srt .vtt)"
complete -c castnow -l subtitles-scale -d "Set subtitles font scale" -x
complete -c castnow -l subtitles-color -d "Set subtitles font RGBA color" -x
complete -c castnow -l subtitles-port -d "Specify port to be used for serving subtitles" -x

View File

@ -4,4 +4,4 @@
complete -p '*clang++*' -n __fish_should_complete_switches -xa '(__fish_complete_clang)'
complete -p '*clang++*' -n 'not __fish_should_complete_switches' \
-k -xa "(__fish_complete_suffix .o; __fish_complete_suffix .out; __fish_complete_suffix .c; __fish_complete_suffix .cpp; __fish_complete_suffix .so; __fish_complete_suffix .dylib)"
-k -xa "(__fish_complete_suffix .o .out .c .cpp .so .dylib)"

View File

@ -5,8 +5,8 @@
# This pattern unfortunately matches clang-format, etc. as well.
complete -p '*clang*' -n __fish_should_complete_switches -xa '(__fish_complete_clang)'
complete -c clang -n 'not __fish_should_complete_switches' \
-k -xa "(__fish_complete_suffix .o; __fish_complete_suffix .out; __fish_complete_suffix .c; __fish_complete_suffix .cpp; __fish_complete_suffix .so; __fish_complete_suffix .dylib)"
-k -xa "(__fish_complete_suffix .o .out .c .cpp .so .dylib)"
# again but without the -x this time for the pattern-matched completion
complete -p '*clang*' -n 'not __fish_should_complete_switches' \
-k -a "(__fish_complete_suffix .o; __fish_complete_suffix .out; __fish_complete_suffix .c; __fish_complete_suffix .cpp; __fish_complete_suffix .so; __fish_complete_suffix .dylib)"
-k -a "(__fish_complete_suffix .o .out .c .cpp .so .dylib)"

View File

@ -1,9 +1,4 @@
complete -k -x -c cmark -a "
(
__fish_complete_suffix .md
__fish_complete_suffix .markdown
)
"
complete -k -x -c cmark -a "(__fish_complete_suffix .md .markdown)"
complete -x -c cmark -s t -l to -a "html man xml latex commonmark" -d "Output format"
complete -c cmark -l width -d "Wrap width"

View File

@ -1,4 +1,4 @@
complete -c curl -n 'string match -qr "^@" -- (commandline -ct)' -k -xa "(printf '%s\n' -- @(__fish_complete_suffix (commandline -ct | string replace -r '^@' '') ''))"
complete -c curl -n 'string match -qr "^@" -- (commandline -ct)' -k -xa "(printf '%s\n' -- @(__fish_complete_suffix --complete=(commandline -ct | string replace -r '^@' '') ''))"
# These based on the autogenerated completions.
complete -c curl -l abstract-unix-socket -d '(HTTP) Connect through an abstract Unix domain socket'

View File

@ -1,9 +1,5 @@
complete -c gunzip -s c -l stdout -d "Compress to stdout"
complete -c gunzip -k -x -a "(
__fish_complete_suffix .gz
__fish_complete_suffix .tgz
)
"
complete -c gunzip -k -x -a "(__fish_complete_suffix .gz .tgz)"
complete -c gunzip -s f -l force -d Overwrite
complete -c gunzip -s h -l help -d "Display help and exit"
complete -c gunzip -s k -l keep -d "Keep input files"

View File

@ -1,7 +1,4 @@
complete -c gv -k -xa "(__fish_complete_suffix .ps)"
complete -c gv -k -xa "(__fish_complete_suffix .ps.gz)"
complete -c gv -k -xa "(__fish_complete_suffix .eps)"
complete -c gv -k -xa "(__fish_complete_suffix .pdf)"
complete -c gv -k -xa "(__fish_complete_suffix .ps .ps.gz .eps .pdf)"
complete -c gv -l monochrome -d 'Display document using only black and white'
complete -c gv -l grayscale -d 'Display document without colors'
complete -c gv -l color -d 'Display document as usual'

View File

@ -1,10 +1,5 @@
complete -c gzip -s c -l stdout -d "Compress to stdout"
complete -c gzip -s d -l decompress -k -x -a "
(
__fish_complete_suffix .gz
__fish_complete_suffix .tgz
)
"
complete -c gzip -s d -l decompress -k -x -a "(__fish_complete_suffix .gz .tgz)"
complete -c gzip -s f -l force -d Overwrite
complete -c gzip -s h -l help -d "Display help and exit"

View File

@ -11,4 +11,4 @@ complete -c hjson -n __fish_should_complete_switches -a -rt -d "round trip comme
complete -c hjson -n __fish_should_complete_switches -a -nocol -d "disable color output"
complete -c hjson -n __fish_should_complete_switches -a "-cond=" -d "set condense option [default 60]"
complete -c hjson -k -xa "(__fish_complete_suffix .hjson; __fish_complete_suffix .json)"
complete -c hjson -k -xa "(__fish_complete_suffix .hjson .json)"

View File

@ -1,6 +1,6 @@
# Completions for the FreeBSD `kldload` kernel module load utility
function __fish_list_kldload_options
set -l klds (__fish_complete_suffix /boot/kernel/(commandline -ct) ".ko" | string replace -r '.*/(.+)\\.ko' '$1')
set -l klds (__fish_complete_suffix --complete=/boot/kernel/(commandline -ct) ".ko" | string replace -r '.*/(.+)\\.ko' '$1')
# Completing available klds is fast, but completing it with a call to __fish_whatis
# is decidedly not. With 846 modules (FreeBSD 11.1), fish --profile 'complete -C"kldload "' returns the following:
# 10671 11892698 > complete -C"kldload "

View File

@ -1,4 +1,4 @@
complete -c latexmk -k -x -a "(__fish_complete_suffix (commandline -ct) .tex '(La)TeX file')"
complete -c latexmk -k -x -a "(__fish_complete_suffix --description='(La)TeX file' .tex)"
complete -c latexmk -o bibtex -d 'use bibtex when needed (default)'
complete -c latexmk -o bibtex- -d 'never use bibtex'
complete -c latexmk -o bibtex-cond -d 'use bibtex when needed, but only if the bib files exist'

View File

@ -1,6 +1,5 @@
__fish_complete_lpr lp
complete -c lpr -k -xa "(__fish_complete_suffix .pdf)"
complete -c lpr -k -xa "(__fish_complete_suffix .ps)"
complete -c lpr -k -xa "(__fish_complete_suffix .pdf .ps)"
complete -c lp -s d -d 'Prints files to the named printer' -xa '(__fish_print_lpr_printers)'
complete -c lp -s i -d 'Specifies an existing job to modify' -x
complete -c lp -s n -d 'Sets the number of copies to print from 1 to 100' -x

View File

@ -8,7 +8,7 @@ complete -c lpadmin -s v -d 'Sets the device-uri attribute of the printer queue'
complete -c lpadmin -s D -d 'Provides a textual description of the destination' -x
complete -c lpadmin -s E -d 'Enables the destination and accepts jobs'
complete -c lpadmin -s L -d 'Provides a textual location of the destination' -x
complete -c lpadmin -s P -d 'Specify a PDD file to use with the printer' -k -xa "(__fish_complete_suffix .ppd; __fish_complete_suffix .ppd.gz)"
complete -c lpadmin -s P -d 'Specify a PDD file to use with the printer' -k -xa "(__fish_complete_suffix .ppd .ppd.gz)"
complete -c lpadmin -s o -xa cupsIPPSupplies=true -d 'Specify if IPP supply level values should be reported'
complete -c lpadmin -s o -xa cupsIPPSupplies=false -d 'Specify if IPP supply level values should be reported'
complete -c lpadmin -s o -xa cupsSNMPSupplies=true -d 'Specify if SNMP supply level values should be reported'

View File

@ -1,6 +1,5 @@
__fish_complete_lpr lpr
complete -c lpr -k -xa "(__fish_complete_suffix .pdf)"
complete -c lpr -k -xa "(__fish_complete_suffix .ps)"
complete -c lpr -k -xa "(__fish_complete_suffix .pdf .ps)"
complete -c lpr -s H -x -d 'Specifies an alternate server' -xa '(__fish_print_hostnames)'
complete -c lpr -s C -s J -s T -x -d 'Sets the job name'
#complete -c lpr -o '\\#' -d 'Sets the number of copies to print from 1 to 100' -xa

View File

@ -13,7 +13,7 @@ end
# The results of this function are as if __fish_complete_suffix were called
# while cd'd into the openocd scripts directory
function __fish_complete_openocd_path
__fish_complete_suffix (commandline -ct) "$argv[1]" "$argv[2]" (__fish_openocd_prefix)/share/openocd/scripts
__fish_complete_suffix --prefix=(__fish_openocd_prefix)/share/openocd/scripts "$argv[1]"
end
complete -c openocd -f # at no point does openocd take arbitrary arguments

View File

@ -37,6 +37,6 @@ complete -x -c optipng -n __fish_should_complete_switches -a '-dir\t"write outpu
complete -x -c optipng -n __fish_should_complete_switches -a '-log\t"log messages to <file>"'
complete -x -c optipng -n 'not __fish_prev_arg_in -out -dir -log' \
-k -a '(__fish_complete_suffix .png; __fish_complete_suffix .pnm; __fish_complete_suffix .tiff; __fish_complete_suffix .bmp)'
-k -a '(__fish_complete_suffix .png .pnm .tiff .bmp)'
complete -x -c optipng -n '__fish_prev_arg_in -dir' -a '(__fish_complete_directories)'

View File

@ -159,4 +159,4 @@ complete -c $progname -n "$files" -l machinereadable -d 'Show in machine readabl
# Upgrade options
# Theoretically, pacman reads packages in all formats that libarchive supports
# In practice, it's going to be tar.xz or tar.gz or tar.zst
complete -c $progname -n "$upgrade" -k -xa '(__fish_complete_suffix pkg.tar.zst; __fish_complete_suffix pkg.tar.xz; __fish_complete_suffix pkg.tar.gz)' -d 'Package file'
complete -c $progname -n "$upgrade" -k -xa '(__fish_complete_suffix pkg.tar.zst pkg.tar.xz pkg.tar.gz)' -d 'Package file'

View File

@ -141,4 +141,4 @@ complete -c $progname -n "$sync" -xa "$listall $listgroups"
# Upgrade options
# Theoretically, pacman reads packages in all formats that libarchive supports
# In practice, it's going to be tar.xz, tar.gz, tar.zst, or just pkg.tar (uncompressed pkg)
complete -c $progname -n "$upgrade" -k -xa '(__fish_complete_suffix pkg.tar.zst; __fish_complete_suffix pkg.tar.xz; __fish_complete_suffix pkg.tar.gz; __fish_complete_suffix pkg.tar;)' -d 'Package file'
complete -c $progname -n "$upgrade" -k -xa '(__fish_complete_suffix pkg.tar.zst pkg.tar.xz pkg.tar.gz pkg.tar)' -d 'Package file'

View File

@ -83,18 +83,8 @@ complete -c pandoc -r -l citation-abbreviations
complete -c pandoc -r -f -l print-highlight-style -k -a "(__fish_complete_suffix 'theme' )"
complete -c pandoc -r -f -l highlight_style -k -a "(__fish_complete_suffix 'theme' )"
complete -c pandoc -r -f -l csl -k -a "(__fish_complete_suffix 'csl' )"
complete -c pandoc -r -f -l reference-file -k -a "(__fish_complete_suffix 'odt') (__fish_complete_suffix 'docx')"
complete -c pandoc -r -f -l bibliography -k -a "(__fish_complete_suffix 'bib')"
complete -c pandoc -r -f -l bibliography -k -a "(__fish_complete_suffix 'bibtex')"
complete -c pandoc -r -f -l bibliography -k -a "(__fish_complete_suffix 'copac')"
complete -c pandoc -r -f -l bibliography -k -a "(__fish_complete_suffix 'json')"
complete -c pandoc -r -f -l bibliography -k -a "(__fish_complete_suffix 'yaml')"
complete -c pandoc -r -f -l bibliography -k -a "(__fish_complete_suffix 'enl')"
complete -c pandoc -r -f -l bibliography -k -a "(__fish_complete_suffix 'xml')"
complete -c pandoc -r -f -l bibliography -k -a "(__fish_complete_suffix 'wos')"
complete -c pandoc -r -f -l bibliography -k -a "(__fish_complete_suffix 'medline')"
complete -c pandoc -r -f -l bibliography -k -a "(__fish_complete_suffix 'mods')"
complete -c pandoc -r -f -l bibliography -k -a "(__fish_complete_suffix 'ria')"
complete -c pandoc -r -f -l reference-file -k -a "(__fish_complete_suffix 'odt' 'docx')"
complete -c pandoc -r -f -l bibliography -k -a "(__fish_complete_suffix 'bib' 'bibtex' 'copac' 'json' 'yaml' 'enl' 'xml' 'wos' 'medline' 'mods' 'ria')"
complete -c pandoc -r -f -l lua-filter -k -a "(__fish_complete_suffix 'lua')"
# options that take files in DATADIR

View File

@ -17,7 +17,7 @@ complete -c patch -s f -l force -d "Like -t, but ignore bad-Prereq patches, assu
complete -c patch -s F -l fuzz -x -d "Number of LINES for inexact 'fuzzy' matching" -a "(seq 0 9){\tfuzz lines}"
complete -c patch -s g -l get -x -d "Get files from RCS etc. if positive; ask if negative" -a '(seq -1 1){\t\n}'
complete -c patch -l help -f -d "Display help"
complete -c patch -s i -l input -x -d "Read patch from FILE instead of stdin" -k -a "( __fish_complete_suffix .patch; __fish_complete_suffix .diff)"
complete -c patch -s i -l input -x -d "Read patch from FILE instead of stdin" -k -a "( __fish_complete_suffix .patch .diff)"
complete -c patch -s l -l ignore-whitespace -d "Ignore whitespace changes between patch & input"
complete -c patch -s n -l normal -d "Interpret patch as normal diff"
complete -c patch -s N -l forward -d "Ignore patches that seem reversed or already applied"

View File

@ -95,7 +95,7 @@ complete -f -c phpunit -l do-not-cache-result -d 'Do not write test results to c
# Configuration Options:
complete -x -c phpunit -l prepend -d 'A PHP script that is included as early as possible'
complete -x -c phpunit -l bootstrap -d 'A PHP script that is included before the tests run'
complete -x -c phpunit -s c -l configuration -k -a '(__fish_complete_suffix .xml; __fish_complete_suffix .xml.dist)' -d 'Read configuration from XML file'
complete -x -c phpunit -s c -l configuration -k -a '(__fish_complete_suffix .xml .xml.dist)' -d 'Read configuration from XML file'
complete -f -c phpunit -l no-configuration -d 'Ignore default configuration file (phpunit.xml)'
complete -f -c phpunit -l no-logging -d 'Ignore logging configuration'
complete -f -c phpunit -l no-extensions -d 'Do not load PHPUnit extensions'

View File

@ -1,8 +1,6 @@
complete -c tex -o help -d "Display help and exit"
complete -c tex -o version -d "Display version and exit"
complete -c tex -k -x -a "(
__fish_complete_suffix (commandline -ct) .tex '(La)TeX file'
)"
complete -c tex -k -x -a "(__fish_complete_suffix --description='(La)TeX file' .tex)"
complete -c tex -o file-line-error -d "Show errors in style file:line"
complete -c tex -o no-file-line-error -d "Show errors not in style file:line"

View File

@ -8,14 +8,14 @@ set -l formats raw row bitwise extfile
set -l line_endings LF CR CRLF
set -l woff_fmts woff woff2
complete -f -c ttx -k -a '(__fish_complete_suffix .otf; __fish_complete_suffix .ttf; __fish_complete_suffix .ttx; __fish_complete_suffix .ttc)'
complete -c ttx -f -n "__fish_is_nth_token 1" -k -a '(__fish_complete_suffix .otf; __fish_complete_suffix .ttf; __fish_complete_suffix .ttx)'
complete -f -c ttx -k -a '(__fish_complete_suffix .otf .ttf .ttx .ttc)'
complete -c ttx -f -n "__fish_is_nth_token 1" -k -a '(__fish_complete_suffix .otf .ttf .ttx)'
# General options
complete -c ttx -f -s h -d'Show help message'
complete -c ttx -f -l version -d'Show version info'
complete -c ttx -x -s d -d'Set output folder' -a '(__fish_complete_directories)'
complete -c ttx -r -s o -d'Set output filename' -k -a '(__fish_complete_suffix .otf; __fish_complete_suffix .ttf; __fish_complete_suffix .ttx)'
complete -c ttx -r -s o -d'Set output filename' -k -a '(__fish_complete_suffix .otf .ttf .ttx)'
complete -c ttx -f -s f -d'Force output overwrite'
complete -c ttx -f -s v -d'Verbose output'
complete -c ttx -f -s q -d'Quiet mode'
@ -35,7 +35,7 @@ complete -c ttx -x -l unicodedata -d'Custom database for character names [Unicod
complete -c ttx -x -l newline -d'Set EOL format' -a "$line_endings"
# Compile options
complete -c ttx -x -s m -d'Merge named TTF/OTF with SINGLE .ttx input' -k -a '(__fish_complete_suffix .otf; __fish_complete_suffix .ttf)'
complete -c ttx -x -s m -d'Merge named TTF/OTF with SINGLE .ttx input' -k -a '(__fish_complete_suffix .otf .ttf)'
complete -c ttx -f -s b -d'Don\'t recalculate glyph bounding boxes'
complete -c ttx -f -l recalc-timestamp -d'Set font modified timestamp to current time'
complete -c ttx -x -l flavor -d'Set WOFF flavor' -a "$woff_fmts"

View File

@ -28,11 +28,7 @@ complete -c unzip -s M -d "pipe through `more` pager"
if unzip -v 2>/dev/null | string match -eq Debian
# the first non-switch argument should be the zipfile
complete -c unzip -n "__fish_is_nth_token 1" -k -xa '(
__fish_complete_suffix .zip
__fish_complete_suffix .jar
__fish_complete_suffix .aar
)'
complete -c unzip -n "__fish_is_nth_token 1" -k -xa '(__fish_complete_suffix .zip .jar .aar)'
# Files thereafter are either files to include or exclude from the operation
set -l zipfile
@ -41,10 +37,6 @@ if unzip -v 2>/dev/null | string match -eq Debian
else
# all tokens should be zip files
complete -c unzip -k -xa '(
__fish_complete_suffix .zip
__fish_complete_suffix .jar
__fish_complete_suffix .aar
)'
complete -c unzip -k -xa '(__fish_complete_suffix .zip .jar .aar)'
end

View File

@ -1,12 +1,5 @@
complete -c xz -s z -l compress -d Compress
complete -c xz -s d -l decompress -l uncompress -d Decompress -k -x -a "
(
__fish_complete_suffix .xz
__fish_complete_suffix .txz
__fish_complete_suffix .lzma
__fish_complete_suffix .tlz
)
"
complete -c xz -s d -l decompress -l uncompress -d Decompress -k -x -a "(__fish_complete_suffix .xz .txz .lzma .tlz)"
complete -c xz -s t -l test -d 'Test the integrity of compressed files'
complete -c xz -s l -l list -d 'Print information about compressed files'

View File

@ -170,7 +170,7 @@ complete -c $progname -n "$files" -l machinereadable -d 'Show in machine readabl
# Upgrade options
# Theoretically, pacman reads packages in all formats that libarchive supports
# In practice, it's going to be tar.xz, tar.gz or tar.zst
complete -c $progname -n "$upgrade" -k -xa '(__fish_complete_suffix pkg.tar.zst; __fish_complete_suffix pkg.tar.xz; __fish_complete_suffix pkg.tar.gz)' -d 'Package file'
complete -c $progname -n "$upgrade" -k -xa '(__fish_complete_suffix pkg.tar.zst pkg.tar.xz pkg.tar.gz)' -d 'Package file'
## Yaourt only stuff
# Clean options

View File

@ -1,8 +1,4 @@
complete -c zcat -k -x -a "(
__fish_complete_suffix .gz
__fish_complete_suffix .tgz
)
"
complete -c zcat -k -x -a "(__fish_complete_suffix .gz .tgz)"
complete -c zcat -s f -l force -d Overwrite
complete -c zcat -s h -l help -d "Display help and exit"
complete -c zcat -s L -l license -d "Print license"

View File

@ -1,10 +1,5 @@
function __fish_complete_docutils -d "Completions for Docutils common options" -a cmd
complete -x -c $cmd -k -a "
(
__fish_complete_suffix .rst
__fish_complete_suffix .txt
)
"
complete -x -c $cmd -k -a "(__fish_complete_suffix .rst .txt)"
# General Docutils Options
complete -c $cmd -l title -d "Specify the docs title"

View File

@ -1,79 +1,52 @@
# Find files ending in any of the non-switch arguments and output them as completions.
# * --description provides the description that should be part of each generated completion,
# * --prefix=DIR makes __fish_complete_suffix behave as if it were called in DIR rather than $PWD
# * --complete=PREFIX only lists files that begin with PREFIX
#
# Find files that complete $argv[1], has the suffix $argv[2], and output them
# as completions with the optional description $argv[3]. Then, also output
# completions for the files that don't have the suffix, so you want to use
# "complete -k" on the output. Both $argv[1] and $argv[3] are optional,
# if only one is specified, it is assumed to be the argument to complete. If
# $argv[4] is present, it is treated as a prefix for the path, i.e. in lieu
# of $PWD.
# Files matching the above preconditions are printed first then other, non-matching files
# are printed for fallback purposes. As such, it is imperative that `complete` calls that
# shell out to `__fish_complete_suffix` are made with a `-k` switch to ensure sort order
# is preserved.
function __fish_complete_suffix -d "Complete using files"
set -l _flag_prefix ""
set -l _flag_complete (commandline -ct)
# Variable declarations
argparse 'prefix=' 'description=' 'complete=' -- $argv
set -l comp
set -l suff
set -l desc
set -l files
set -l prefix ""
switch (count $argv)
case 1
set comp (commandline -ct)
set suff $argv
set desc ""
case 2
set comp $argv[1]
set suff $argv[2]
set desc ""
case 3
set comp $argv[1]
set suff $argv[2]
set desc $argv[3]
case 4
set comp $argv[1]
set suff $argv[2]
set desc $argv[3]
set prefix $argv[4]
# Only directories are supported as prefixes, and to use the same logic
# for both absolute prefixed paths and relative non-prefixed paths, $prefix
# must terminate in a `/` if it is present, so it can be unconditionally
# prefixed to any path to get the desired result.
if not string match -qr '/$' $prefix
set prefix $prefix/
end
end
set -l suff (string escape --style=regex -- $argv)
# Simple and common case: no prefix, just complete normally and sort matching files first.
if test -z $prefix
set -l suffix (string escape --style=regex -- $suff)
if test -z $_flag_prefix
# Use normal file completions.
set files (complete -C "__fish_command_without_completions $comp")
set -l files_with_suffix (string match -r -- "^.*$suffix\$" $files)
set files (complete -C "__fish_command_without_completions $_flag_complete")
set -l files_with_suffix (string match -r -- (string join "|" "^.*"$suff\$) $files)
set -l directories (string match -r -- '^.*/$' $files)
set files $files_with_suffix $directories $files
else
# Only directories are supported as prefixes, and to use the same logic
# for both absolute prefixed paths and relative non-prefixed paths, $_flag_prefix
# must terminate in a `/` if it is present, so it can be unconditionally
# prefixed to any path to get the desired result.
if not string match -qr '/$' $_flag_prefix
set _flag_prefix $_flag_prefix/
end
# Strip leading ./ as it confuses the detection of base and suffix
# It is conditionally re-added below.
set base $prefix(string replace -r '^("\')?\\./' '' -- $comp | string trim -c '\'"') # " make emacs syntax highlighting happy
set base $_flag_prefix(string replace -r '^("\')?\\./' '' -- $_flag_complete | string trim -c '\'"') # " make emacs syntax highlighting happy
set -l all
set -l files_with_suffix
set -l dirs
# If $comp is "./ma" and the file is "main.py", we'll catch that case here,
# If $_flag_complete is "./ma" and the file is "main.py", we'll catch that case here,
# but complete.cpp will not consider it a match, so we have to output the
# correct form.
# Also do directory completion, since there might be files with the correct
# suffix in a subdirectory.
set all $base*
set files_with_suffix (string match -r -- ".*"(string escape --style=regex -- $suff) $all)
if not string match -qr '/$' -- $suff
set files_with_suffix (string match -r -- (string join "|" ".*"$suff) $all)
if not string match -qr '/$' -- $argv
set dirs $base*/
# The problem is that we now have each directory included twice in the output,
@ -88,7 +61,7 @@ function __fish_complete_suffix -d "Complete using files"
end
set files $files_with_suffix $dirs $all
if string match -qr '^\\./' -- $comp
if string match -qr '^\\./' -- $_flag_complete
set files ./$files
else
# "Escape" files starting with a literal dash `-` with a `./`
@ -97,14 +70,14 @@ function __fish_complete_suffix -d "Complete using files"
end
if set -q files[1]
if string match -qr -- . "$desc"
set desc "\t$desc"
if string match -qr -- . "$_flag_description"
set _flag_description "\t$_flag_description"
end
if string match -qr -- . "$prefix"
set prefix (string escape --style=regex -- $prefix)
if string match -qr -- . "$_flag_prefix"
set prefix (string escape --style=regex -- $_flag_prefix)
set files (string replace -r -- "^$prefix" "" $files)
end
printf "%s$desc\n" $files
printf "%s$_flag_description\n" $files
end
end