Commit Graph

32 Commits

Author SHA1 Message Date
lengyijun
aa65856ee0 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.
2023-03-12 22:07:44 -05:00
Johannes Altmanninger
bae75c96d9 __fish_complete_suffix: complete all files, but sort files with matching suffix first
See #7040 and others.
2020-12-23 19:14:10 +01:00
Johannes Altmanninger
1173e8bda4 Clarify that some complete calls just need a command with no user-defined completion 2020-10-10 09:24:49 +02:00
Johannes Altmanninger
93cb0e2abb __fish_complete_suffix: enable fuzzy completion, simplify
fish's internal completion logic is much smarter than the globbing in this
function, so let's just reuse "complete -C", and filter directories and
files with the given suffix.

Thanks to @Kratacoa for reporting on Gitter.

Using "complete -C" works well no prefix is given. Since in this repository
only the openocd completions pass a prefix, I left the prefix-case as is.
It could probably be improved and simplified as well.  The prefix argument was
introduced to avoid cd's side effects inside a completion. Using cd is tempting
though because it would allow to use the same logic as without a prefix.
2020-08-08 22:59:41 +02:00
Johannes Altmanninger
0dd334ee46 __fish_complete_suffix: replace prefix only at start 2020-08-08 22:56:54 +02:00
Johannes Altmanninger
ac1f63781d __fish_complete_suffix: don't fail when a part of the suffix is present
Resolves #7233
2020-08-01 17:04:03 +02:00
Fabian Homborg
b0e3cc4b5c __fish_complete_suffix: Remove eval
This use of eval is unsafe, not really all that useful and can spew
errors that can't be suppressed. So let's remove it, and in future add
a thing that can do expansions in a safe manner

Fixes #6456.
2019-12-28 17:10:23 +01:00
Mahmoud Al-Qudsi
6dc8a1d3a7 Partially address #6340 (escape files starting with -)
This prefixes files beginning with `-` with a `./` when generating
completions *in fish code*. Standard completions for directory listings
generated by the C++ directory traversal code are not afected by this
patch.

Most fish completions defer to `__fish_complete_suffix` to generate the
file/directory completions, these *will* be corrected.
2019-12-18 13:13:23 -06:00
Fabian Homborg
c2970f9618 Reformat all files
This runs build_tools/style.fish, which runs clang-format on C++, fish_indent on fish and (new) black on python.

If anything is wrong with the formatting, we should fix the tools, but automated formatting is worth it.
2019-05-05 12:09:25 +02:00
Aaron Gyes
b23403ee6b Revert "__fish_complete_suffix: do not show description when not passed one"
This reverts commit 367661d4f1.

This was the wrong way to address this annoyance of mine.
2019-01-21 22:55:56 -08:00
Aaron Gyes
367661d4f1 __fish_complete_suffix: do not show description when not passed one
Make it so that the generated completion has the form \t\n
when the optional description has been ommitted - otherwise
the original option's description gets inherited and is seen hundreds
of times repeating in the pager.
2019-01-21 22:37:45 -08:00
Mahmoud Al-Qudsi
d6ab3db159 fixup! Extend __fish_complete_suffix to support a virtual $PWD 2018-11-08 16:17:56 -06:00
Mahmoud Al-Qudsi
da6937e0cf Extend __fish_complete_suffix to support a virtual $PWD
In writing the completion script for openocd I found the need to
complete paths at the command-line as if they were relative to a
path other than the current $PWD. Given that `$PWD` is currently
global in fish (i.e. no side-effect free `cd` within a subshell)
this is probably good to have for other completions too.

This also fixes a bug in support for explicitly supplying the
description for completions via a `$argv` parameter, which prefixed
the description with `\t` (which is correct) except it did so in
the local scope within an `if` statement, meaning the changes never
had any effect and in the output the description was directly
concatenated to the completions, instead of separated by a tab.
2018-11-07 20:08:16 -06:00
Mahmoud Al-Qudsi
46b65a550f Reverse order of files and directories in __fish_complete_suffix output
Ordering of directories above files was introduced in a recent change to
the same script. By default it does not matter as completions are sorted
by fish internally, but this allows the use of `-k` to sort files before
directories (or piped to `sort -r` for vice-versa).
2018-07-30 14:31:47 -05:00
Mahmoud Al-Qudsi
49bfc4f000 fixup! Fix __fish_complete_suffix behavior for paths with literal . 2018-06-25 20:59:24 -05:00
Mahmoud Al-Qudsi
72d80c3d91 Fix __fish_complete_suffix behavior for paths with literal .
__fish_complete_suffix assumed that the only literal . in a path
would be the . before an extension, and stripped accordingly. This
behavior has been there for a long time, but broke many things
including completion of relative paths and completion of paths with
a literal . in a directory name.

__fish_complete_suffix does not just complete extensions (or at the
very least, it no longer does just that) but rather any suffix, so
isolating the path name without the extension was unnecessary in all
cases.
2018-06-25 13:54:10 -05:00
Mahmoud Al-Qudsi
6e36b20e42 Optimize __fish_complete_suffix and fix duplicate listings
With a blank $suff (i.e. complete all files), __fish_complete_suffix
returned directories twice, once with the trailing `/` and once without.
This fixes that, and additionally speeds up the code by no longer
shelling out to `sort -u` as we no longer rely on brace expansion to
enumerate directories and files simultaneously.

In general, this behavior would occur when a directory exists that
matches the suffix search pattern (so a dir named 'foo.bar' with a
search pattern '.bar' would return 'foo.bar' twice).

Runtime has dropped from ~22ms to ~8ms on my machine, while also
returning more correct results.
2018-06-18 23:55:18 -05:00
Mahmoud Al-Qudsi
6401906288 Fix missing -- in string match in __fish_complete_suffix
Caused completion to fail when current token begins with -
2018-05-22 09:59:16 -05:00
Mahmoud Al-Qudsi
7d33372d20 Fix __fish_complete_suffix behavior per __fish_complete_directories test 2018-05-20 14:35:52 -05:00
Mahmoud Al-Qudsi
fd4b3f2c26 Fix __fish_complete_directories test failure
The `sort -u` was applied only conditionally in __fish_complete_suffix,
now applied universally at the final step.
2018-05-20 13:50:28 -05:00
Mahmoud Al-Qudsi
beac145e75 Support expansions in directory completions as well
Also fixes some issues with duplicate results in __fish_complete_suffix.
2018-05-20 12:30:07 -05:00
Mahmoud Al-Qudsi
332e17e8e8 Support [*{}~$] in completions with __fish_complete_suffix
Previously, trying to complete a token with any of these
expansion-related characters would cause the completion to return no
results, as it would emit expanded values which weren't matched by the
autocompleter.
2018-05-20 00:38:17 -05:00
Mahmoud Al-Qudsi
4962244161 Fix __fish_complete_suffix for arguments starting with './'
The previous completion generation was broken for several reasons:
* ./foo would break detection of suffix due to the leading . being
  interpreted an extension marker,
* ./foo would be completed as foo, which would be excluded from
  matching inrcomplete.cpp
2018-04-29 11:20:07 -05:00
Fabian Homborg
66f181499b Strip quotes in __fish_complete_suffix
Fixes #4481.
2018-01-01 13:18:40 +01:00
Kurtis Rader
11a60c8374 reformat all fish scripts
I hate doing this but I am tired of touching a fish script as part of
some change and having `make style` radically change it. Which makes
editing fish scripts more painful than it needs to be. It is time to do
a wholesale reformatting of these scripts to conform to the documented
style as implemented by the `fish_indent` program.
2016-11-27 21:27:22 -08:00
David Adam
7fa69ef8be __fish_complete_suffix: don't provide file description by default
Drops dependency on the mimedb tool and reflects the changes made to the
default chooser for files in #279.
2015-07-23 14:26:38 +08:00
gonchar
c66ec4df3d * __fish_complete_subcommand_root now passes arguments to
__fish_complete_subcommand

* sudo:
  - now can be completed bu group and user (-u and -g keys).
  - subcommand completion is fixed

* __fish_complete_proc.fish is added to complete killall command with
  list of running processes

* __fish_complete_tex.fish is updated with common options

* __fish_make_completion_signals.fish is added to make a list of kill
  signals for kill and killall

* completions:
 - minor filetype completions are added for djview, xpdf, mupdf, gv,
   xdvi
 - adduser is copmleted by user and group
 - dlocate and dpkg are completed by packages
 - find: -executable options is added
 - htop: options
 - funced and funcsave are completed by function names
 - ifdown and ifup are copmleted by interfaces
 - kill and killall: options, signals and processes
 - latexmk, ln, nm: options
 - lualatex and xelatex copmletions
 - sudo: -u and -g options
 - wvdial: presets
2011-09-23 12:24:21 +04:00
Grissiom
70322077d2 remove trialing spaces #2 2010-09-18 10:18:26 +08:00
axel
418192b312 Make the first and last argument to __fish_complete_suffix optional. Use mimedb to look up descriptions if not supplied.
darcs-hash:20070130152631-ac50b-24f1c947d88ce3ad20f31a17b58adfe02cf002e2.gz
2007-01-31 01:26:31 +10:00
axel
6c8a559023 Drop unneeded '--' when using set builtin in various places
darcs-hash:20061212203727-ac50b-23fbb54bba0c5773e8a3dd2e5737ea8a670c801d.gz
2006-12-13 06:37:27 +10:00
axel
8b73bac580 Rename __fish_complete_directory to increase consistency
darcs-hash:20061202233433-ac50b-48368a338773ad47807b0032389fd305d86b3275.gz
2006-12-03 09:34:33 +10:00
axel
343cafef34 Redo installation file structure, move lots of things to $PREFIX/share/fish
darcs-hash:20060217101339-ac50b-d93d2c620a4b7f75f05ff461a6edbee001da7613.gz
2006-02-17 20:13:39 +10:00