feat: show directories last

This feature lists directories after all other entries in a directory.
This is convenient when combined with the tree-view.
This commit is contained in:
Erwin van Eijk 2024-03-03 17:08:06 +01:00 committed by Erwin
parent 22dbeec229
commit 92471941c4
10 changed files with 23 additions and 1 deletions

View File

@ -108,6 +108,7 @@ ezas options are almost, but not quite, entirely unlike `ls`s. Quick overv
- **-r**, **--reverse**: reverse the sort order
- **-s**, **--sort=(field)**: which field to sort by
- **--group-directories-first**: list directories before other files
- **--group-directories-last**: list directories after other files
- **-D**, **--only-dirs**: list only directories
- **-f**, **--only-files**: list only files
- **--git-ignore**: ignore files mentioned in `.gitignore`

View File

@ -47,6 +47,7 @@ complete -c eza -l smart-group -d "Only show group if it has a different name fr
# Filtering and sorting options
complete -c eza -l group-directories-first -d "Sort directories before other files"
complete -c eza -l group-directories-last -d "Sort directories after other files"
complete -c eza -l git-ignore -d "Ignore files mentioned in '.gitignore'"
complete -c eza -s a -l all -d "Show hidden and 'dot' files. Use this twice to also show the '.' and '..' directories"
complete -c eza -s A -l almost-all -d "Equivalent to --all; included for compatibility with `ls -A`"

View File

@ -20,6 +20,7 @@ export extern "eza" [
--hyperlink # Display entries as hyperlinks
--absolute # Display entries with their absolute path
--group-directories-first # Sort directories before other files
--group-directories-last # Sort directories after other files
--git-ignore # Ignore files mentioned in '.gitignore'
--all(-a) # Show hidden and 'dot' files. Use this twice to also show the '.' and '..' directories
--almost-all(-A) # Equivalent to --all; included for compatibility with `ls -A`

View File

@ -28,6 +28,7 @@ __eza() {
--hyperlink"[Display entries as hyperlinks]" \
--absolute"[Display entries with their absolute path]:(mode):(on follow off)" \
--group-directories-first"[Sort directories before other files]" \
--group-directories-last"[Sort directories after other files]" \
--git-ignore"[Ignore files mentioned in '.gitignore']" \
{-a,--all}"[Show hidden and 'dot' files. Use this twice to also show the '.' and '..' directories]" \
{-A,--almost-all}"[Equivalent to --all; included for compatibility with \'ls -A\']" \

View File

@ -160,6 +160,9 @@ Sort fields starting with a capital letter will sort uppercase before lowercase:
`--group-directories-first`
: List directories before other files.
`--group-directories-last`
: List directories after other files.
`-D`, `--only-dirs`
: List only directories, not files.

View File

@ -129,6 +129,8 @@ commands:
- type
? - null
- --group-directories-first
? - null
- --group-directories-last
? - -D
- --only-dirs
? - -f

View File

@ -43,6 +43,10 @@ pub struct FileFilter {
/// second. Some users prefer it like this.
pub list_dirs_first: bool,
/// Whether directories should be listed as the last items, after other
/// types of file. Some users prefer it like this.
pub list_dirs_last: bool,
/// The metadata field to sort by.
pub sort_field: SortField,
@ -126,6 +130,12 @@ impl FileFilter {
.points_to_directory()
.cmp(&a.as_ref().points_to_directory())
});
} else if self.list_dirs_last {
files.sort_by(|a, b| {
a.as_ref()
.points_to_directory()
.cmp(&b.as_ref().points_to_directory())
});
}
}
}

View File

@ -27,6 +27,7 @@ impl FileFilter {
#[rustfmt::skip]
return Ok(Self {
list_dirs_first: matches.has(&flags::DIRS_FIRST)?,
list_dirs_last: matches.has(&flags::DIRS_LAST)?,
flags: filter_flags,
sort_field: SortField::deduce(matches)?,
dot_filter: DotFilter::deduce(matches)?,

View File

@ -39,6 +39,7 @@ pub static SORT: Arg = Arg { short: Some(b's'), long: "sort", take
pub static IGNORE_GLOB: Arg = Arg { short: Some(b'I'), long: "ignore-glob", takes_value: TakesValue::Necessary(None) };
pub static GIT_IGNORE: Arg = Arg { short: None, long: "git-ignore", takes_value: TakesValue::Forbidden };
pub static DIRS_FIRST: Arg = Arg { short: None, long: "group-directories-first", takes_value: TakesValue::Forbidden };
pub static DIRS_LAST: Arg = Arg { short: None, long: "group-directories-last", takes_value: TakesValue::Forbidden };
pub static ONLY_DIRS: Arg = Arg { short: Some(b'D'), long: "only-dirs", takes_value: TakesValue::Forbidden };
pub static ONLY_FILES: Arg = Arg { short: Some(b'f'), long: "only-files", takes_value: TakesValue::Forbidden };
const SORTS: Values = &[ "name", "Name", "size", "extension",
@ -92,7 +93,7 @@ pub static ALL_ARGS: Args = Args(&[
&COLOR, &COLOUR, &COLOR_SCALE, &COLOUR_SCALE, &COLOR_SCALE_MODE, &COLOUR_SCALE_MODE,
&WIDTH, &NO_QUOTES, &ABSOLUTE,
&ALL, &ALMOST_ALL, &LIST_DIRS, &LEVEL, &REVERSE, &SORT, &DIRS_FIRST,
&ALL, &ALMOST_ALL, &LIST_DIRS, &LEVEL, &REVERSE, &SORT, &DIRS_FIRST, &DIRS_LAST,
&IGNORE_GLOB, &GIT_IGNORE, &ONLY_DIRS, &ONLY_FILES,
&BINARY, &BYTES, &GROUP, &NUMERIC, &HEADER, &ICONS, &INODE, &LINKS, &MODIFIED, &CHANGED,

View File

@ -39,6 +39,7 @@ FILTERING AND SORTING OPTIONS
-r, --reverse reverse the sort order
-s, --sort SORT_FIELD which field to sort by
--group-directories-first list directories before other files
--group-directories-last list directories after other files
-D, --only-dirs list only directories
-f, --only-files list only files
-I, --ignore-glob GLOBS glob patterns (pipe-separated) of files to ignore";