提交 0fefc78c 编写于 作者: B Benjamin Sago

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”.
上级 19b77807
......@@ -54,7 +54,7 @@ These options are available when running with --long (`-l`):
- **--time-style**: how to format timestamps
- Valid **--color** options are **always**, **automatic**, and **never**.
- Valid sort fields are **accessed**, **created**, **extension**, **Extension**, **inode**, **modified**, **name**, **Name**, **size**, **type**, and **none**. Fields starting with a capital letter sort uppercase before lowercase.
- Valid sort fields are **accessed**, **created**, **extension**, **Extension**, **inode**, **modified**, **name**, **Name**, **size**, **type**, and **none**. Fields starting with a capital letter sort uppercase before lowercase. The modified field has the aliases **date**, **time**, and **oldest**, while its reverse has the aliases **age** and **newest**.
- Valid time fields are **modified**, **accessed**, and **created**.
- Valid time styles are **default**, **iso**, **long-iso**, and **full-iso**.
......
......@@ -14,7 +14,7 @@ _exa()
;;
-s|--sort)
COMPREPLY=( $( compgen -W 'name filename Name Filename size filesize extension Extension modified accessed created type inode none --' -- "$cur" ) )
COMPREPLY=( $( compgen -W 'name filename Name Filename size filesize extension Extension date time modified accessed created type inode oldest newest age none --' -- "$cur" ) )
return
;;
......
......@@ -23,7 +23,9 @@ complete -c exa -s 'L' -l 'level' -d "Limit the depth of recursion" -a "1 2
complete -c exa -s 'r' -l 'reverse' -d "Reverse the sort order"
complete -c exa -s 's' -l 'sort' -x -d "Which field to sort by" -a "
accessed\t'Sort by file accessed time'
age\t'Sort by file modified time (newest first)'
created\t'Sort by file modified time'
date\t'Sort by file modified time'
ext\t'Sort by file extension'
Ext\t'Sort by file extension (uppercase first)'
extension\t'Sort by file extension'
......@@ -34,8 +36,11 @@ complete -c exa -s 's' -l 'sort' -x -d "Which field to sort by" -a "
modified\t'Sort by file modified time'
name\t'Sort by filename'
Name\t'Sort by filename (uppercase first)'
newest\t'Sort by file modified time (newest first)'
none\t'Do not sort files at all'
oldest\t'Sort by file modified time'
size\t'Sort by file size'
time\t'Sort by file modified time'
type\t'Sort by file type'
"
......
......@@ -18,7 +18,7 @@ __exa() {
{-d,--list-dirs}"[List directories like regular files]" \
{-L,--level}"+[Limit the depth of recursion]" \
{-r,--reverse}"[Reverse the sort order]" \
{-s,--sort}"[Which field to sort by]:(sort field):(accessed created extension Extension filename Filename inode modified name Name none size type)" \
{-s,--sort}"[Which field to sort by]:(sort field):(accessed age created date extension Extension filename Filename inode modified oldest name Name newest none size time type)" \
{-I,--ignore-glob}"[Ignore files that match these glob patterns]" \
{-b,--binary}"[List file sizes with binary prefixes]" \
{-B,--bytes}"[List file sizes in bytes, without any prefixes]" \
......
......@@ -77,6 +77,7 @@ reverse the sort order
.B \-s, \-\-sort=\f[I]SORT_FIELD\f[]
which field to sort by.
Valid fields are name, Name, extension, Extension, size, modified, accessed, created, inode, type, and none.
The modified field has the aliases date, time, and oldest, and its reverse order has the aliases age and newest.
Fields starting with a capital letter will sort uppercase before lowercase: 'A' then 'B' then 'a' then 'b'.
Fields starting with a lowercase letter will mix them: 'A' then 'a' then 'B' then 'b'.
.RS
......
......@@ -142,14 +142,14 @@ pub enum SortField {
/// files were created on the filesystem, more or less.
FileInode,
/// The time this file was modified (the “mtime”).
/// The time the file was modified (the “mtime”).
///
/// As this is stored as a Unix timestamp, rather than a local time
/// instance, the time zone does not matter and will only be used to
/// display the timestamps, not compare them.
ModifiedDate,
/// The time file was accessed (the “atime”).
/// The time the was accessed (the “atime”).
///
/// Oddly enough, this field rarely holds the *actual* accessed time.
/// Recording a read time means writing to the file each time it’s read
......@@ -159,7 +159,7 @@ pub enum SortField {
/// http://unix.stackexchange.com/a/8842
AccessedDate,
/// The time this file was changed or created (the “ctime”).
/// The time the file was changed or created (the “ctime”).
///
/// Contrary to the name, this field is used to mark the time when a
/// file’s metadata changed -- its permissions, owners, or link count.
......@@ -173,6 +173,17 @@ pub enum SortField {
/// Files are ordered according to the `PartialOrd` implementation of
/// `fs::fields::Type`, so changing that will change this.
FileType,
/// The “age” of the file, which is the time it was modified sorted
/// backwards. The reverse of the `ModifiedDate` ordering!
///
/// It turns out that listing the most-recently-modified files first is a
/// common-enough use case that it deserves its own variant. This would be
/// implemented by just using the modified date and setting the reverse
/// flag, but this would make reversing *that* output not work, which is
/// bad, even though that’s kind of nonsensical. So it’s its own variant
/// that can be reversed like usual.
ModifiedAge,
}
/// Whether a field should be sorted case-sensitively or case-insensitively.
......@@ -219,6 +230,7 @@ impl SortField {
SortField::ModifiedDate => a.metadata.mtime().cmp(&b.metadata.mtime()),
SortField::AccessedDate => a.metadata.atime().cmp(&b.metadata.atime()),
SortField::CreatedDate => a.metadata.ctime().cmp(&b.metadata.ctime()),
SortField::ModifiedAge => b.metadata.mtime().cmp(&a.metadata.mtime()), // flip b and a
SortField::FileType => match a.type_char().cmp(&b.type_char()) { // todo: this recomputes
Ordering::Equal => natord::compare(&*a.name, &*b.name),
......
......@@ -53,9 +53,12 @@ impl SortField {
else if word == "Ext" || word == "Extension" {
Ok(SortField::Extension(SortCase::ABCabc))
}
else if word == "mod" || word == "modified" {
else if word == "date" || word == "time" || word == "mod" || word == "modified" || word == "old" || word == "oldest" {
Ok(SortField::ModifiedDate)
}
else if word == "age" || word == "new" || word == "newest" {
Ok(SortField::ModifiedAge)
}
else if word == "acc" || word == "accessed" {
Ok(SortField::AccessedDate)
}
......@@ -216,6 +219,11 @@ mod test {
test!(one_short: SortField <- ["-saccessed"]; Both => Ok(SortField::AccessedDate));
test!(lowercase: SortField <- ["--sort", "name"]; Both => Ok(SortField::Name(SortCase::AaBbCc)));
test!(uppercase: SortField <- ["--sort", "Name"]; Both => Ok(SortField::Name(SortCase::ABCabc)));
test!(old: SortField <- ["--sort", "old"]; Both => Ok(SortField::ModifiedDate));
test!(oldest: SortField <- ["--sort=oldest"]; Both => Ok(SortField::ModifiedDate));
test!(new: SortField <- ["--sort", "new"]; Both => Ok(SortField::ModifiedAge));
test!(newest: SortField <- ["--sort=newest"]; Both => Ok(SortField::ModifiedAge));
test!(age: SortField <- ["-sage"]; Both => Ok(SortField::ModifiedAge));
// Errors
test!(error: SortField <- ["--sort=colour"]; Both => Err(Misfire::bad_argument(&flags::SORT, &os("colour"), super::SORTS)));
......
......@@ -28,7 +28,8 @@ FILTERING AND SORTING OPTIONS
--group-directories-first list directories before other files
-I, --ignore-glob GLOBS glob patterns (pipe-separated) of files to ignore
Valid sort fields: name, Name, extension, Extension, size, type,
modified, accessed, created, inode, none
modified, accessed, created, inode, and none.
date, time, old, and new all refer to modified.
"##;
static LONG_OPTIONS: &str = r##"
......
Permissions Size User Date Modified Name
.rw-rw-r-- 0 cassowary 22 Dec 2009 plum
.rw-rw-r-- 0 cassowary 15 Jun 2006 peach
.rw-rw-r-- 0 cassowary  3 Mar 2003 pear
......@@ -23,7 +23,8 @@ FILTERING AND SORTING OPTIONS
--group-directories-first list directories before other files
-I, --ignore-glob GLOBS glob patterns (pipe-separated) of files to ignore
Valid sort fields: name, Name, extension, Extension, size, type,
modified, accessed, created, inode, none
modified, accessed, created, inode, and none.
date, time, old, and new all refer to modified.
LONG VIEW OPTIONS
-b, --binary list file sizes with binary prefixes
......
......@@ -143,9 +143,11 @@ $exa $testcases/file-names-exts/music.* -I "*.OGG|*.mp3" -1 2>&1 | diff -q - $re
# Dates and times
$exa $testcases/dates -lh --accessed --sort=accessed 2>&1 | diff -q - $results/dates_accessed || exit 1
$exa $testcases/dates -lh --sort=modified 2>&1 | diff -q - $results/dates_modified || exit 1
$exa $testcases/dates -lh -r --sort=newest 2>&1 | diff -q - $results/dates_modified || exit 1
$exa $testcases/dates -lh --sort=newest 2>&1 | diff -q - $results/dates_deifidom || exit 1
$exa $testcases/dates -l --time-style=long-iso 2>&1 | diff -q - $results/dates_long_iso || exit 1
$exa $testcases/dates -l --time-style=full-iso 2>&1 | diff -q - $results/dates_full_iso || exit 1
$exa $testcases/dates -l --time-style=iso 2>&1 | diff -q - $results/dates_iso || exit 1
$exa $testcases/dates -l --time-style=iso 2>&1 | diff -q - $results/dates_iso || exit 1
# Locales
# These two are used in particular because they have 5-long and 4-long
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册