Skip to content

Commit 07443e8

Browse files
committed
Add a --git-ignore option that doesn’t do anything
!!
1 parent 2b099d8 commit 07443e8

File tree

9 files changed

+51
-3
lines changed

9 files changed

+51
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ exa’s options are almost, but not quite, entirely unlike `ls`'s.
3030
- **-r**, **--reverse**: reverse the sort order
3131
- **-s**, **--sort=(field)**: which field to sort by
3232
- **--group-directories-first**: list directories before other files
33+
- **--git-ignore**: ignore files mentioned in `.gitignore`
3334
- **-I**, **--ignore-glob=(globs)**: glob patterns (pipe-separated) of files to ignore
3435

3536
Pass the `--all` option twice to also show the `.` and `..` directories.

contrib/completions.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ complete -c exa -l 'colour-scale' -d "Highlight levels of file sizes dist
1717

1818
# Filtering and sorting options
1919
complete -c exa -l 'group-directories-first' -d "Sort directories before other files"
20+
complete -c exa -l 'git-ignore' -d "Ignore files mentioned in '.gitignore'"
2021
complete -c exa -s 'a' -l 'all' -d "Show and 'dot' files"
2122
complete -c exa -s 'd' -l 'list-dirs' -d "List directories like regular files"
2223
complete -c exa -s 'L' -l 'level' -d "Limit the depth of recursion" -a "1 2 3 4 5 6 7 8 9"

contrib/completions.zsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ __exa() {
1414
{--color,--colour}"[When to use terminal colours]" \
1515
{--color,--colour}-scale"[Highlight levels of file sizes distinctly]" \
1616
--group-directories-first"[Sort directories before other files]" \
17+
--git-ignore"[Ignore files mentioned in '.gitignore']" \
1718
{-a,--all}"[Show hidden and 'dot' files]" \
1819
{-d,--list-dirs}"[List directories like regular files]" \
1920
{-L,--level}"+[Limit the depth of recursion]" \

contrib/man/exa.1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ Glob patterns, pipe-separated, of files to ignore
8888
.RS
8989
.RE
9090
.TP
91+
.B \-\-git\-ignore
92+
ignore files mentioned in '.gitignore'
93+
.RS
94+
.RE
95+
.TP
9196
.B \-\-group\-directories\-first
9297
list directories before other files
9398
.RS

src/fs/filter.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,26 @@ impl IgnorePatterns {
305305
}
306306

307307

308+
/// Whether to ignore or display files that are mentioned in `.gitignore` files.
309+
#[derive(PartialEq, Debug, Copy, Clone)]
310+
pub enum GitIgnore {
311+
312+
/// Ignore files that Git would ignore. This means doing a check for a
313+
/// `.gitignore` file, possibly recursively up the filesystem tree.
314+
CheckAndIgnore,
315+
316+
/// Display files, even if Git would ignore them.
317+
Off,
318+
}
319+
320+
// This is not fully baked yet. The `ignore` crate lists a lot more files that
321+
// we aren’t checking:
322+
//
323+
// > By default, all ignore files found are respected. This includes .ignore,
324+
// > .gitignore, .git/info/exclude and even your global gitignore globs,
325+
// > usually found in $XDG_CONFIG_HOME/git/ignore.
326+
327+
308328

309329
#[cfg(test)]
310330
mod test_ignores {

src/options/filter.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Parsing the options for `FileFilter`.
22
33
use fs::DotFilter;
4-
use fs::filter::{FileFilter, SortField, SortCase, IgnorePatterns};
4+
use fs::filter::{FileFilter, SortField, SortCase, IgnorePatterns, GitIgnore};
55

66
use options::{flags, Misfire};
77
use options::parser::MatchedFlags;
@@ -180,6 +180,14 @@ impl IgnorePatterns {
180180
}
181181

182182

183+
impl GitIgnore {
184+
pub fn deduce(matches: &MatchedFlags) -> Result<Self, Misfire> {
185+
Ok(if matches.has(&flags::GIT_IGNORE)? { GitIgnore::CheckAndIgnore }
186+
else { GitIgnore::Off })
187+
}
188+
}
189+
190+
183191

184192
#[cfg(test)]
185193
mod test {
@@ -196,7 +204,7 @@ mod test {
196204
use options::test::parse_for_test;
197205
use options::test::Strictnesses::*;
198206

199-
static TEST_ARGS: &[&Arg] = &[ &flags::SORT, &flags::ALL, &flags::TREE, &flags::IGNORE_GLOB ];
207+
static TEST_ARGS: &[&Arg] = &[ &flags::SORT, &flags::ALL, &flags::TREE, &flags::IGNORE_GLOB, &flags::GIT_IGNORE ];
200208
for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf)) {
201209
assert_eq!(result, $result);
202210
}
@@ -275,4 +283,12 @@ mod test {
275283
test!(overridden_3: IgnorePatterns <- ["-I=*.ogg", "-I", "*.mp3"]; Complain => Err(Misfire::Duplicate(Flag::Short(b'I'), Flag::Short(b'I'))));
276284
test!(overridden_4: IgnorePatterns <- ["-I", "*.OGG", "-I*.MP3"]; Complain => Err(Misfire::Duplicate(Flag::Short(b'I'), Flag::Short(b'I'))));
277285
}
286+
287+
288+
mod git_ignores {
289+
use super::*;
290+
291+
test!(off: GitIgnore <- []; Both => Ok(GitIgnore::Off));
292+
test!(on: GitIgnore <- ["--git-ignore"]; Both => Ok(GitIgnore::CheckAndIgnore));
293+
}
278294
}

src/options/flags.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub static LEVEL: Arg = Arg { short: Some(b'L'), long: "level", take
2828
pub static REVERSE: Arg = Arg { short: Some(b'r'), long: "reverse", takes_value: TakesValue::Forbidden };
2929
pub static SORT: Arg = Arg { short: Some(b's'), long: "sort", takes_value: TakesValue::Necessary(Some(SORTS)) };
3030
pub static IGNORE_GLOB: Arg = Arg { short: Some(b'I'), long: "ignore-glob", takes_value: TakesValue::Necessary(None) };
31+
pub static GIT_IGNORE: Arg = Arg { short: None, long: "git-ignore", takes_value: TakesValue::Forbidden };
3132
pub static DIRS_FIRST: Arg = Arg { short: None, long: "group-directories-first", takes_value: TakesValue::Forbidden };
3233
const SORTS: Values = &[ "name", "Name", "size", "extension",
3334
"Extension", "modified", "accessed",
@@ -60,7 +61,8 @@ pub static ALL_ARGS: Args = Args(&[
6061
&ONE_LINE, &LONG, &GRID, &ACROSS, &RECURSE, &TREE, &CLASSIFY,
6162
&COLOR, &COLOUR, &COLOR_SCALE, &COLOUR_SCALE,
6263

63-
&ALL, &LIST_DIRS, &LEVEL, &REVERSE, &SORT, &IGNORE_GLOB, &DIRS_FIRST,
64+
&ALL, &LIST_DIRS, &LEVEL, &REVERSE, &SORT, &DIRS_FIRST,
65+
&IGNORE_GLOB, &GIT_IGNORE,
6466

6567
&BINARY, &BYTES, &GROUP, &HEADER, &INODE, &LINKS, &MODIFIED, &BLOCKS,
6668
&TIME, &ACCESSED, &CREATED, &TIME_STYLE,

src/options/help.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ FILTERING AND SORTING OPTIONS
2727
-s, --sort SORT_FIELD which field to sort by
2828
--group-directories-first list directories before other files
2929
-I, --ignore-glob GLOBS glob patterns (pipe-separated) of files to ignore
30+
--git-ignore Ignore files mentioned in '.gitignore'
3031
Valid sort fields: name, Name, extension, Extension, size, type,
3132
modified, accessed, created, inode, and none.
3233
date, time, old, and new all refer to modified.

xtests/help

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ FILTERING AND SORTING OPTIONS
2222
-s, --sort SORT_FIELD which field to sort by
2323
--group-directories-first list directories before other files
2424
-I, --ignore-glob GLOBS glob patterns (pipe-separated) of files to ignore
25+
--git-ignore Ignore files mentioned in '.gitignore'
2526
Valid sort fields: name, Name, extension, Extension, size, type,
2627
modified, accessed, created, inode, and none.
2728
date, time, old, and new all refer to modified.

0 commit comments

Comments
 (0)