diff options
author | Daniel Milde <daniel@milde.cz> | 2024-04-23 16:13:35 +0200 |
---|---|---|
committer | Daniel Milde <daniel@milde.cz> | 2024-04-23 16:42:06 +0200 |
commit | e621676086e1349d1de5cfdf815b6f295721e7d6 (patch) | |
tree | 821534f8c9dd9522b9a7abaf8d66c2d5147fa889 | |
parent | f8802e61d034231d6584caa4038b6eff9266554a (diff) |
feat: add --show-mtime (-M) option
fixes #242
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | cmd/gdu/app/app.go | 6 | ||||
-rw-r--r-- | cmd/gdu/main.go | 1 | ||||
-rw-r--r-- | gdu.1.md | 2 | ||||
-rw-r--r-- | tui/tui.go | 5 | ||||
-rw-r--r-- | tui/tui_test.go | 12 |
6 files changed, 27 insertions, 0 deletions
@@ -65,6 +65,7 @@ Flags: -a, --show-apparent-size Show apparent size -d, --show-disks Show all mounted disks -C, --show-item-count Show number of items in directory + -M, --show-mtime Show latest mtime of items in directory -B, --show-relative-size Show relative size --si Show sizes with decimal SI prefixes (kB, MB, GB) instead of binary prefixes (KiB, MiB, GiB) --storage-path string Path to persistent key-value storage directory (default is /tmp/badger) (default "/tmp/badger") diff --git a/cmd/gdu/app/app.go b/cmd/gdu/app/app.go index 96bc77e..6007cab 100644 --- a/cmd/gdu/app/app.go +++ b/cmd/gdu/app/app.go @@ -57,6 +57,7 @@ type Flags struct { ShowRelativeSize bool `yaml:"show-relative-size"` ShowVersion bool `yaml:"-"` ShowItemCount bool `yaml:"show-item-count"` + ShowMTime bool `yaml:"show-mtime"` NoColor bool `yaml:"no-color"` NoMouse bool `yaml:"no-mouse"` NonInteractive bool `yaml:"non-interactive"` @@ -277,6 +278,11 @@ func (a *App) createUI() (UI, error) { ui.SetShowItemCount() }) } + if a.Flags.ShowMTime { + opts = append(opts, func(ui *tui.UI) { + ui.SetShowMTime() + }) + } if a.Flags.NoDelete { opts = append(opts, func(ui *tui.UI) { ui.SetNoDelete() diff --git a/cmd/gdu/main.go b/cmd/gdu/main.go index 4b40fad..f35e641 100644 --- a/cmd/gdu/main.go +++ b/cmd/gdu/main.go @@ -67,6 +67,7 @@ func init() { flags.BoolVarP(&af.ShowRelativeSize, "show-relative-size", "B", false, "Show relative size") flags.BoolVarP(&af.NoColor, "no-color", "c", false, "Do not use colorized output") flags.BoolVarP(&af.ShowItemCount, "show-item-count", "C", false, "Show number of items in directory") + flags.BoolVarP(&af.ShowMTime, "show-mtime", "M", false, "Show latest mtime of items in directory") flags.BoolVarP(&af.NonInteractive, "non-interactive", "n", false, "Do not run in interactive mode") flags.BoolVarP(&af.NoProgress, "no-progress", "p", false, "Do not show progress in non-interactive mode") flags.BoolVarP(&af.Summarize, "summarize", "s", false, "Show only a total in non-interactive mode") @@ -58,6 +58,8 @@ non-interactive mode **-C**, **\--show-item-count**\[=false\] Show number of items in directory +**-M**, **\--show-mtime**\[=false\] Show latest mtime of items in directory + **\--si**\[=false\] Show sizes with decimal SI prefixes (kB, MB, GB) instead of binary prefixes (KiB, MiB, GiB) **\--no-prefix**\[=false\] Show sizes as raw numbers without any prefixes (SI or binary) in non-interactive mode @@ -257,6 +257,11 @@ func (ui *UI) SetShowItemCount() { ui.showItemCount = true } +// SetShowMTime sets the flag to show last modification time of items in directory +func (ui *UI) SetShowMTime() { + ui.showMtime = true +} + // SetNoDelete disables all write operations func (ui *UI) SetNoDelete() { ui.noDelete = true diff --git a/tui/tui_test.go b/tui/tui_test.go index 46821ec..0e80d7a 100644 --- a/tui/tui_test.go +++ b/tui/tui_test.go @@ -760,6 +760,18 @@ func TestSetShowItemCount(t *testing.T) { assert.Equal(t, ui.showItemCount, true) } +func TestSetShowMTime(t *testing.T) { + simScreen := testapp.CreateSimScreen() + defer simScreen.Fini() + + app := testapp.CreateMockedApp(true) + ui := CreateUI(app, simScreen, &bytes.Buffer{}, false, true, false, false, false) + + ui.SetShowMTime() + + assert.Equal(t, ui.showMtime, true) +} + func TestNoDelete(t *testing.T) { simScreen := testapp.CreateSimScreen() defer simScreen.Fini() |