exa icon indicating copy to clipboard operation
exa copied to clipboard

Ignore pattern

Open ghost opened this issue 9 years ago • 10 comments

I think having support for ignoring certain files or directories, especially in tree view, would result in much better ability to quickly figure out the structure of a directory. I couldn't find the equivalent of tree -I '.git|node_modules|bower_components' when looking at exa switches.

Is there any way to work around this and/or is the feature considered for implementation?

ghost avatar Jan 15 '16 12:01 ghost

It wasn't considered for implementation by me, but I'm happy to take on feature requests: my use cases won't always be the same as others', and there'll always be things I haven't thought about. For example: I actually had no idea that tree had that feature!

A feature like this will have to be supported by exa itself, since there's no way to work around it. You can't grep -v out the lines you don't want to see in the tree view because their children will still be hidden, and it would look weird. Fortunately, exa already uses a filter_files function internally, so I should be able to add some support for this to that.

ogham avatar Feb 10 '16 15:02 ogham

Thanks @ogham! I'll stay tuned - exa has been mighty useful for me so far already. :smile:

ghost avatar Feb 12 '16 01:02 ghost

This is something I would like to see in exa as well.

daGrevis avatar Apr 08 '16 11:04 daGrevis

I can add in the basic functionality for this. Note that tree's full implementation is rather complicated:

-P pattern
    List only those files that match the wild-card pattern. Note: you must use the -a option to also
    consider those files beginning with a dot '.' for matching. Valid wildcard operators are '*' (any zero or 
    more characters), '?' (any single character), '[...]' (any single character listed between brackets 
    (optional - (dash) for character range may be used: ex: [A-Z]), and '[^...]' (any single character not 
    listed in brackets) and '|' separates alternate patterns. 
-I pattern
    Do not list those files that match the wild-card pattern.

I'm sure that Rust has a library for simple globbing on strings, but I'm not sure how simple character classes and alternate pipes would be (if there's a pipe within square brackets, we'd have to parse the whole thing). So I could get a "simple" implementation out there first, because it looks like people want this feature. Thoughts?

ogham avatar Apr 18 '16 12:04 ogham

@ogham I'm all for getting the more basic, easiest implementation out there first, and then improving it as needed based on feedback - I'd really appreciate the switches being there. :+1:

ghost avatar Apr 25 '16 09:04 ghost

This would be awesome, indeed.

I have a request for this feature though. Is it possible to cancel these commands with -a?

I'd like to remove stuff like .pyc etc. by default by adding them to my alias, but want a way to easily get everything back again.

jonathf avatar Apr 26 '16 20:04 jonathf

As for thoughts on implementation of -I and -P, the feature you describe seems like a rudimentary version of regex. I for one would appreciate full regex support. For example: https://doc.rust-lang.org/regex/regex/index.html

jonathf avatar Apr 26 '16 21:04 jonathf

I've been developing a "modern tree" called Oak and was happy when I found this project. Oak already has a more advanced version of glob filtering which I could port over to exa if there's interest.

These are the differences in my implementation in comparison to what exa currently does:

  • Multiple patterns are supplied with multiple options instead of | separation. I made this decision to avoid escaping which generally gets messy. Example: tree -I "*.pyc|build" is written as oak -I "*.pyc" -I "build".
  • Whitelisting is supported through -P.
  • I use globset instead of glob which is more efficient for more patterns.

My project can be found at https://github.com/jacwah/oak.

jacwah avatar Dec 05 '16 12:12 jacwah

@ogham it seems this feature has now been implemented, so I suppose this issue could be closed. However, would it be possible to allow sub-directory pattern matching in the -I option (with --tree option)? If not, I think the current behavior of only allowing patterns with a single component matching on any component in the path should be documented in the man page. It is unintuitive. Given that exa is a modern replacement for ls, and in all shells I have used that support glob expansion ls foo/* matches foo/bar but ls *bar does not, then either exa -I foo/* should ignore ./foo/bar or this break from the norm should be documented.

Actual behavior

# each of the following commands produces the same output, so the output is only pasted below once
$ exa --tree -I '.git|venv|*/zip2d/*'
$ exa --tree -I '.git|venv|data/zip2d/*'
$ exa --tree -I '.git|venv|data\/zip2d\/*'
.
├── data
│  ├── tl_2019_us_zcta510
│  │  ├── tl_2019_us_zcta510.cpg
│  │  ├── tl_2019_us_zcta510.dbf
│  │  ├── tl_2019_us_zcta510.prj
│  │  ├── tl_2019_us_zcta510.shp
│  │  ├── tl_2019_us_zcta510.shp.ea.iso.xml
│  │  ├── tl_2019_us_zcta510.shp.iso.xml
│  │  └── tl_2019_us_zcta510.shx
│  ├── tl_2019_us_zcta510.zip
│  ├── zip2d
│  │  ├── zip2d.cpg
│  │  ├── zip2d.dbf
│  │  ├── zip2d.prj
│  │  ├── zip2d.shp
│  │  └── zip2d.shx
│  └── zip2d-complete.tar.gz
├── lazy-install.sh
├── pyproject.toml
├── README.md
├── requirements.txt
└── src
   └── zip2d.py

Expected behavior

# Both should produce similar output; only shown once below for brevity's sake
$ exa --tree -I '.git|venv|data/zip2d'
$ exa --tree -I '.git|venv|data/zip2d/*'
.
├── data
│  ├── tl_2019_us_zcta510
│  │  ├── tl_2019_us_zcta510.cpg
│  │  ├── tl_2019_us_zcta510.dbf
│  │  ├── tl_2019_us_zcta510.prj
│  │  ├── tl_2019_us_zcta510.shp
│  │  ├── tl_2019_us_zcta510.shp.ea.iso.xml
│  │  ├── tl_2019_us_zcta510.shp.iso.xml
│  │  └── tl_2019_us_zcta510.shx
│  ├── tl_2019_us_zcta510.zip
│  └── zip2d-complete.tar.gz
├── lazy-install.sh
├── pyproject.toml
├── README.md
├── requirements.txt
└── src
   └── zip2d.py

use case

I was attempting to ignore all files in the data/zip2d sub-directory while still printing the data/zip2d directory itself; I was attempting to show the tree structure of this project and ignore irrelevant outputs while reporting an issue in another repository. Note: I was able to achieve the desired effect by adding appropriate globs to the project's gitignore and using the --gitignore option

wish list

  • It would also be great to have the double-asterisk match an arbitrary number of components as a wildcard
  • fold tree- perhaps enabled by a new --fold switch, i.e., supposing we have foo/bar/baz and all intermediate components have no other children, we would have
.
└──────  foo/bar/baz

However, supposing we touch foo/bar/bun

.
└──── foo/bar
      ├── baz
      └── bun

justin-f-perez avatar Jun 26 '22 13:06 justin-f-perez

Found this feature request and want to ask if there is an easy hack to ignore .git folder at least. I'm trying to visualize the tree on local folder and .git folder adds to the noise.

hrmnjt avatar Sep 15 '22 14:09 hrmnjt