exa
                                
                                
                                
                                    exa copied to clipboard
                            
                            
                            
                        Ignore pattern
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?
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.
Thanks @ogham! I'll stay tuned - exa has been mighty useful for me so far already. :smile:
This is something I would like to see in exa as well.
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 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:
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.
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
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 asoak -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.
@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 
--foldswitch, i.e., supposing we havefoo/bar/bazand all intermediate components have no other children, we would have 
.
└──────  foo/bar/baz
However, supposing we touch foo/bar/bun
.
└──── foo/bar
      ├── baz
      └── bun
                                    
                                    
                                    
                                
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.