mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 13:23:09 +00:00
Fix path filter --invert
This would still remove non-existent paths, which isn't a strict inversion and contradicts the docs. Currently, to only allow paths that exist but don't pass a type check, you'd have to filter twice: path filter -Z foo bar | path filter -vfz If a shortcut for this becomes necessary we can add it later.
This commit is contained in:
parent
a9034610e1
commit
e088c974dd
2 changed files with 12 additions and 2 deletions
|
@ -807,9 +807,8 @@ static int path_filter(parser_t &parser, io_streams_t &streams, int argc, const
|
|||
int n_transformed = 0;
|
||||
arg_iterator_t aiter(argv, optind, streams, opts.null_in);
|
||||
while (const wcstring *arg = aiter.nextstr()) {
|
||||
if ((!opts.invert || (!opts.have_perm && !opts.have_type)) && filter_path(opts, *arg)) {
|
||||
if ((!opts.have_perm && !opts.have_type) || (filter_path(opts, *arg) != opts.invert)) {
|
||||
// If we don't have filters, check if it exists.
|
||||
// (for match this is done by the glob already)
|
||||
if (!opts.have_type && !opts.have_perm) {
|
||||
bool ok = !waccess(*arg, F_OK);
|
||||
if (ok == opts.invert) continue;
|
||||
|
|
|
@ -94,6 +94,17 @@ chmod +x bin/*
|
|||
path filter bin argagagji
|
||||
# The (hopefully) nonexistent argagagji is filtered implicitly:
|
||||
# CHECK: bin
|
||||
|
||||
# With --invert, the existing bin is filtered
|
||||
path filter --invert bin argagagji
|
||||
# CHECK: argagagji
|
||||
|
||||
# With --invert and a type, bin fails the type,
|
||||
# and argagagji doesn't exist, so both are printed.
|
||||
path filter -vf bin argagagji
|
||||
# CHECK: bin
|
||||
# CHECK: argagagji
|
||||
|
||||
path filter --type file bin bin/fish
|
||||
# Only fish is a file
|
||||
# CHECK: bin/fish
|
||||
|
|
Loading…
Reference in a new issue