Skip to content

Commit 1f167dd

Browse files
authored
Merge pull request ogham#577 from 0rvar/feature/suppress-columns
Add support for suppressing table columns
2 parents 5521f2d + e791cf4 commit 1f167dd

File tree

10 files changed

+78
-12
lines changed

10 files changed

+78
-12
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ These options are available when running with --long (`-l`):
6060
- **-@**, **--extended**: list each file's extended attributes and sizes
6161
- **--git**: list each file's Git status, if tracked or ignored
6262
- **--time-style**: how to format timestamps
63+
- **--no-permissions**: suppress the permissions field
64+
- **--no-filesize**: suppress the filesize field
65+
- **--no-user**: suppress the user field
66+
- **--no-time**: suppress the time field
6367

6468
- Valid **--color** options are **always**, **automatic**, and **never**.
6569
- Valid sort fields are **accessed**, **changed**, **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 **newest**, while its reverse has the aliases **age** and **oldest**.

contrib/completions.fish

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ complete -c exa -l 'time-style' -x -d "How to format timestamps" -a "
7373
long-iso\t'Display longer ISO timestaps, up to the minute'
7474
full-iso\t'Display full ISO timestamps, up to the nanosecond'
7575
"
76+
complete -c exa -l 'no-permissions' -d "Suppress the permissions field"
77+
complete -c exa -l 'no-filesize' -d "Suppress the filesize field"
78+
complete -c exa -l 'no-user' -d "Suppress the user field"
79+
complete -c exa -l 'no-time' -d "Suppress the time field"
7680

7781
# Optional extras
7882
complete -c exa -s 'g' -l 'git' -d "List each file's Git status, if tracked"

contrib/completions.zsh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ __exa() {
4040
{-S,--blocks}"[List each file's number of filesystem blocks]" \
4141
{-t,--time}="[Which time field to show]:(time field):(accessed changed created modified)" \
4242
--time-style="[How to format timestamps]:(time style):(default iso long-iso full-iso)" \
43+
--no-permissions"[Suppress the permissions field]" \
44+
--no-filesize"[Suppress the filesize field]" \
45+
--no-user"[Suppress the user field]" \
46+
--no-time"[Suppress the time field]" \
4347
{-u,--accessed}"[Use the accessed timestamp field]" \
4448
{-U,--created}"[Use the created timestamp field]" \
4549
--git"[List each file's Git status, if tracked]" \

contrib/man/exa.1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,26 @@ use the created timestamp field
182182
.RS
183183
.RE
184184
.TP
185+
.B \-\-no\-permissions
186+
suppress the permissions field
187+
.RS
188+
.RE
189+
.TP
190+
.B \-\-no\-filesize
191+
suppress the filesize field
192+
.RS
193+
.RE
194+
.TP
195+
.B \-\-no\-user
196+
suppress the user field
197+
.RS
198+
.RE
199+
.TP
200+
.B \-\-no\-time
201+
suppress the time field
202+
.RS
203+
.RE
204+
.TP
185205
.B \-\@, \-\-extended
186206
list each file\[aq]s extended attributes and sizes
187207
.RS

src/options/flags.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ pub static TIME_STYLE: Arg = Arg { short: None, long: "time-style", takes_
5353
const TIMES: Values = &["modified", "changed", "accessed", "created"];
5454
const TIME_STYLES: Values = &["default", "long-iso", "full-iso", "iso"];
5555

56+
// suppressing columns
57+
pub static NO_PERMISSIONS: Arg = Arg { short: None, long: "no-permissions", takes_value: TakesValue::Forbidden };
58+
pub static NO_FILESIZE: Arg = Arg { short: None, long: "no-filesize", takes_value: TakesValue::Forbidden };
59+
pub static NO_USER: Arg = Arg { short: None, long: "no-user", takes_value: TakesValue::Forbidden };
60+
pub static NO_TIME: Arg = Arg { short: None, long: "no-time", takes_value: TakesValue::Forbidden };
61+
5662
// optional feature options
5763
pub static GIT: Arg = Arg { short: None, long: "git", takes_value: TakesValue::Forbidden };
5864
pub static EXTENDED: Arg = Arg { short: Some(b'@'), long: "extended", takes_value: TakesValue::Forbidden };
@@ -69,6 +75,7 @@ pub static ALL_ARGS: Args = Args(&[
6975

7076
&BINARY, &BYTES, &GROUP, &HEADER, &ICONS, &INODE, &LINKS, &MODIFIED, &CHANGED,
7177
&BLOCKS, &TIME, &ACCESSED, &CREATED, &TIME_STYLE,
78+
&NO_PERMISSIONS, &NO_FILESIZE, &NO_USER, &NO_TIME,
7279

7380
&GIT, &EXTENDED,
7481
]);

src/options/help.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ LONG VIEW OPTIONS
4949
-t, --time FIELD which timestamp field to list (modified, accessed, created)
5050
-u, --accessed use the accessed timestamp field
5151
-U, --created use the created timestamp field
52-
--time-style how to format timestamps (default, iso, long-iso, full-iso)"##;
52+
--time-style how to format timestamps (default, iso, long-iso, full-iso)
53+
--no-permissions suppress the permissions field
54+
--no-filesize suppress the filesize field
55+
--no-user suppress the user field
56+
--no-time suppress the time field"##;
5357

5458
static GIT_HELP: &str = r##" --git list each file's Git status, if tracked or ignored"##;
5559
static EXTENDED_HELP: &str = r##" -@, --extended list each file's extended attributes and sizes"##;

src/options/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl Options {
148148
pub fn should_scan_for_git(&self) -> bool {
149149
match self.view.mode {
150150
Mode::Details(details::Options { table: Some(ref table), .. }) |
151-
Mode::GridDetails(grid_details::Options { details: details::Options { table: Some(ref table), .. }, .. }) => table.extra_columns.git,
151+
Mode::GridDetails(grid_details::Options { details: details::Options { table: Some(ref table), .. }, .. }) => table.columns.git,
152152
_ => false,
153153
}
154154
}

src/options/view.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ impl TableOptions {
211211
let env = Environment::load_all();
212212
let time_format = TimeFormat::deduce(matches, vars)?;
213213
let size_format = SizeFormat::deduce(matches)?;
214-
let extra_columns = Columns::deduce(matches)?;
215-
Ok(TableOptions { env, time_format, size_format, extra_columns })
214+
let columns = Columns::deduce(matches)?;
215+
Ok(TableOptions { env, time_format, size_format, columns })
216216
}
217217
}
218218

@@ -227,7 +227,11 @@ impl Columns {
227227
let inode = matches.has(&flags::INODE)?;
228228
let links = matches.has(&flags::LINKS)?;
229229

230-
Ok(Columns { time_types, git, blocks, group, inode, links })
230+
let permissions = !matches.has(&flags::NO_PERMISSIONS)?;
231+
let filesize = !matches.has(&flags::NO_FILESIZE)?;
232+
let user = !matches.has(&flags::NO_USER)?;
233+
234+
Ok(Columns { time_types, git, blocks, group, inode, links, permissions, filesize, user })
231235
}
232236
}
233237

@@ -309,7 +313,11 @@ impl TimeTypes {
309313
let accessed = matches.has(&flags::ACCESSED)?;
310314
let created = matches.has(&flags::CREATED)?;
311315

312-
let time_types = if let Some(word) = possible_word {
316+
let no_time = matches.has(&flags::NO_TIME)?;
317+
318+
let time_types = if no_time {
319+
TimeTypes { modified: false, changed: false, accessed: false, created: false }
320+
} else if let Some(word) = possible_word {
313321
if modified {
314322
return Err(Misfire::Useless(&flags::MODIFIED, true, &flags::TIME));
315323
}

src/output/table.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ pub struct Options {
2525
pub env: Environment,
2626
pub size_format: SizeFormat,
2727
pub time_format: TimeFormat,
28-
pub extra_columns: Columns,
28+
pub columns: Columns,
2929
}
3030

3131
// I had to make other types derive Debug,
3232
// and Mutex<UsersCache> is not that!
3333
impl fmt::Debug for Options {
3434
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
35-
write!(f, "Table({:#?})", self.extra_columns)
35+
write!(f, "Table({:#?})", self.columns)
3636
}
3737
}
3838

@@ -49,6 +49,11 @@ pub struct Columns {
4949
pub blocks: bool,
5050
pub group: bool,
5151
pub git: bool,
52+
53+
// Defaults to true:
54+
pub permissions: bool,
55+
pub filesize: bool,
56+
pub user: bool,
5257
}
5358

5459
impl Columns {
@@ -59,19 +64,25 @@ impl Columns {
5964
columns.push(Column::Inode);
6065
}
6166

62-
columns.push(Column::Permissions);
67+
if self.permissions {
68+
columns.push(Column::Permissions);
69+
}
6370

6471
if self.links {
6572
columns.push(Column::HardLinks);
6673
}
6774

68-
columns.push(Column::FileSize);
75+
if self.filesize {
76+
columns.push(Column::FileSize);
77+
}
6978

7079
if self.blocks {
7180
columns.push(Column::Blocks);
7281
}
7382

74-
columns.push(Column::User);
83+
if self.user {
84+
columns.push(Column::User);
85+
}
7586

7687
if self.group {
7788
columns.push(Column::Group);
@@ -296,7 +307,7 @@ pub struct Row {
296307

297308
impl<'a, 'f> Table<'a> {
298309
pub fn new(options: &'a Options, git: Option<&'a GitCache>, colours: &'a Colours) -> Table<'a> {
299-
let columns = options.extra_columns.collect(git.is_some());
310+
let columns = options.columns.collect(git.is_some());
300311
let widths = TableWidths::zero(columns.len());
301312

302313
Table {

xtests/help

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,9 @@ LONG VIEW OPTIONS
4343
-u, --accessed use the accessed timestamp field
4444
-U, --created use the created timestamp field
4545
--time-style how to format timestamps (default, iso, long-iso, full-iso)
46+
--no-permissions suppress the permissions field
47+
--no-filesize suppress the filesize field
48+
--no-user suppress the user field
49+
--no-time suppress the time field
4650
--git list each file's Git status, if tracked or ignored
4751
-@, --extended list each file's extended attributes and sizes

0 commit comments

Comments
 (0)