Commit Graph

46 Commits

Author SHA1 Message Date
Benjamin Sago f8df02dae7 Batch source formatting
I read through every file and applied a couple of rustfmt suggestions. The brace placement and alignment of items on similar lines has been made consistent, even if neither are rustfmt's default style (a file has been put in place to enforce this). Other changes are:

• Alphabetical imports and modules
• Comma placement at the end of match blocks
• Use newlines and indentation judiciously
• Spaces around associated types
• Spaces after negations (it makes it more clear imho)
• Comment formatting
• Use early-returns and Optional `?` where appropriate
2020-10-10 20:02:55 +01:00
Benjamin Sago f0c139ca68 Better referencing
This commit makes changes to the way variables are referenced:

• Make types Copy when possible
• Make methods take `self` instead of `&self` where possible (trivially_copy_pass_by_ref)
• Remove unnecessary borrowing (needless_ref)
• Remove unnecessary cloning (clone_on_copy)
• Remove `ref` from match arms where possible (new Rust match ergonomics)
2020-10-10 15:30:19 +01:00
Benjamin Sago 70a30ed683 The Selfening
This commit uses Clippy to fix all the 'use_self' warnings. Using Self instead of the type name has been good Rust style for a while now, and it's become the style I'm used to seeing.
2020-10-10 13:55:26 +01:00
ariasuni 5a84953b4e Fix typos in code documentation 2020-04-19 06:54:06 +02:00
Benjamin Sago 490d9680c2 Merge branch 'fix-handling-maybe-unsupported-time-metadata' of https://github.com/ariasuni/exa into ariasuni-fix-handling-maybe-unsupported-time-metadata
# Conflicts:
#	src/fs/file.rs
#	src/options/filter.rs
#	src/options/view.rs
2020-01-19 16:46:51 +00:00
ariasuni a636d08f8b Fix handling of potentially unsupported time metadata
- Checking on a directory doesn’t tell us if supported elsewhere
(some filesystems, like tmpfs, don’t support created time)
- We want to be able to display a column even if some subfiles or
subdirectories don’t support it

So now if unsupported a time of zero is used, and displayed as `-`
2019-12-20 05:37:29 +01:00
Bond_009 f599c7ce93 Update to Rust 2018 2019-07-19 20:40:21 +02:00
ariasuni f0e7321506 Fix and add tests 2019-03-23 17:23:43 +01:00
ariasuni 39a49a3d36 Check if the sort field is supported by the OS 2019-03-23 17:23:43 +01:00
ariasuni 56717c7336 Add “changed” sort option, to replace old incorrect “created” 2019-03-23 17:23:40 +01:00
Marco 'don' Kaulea 054cac6b82 Add option to only display directories
This allows printing directory trees without any files, only
showing the structure.
I haven't decided on a letter for the short option.

Implements #401
2018-07-12 18:51:14 +02:00
Benjamin Sago 5438f949c9
Merge pull request #311 from martinlindhe/master
adjust some spelling
2018-05-28 10:47:38 +02:00
BenWhitehead a156d96768 Add new sort option `.name` and `.Name`
Add two new sort options `.name` and `.Name` which with ignore a leading
`.` if present on the file name before sorting according to `name` and
`Name`.

This new sort is convenient if you want to list hidden and unhidden
files sorted together.
2018-01-30 15:01:56 -08:00
Martin Lindhe 7b1ee01eb5 adjust some spelling 2017-10-31 06:24:31 +01:00
Benjamin Sago b95446d834 Thread an ignore cache through the program
!
2017-09-30 09:17:29 +02:00
Benjamin Sago 07443e87ba Add a --git-ignore option that doesn’t do anything
!!
2017-09-30 09:17:28 +02:00
Benjamin Sago c475cccce4 Flip the new/old order, and add suggestion for -lt
I changed my mind about which way round sorting by “newest” or by “oldest” should actually go. If you’re listing a large directory, you see the last lines of the output first, so these files should be the ones with the largest whatever the sort field is. It’s about sorting *last*, not sorting *first*. Sorting by size wouldn’t say “sorts smallest files first”, it would say “sorts largest files last”. Right?

Also, add a new suggestion that warns against “ls -lt”.
2017-09-14 09:18:17 +01:00
Benjamin Sago a8bf990674 Tie value suggestions to their arguments
This commit changes the definition of Arg so that it knows about which values it can accept, and can display them in the help text. They were already being shown in the help text, but they were passed in separately, so one argument could show two different sets of options if it wanted. Now, the argument itself knows whether there are suggestions, so it doesn’t have to be passed in separately.

This means we can use it for other things, including listing choices when an option is missed out, without having to repeat the list.

With Misfire::BadArgument now only having two fields, it’s not worth using a constructor function anymore.
2017-09-14 01:22:37 +01:00
Benjamin Sago 0fefc78cbb Add more modified date aliases
I don’t really see the modified date as the *modified* date, rather just the *date* field, because it’s the date field I refer to like 99.9% of the time. So now it has aliases to match.

Also are included are aliases for the reverse order, because I’d rather write “new” than “the reverse of old”.
2017-09-13 23:26:06 +01:00
Benjamin Sago d86fc4286b \t and \s+$ 2017-08-26 23:54:12 +01:00
Benjamin Sago 57c647fee5 Default to sorting case-insensitively
This was touched on in #209 where I got the docs wrong compared to the actual implementation, but after thinking about it, I’d like to switch it round. (The --sort=Name and --sort=name difference has also been switched.) See the big ol’ comment for my reasons.

Because this changes core functionality, it broke many, many tests. You can see that this doesn’t change the -star- tests because the shell, rather than exa, orders the globbed files.

I kept on forgetting which way round Sensitive and Insensitive went, so I named them after the effect they have.
2017-08-20 17:33:39 +01:00
Benjamin Sago 673e894d25 Give the filter modules some love 2017-08-12 10:09:33 +01:00
Benjamin Sago 0b87392fd4 Decouple assert_eq! and assert_parses
The assert_parses function was problematic because it insisted on using assert_eq! to check its contents. This won’t work for any type we want to test that doesn’t implement PartialEq, such as TimeFormat, which holds references to years and date strings and other such.

To go about fixing this, the first step is to change that function so it only does the initial processing, rather than the assertion, which is now done outside of it in the test macros instead.
2017-08-09 13:41:07 +01:00
Benjamin Sago ff497b52e5 Be stricter in strict mode
Now the code actually starts to use the Strictness flag that was added in the earlier commit! Well, the *code* doesn’t, but the tests do: the macros that create the test cases now have a parameter for which tests they should run. It’s usually ‘Both’ for both strict mode and default mode, but can be specified to only run in one, for when the results differ (usually when options override one another)

The downside to strict mode is that, now, *any* call to `matches.has` or `matches.get` could fail, because an option could have been specified twice, and this is the place where those are checked for. This makes the code a little less ergonomic in places, but that’s what the ? operator is for. The only place this has really had an effect is in `Classify::deduce`, which used to just return a boolean but can now fail.

In order to more thoroughly test the mode, some of the older parts of the code can now act more strict. For example, `TerminalColours::deduce` will now use the last-given option rather than searching for “colours” before “colors”.

Help and Version continue doing their own thing.
2017-08-09 09:21:29 +01:00
Benjamin Sago 00379cce63 Thread Strictness through the parser
The value is ignored, but this broke quite a lot of tests that assumed MatchedFlags had only one field.

Parsing tests have to have OsStr flags because I couldn’t get that part working right, but in general, some tests now re-use common functionality too.
2017-08-08 09:18:17 +01:00
Benjamin Sago c1e206669e Give IgnorePatterns a better interface
This commit gives IgnorePatterns a bunch of constructor methods that mean its option-parsing sister file doesn’t need to know that it’s a vec of glob patterns inside: it can work with anything that iterates over strings. Now, the options module doesn’t need to know about the glob crate.
2017-08-07 09:16:56 +01:00
Benjamin Sago 9872eba821 Separate the matched flags from the free strings
Originally, both the matched flags and the list of free strings were returned from the parsing function and then passed around to every type that had a ‘deduce’ method. This worked, but the list of free strings was carried around with it, never used.

Now, only the flags are passed around. They’re in a new struct which has the methods the Matches had.

Both of Matches’s fields are now just data, and all of the methods on MatchedFlags don’t ignore any fields, so it’s more cohesive, at least I think that’s the word.

Building up the MatchedFlags is a bit more annoying though because the vector is now hidden behind a field.
2017-08-05 19:11:00 +01:00
Benjamin Sago 0456e7cfbd Document and organise the parser module 2017-08-05 17:46:38 +01:00
Benjamin Sago adca0d3629 Add test for ignoring globs 2017-07-26 21:29:49 +01:00
Benjamin Sago a2cd39e0a9 Fix --tree --all
Fixes #193. --all was treated the same as --all --all; now it’s treated differently.
2017-07-26 21:14:05 +01:00
Benjamin Sago 0831573669 Add tests for dot filters 2017-07-26 21:01:22 +01:00
Benjamin Sago bc5c0194b4 Add tests for sort field
**
2017-07-26 20:53:57 +01:00
Benjamin Sago 2d1f462bfa Switch to the new options parser
This commit removes the dependency on the ‘getopts’ crate entirely, and re-writes all its uses to use the new options parser instead.

As expected there are casualties galore:

- We now need to collect the options into a vector at the start, so we can use references to them, knowing they’ll be stored *somewhere*.
- Because OsString isn’t Display, its Debug impl gets used instead. (This is hopefully temporary)
- Options that take values (such as ‘sort’ or ‘time-style’) now parse those values with ‘to_string_lossy’. The ‘lossy’ part means “I’m at a loss for what to do here”
- Error messages got a lot worse, but “--tree --all --all” is now a special case of error rather than just another Misfire::Useless.
- Some tests had to be re-written to deal with the fact that the parser works with references.
- ParseError loses its lifetime and owns its contents, to avoid having to attach <'a> to Misfire.
- The parser now takes an iterator instead of a slice.
- OsStrings can’t be ‘match’ patterns, so the code devolves to using long Eq chains instead.
- Make a change to the xtest that assumed an input argument with invalid UTF-8 in was always an error to stderr, when that now in fact works!
- Fix a bug in Vagrant where ‘exa’ and ‘rexa’ didn’t properly escape filenames with spaces in.
2017-07-26 17:48:18 +01:00
Benjamin Sago 5b1966d261 Move filter and dir_action from options to fs
This commit moves the definitions of Filter and DirAction from the options module to the fs module, but leaves the parts that actually have to do with option parsing alone.

Now, the options module shouldn’t define any types that get used elsewhere in the program: it only adds functionality to types that already exist.
2017-07-24 08:34:50 +01:00
Benjamin Sago f750536420 Add sorting by type
This isn’t perfect, as a file’s type isn’t cached, so it gets recomputed for every comparison in the sort! We can’t go off the file’s `st_mode` flag because it’s not guaranteed to be in any order between systems.
2017-06-29 14:52:02 +01:00
Benjamin Sago 340bccbcfc Forbid --tree --all --all
There’s a problem with the tree view where it’ll still recurse through `.` and `..`. But if you were using tree view, would you even need to see them? They’d be in the tree already!
2017-06-29 12:07:46 +01:00
Benjamin Sago 20793ce7f4 Implement . and .. by inserting them maually
I originally thought that the entries . and .. were in *every* directory entry, and exa was already doing something to filter it out. And then... I could find no such code! Turns out, if we want those entries present, we have to insert them ourselves.

This was harder than expected. Because the file filter doesn’t have access to the parent directory path, it can’t “filter” the files vector by inserting the files at the beginning.

Instead, we do it at the iterator level. A directory can be scanned in three different ways depending on what sort of dotfiles, if any, are wanted. At this point, we already have access to the parent directory’s path, so we can just insert them manually. The enum got moved to the dir module because it’s used most there.
2017-06-27 01:13:50 +01:00
Benjamin Sago 39fd905999 Allow passing in the --all option more than once 2017-06-26 23:48:55 +01:00
Benjamin Sago 5ace1264f2 Move the show-invisibles flag into a struct 2017-06-26 23:28:10 +01:00
Benjamin Sago 81c5d8b7c6 Avoid allocating vectors for the help text 2017-06-23 22:58:07 +01:00
Benjamin Sago 3bce55f569 Run Untry over the entire source tree 2017-03-26 17:35:50 +01:00
Ben S 95596297a9 Basic glob ignoring
See #97 and recently #130 too.

This allows the user to pass in options such as "--ignore '*.pyc'" to not list any files ending in '.pyc' in the output. It uses the Rust glob crate and currently does a simple split on pipe, without any escaping, so it’s not really *complete*, but is at least something.
2016-10-30 14:43:33 +00:00
Ben S a6712994c5 Make the views non-Copy
This has to be done for when ignore patterns get introduced and have to be stored in a Vec.
2016-10-30 14:31:25 +00:00
Brandon W Maister 7e15e0dd49 Add legal values to error messages
Now when you do `--sort time` instead of saying "unknown option --sort
time" it will say "unknown options '--sort time' (choices: name...)"
with all legal options.

This also adds the legal values to the default help text.
2016-08-28 21:56:32 -04:00
Ben S 331d5ea724 Rename underscored lifetimes
See https://github.com/rust-lang/rfcs/pull/1177
2016-06-11 13:35:40 +01:00
Benjamin Sago e9e1161cec Split up the options module
The original options was becoming a bit unwieldy, and would have been even more so if I added the same amount of comments. So this commit splits it up.

There's no extra hiding going on here, or rearranging things within the module: (almost) everything now has to be marked 'pub' to let other sub-modules in the new options module to see it.
2016-04-17 20:38:37 +01:00