summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkadogo <kadogo@users.noreply.github.com>2024-02-10 22:07:34 +0100
committerDaniel Milde <daniel@milde.cz>2024-02-13 23:32:27 +0100
commit09d239fc8e5b3dfcefacd5ccd8649fc4c5baca12 (patch)
treeba58c3479830ecbc7380b8549aa6fa22f83ad62b
parenteb659516feb15c9a1f0569ee63d0efc09a51ec29 (diff)
Add export-file in interactive mode
Signed-off-by: kadogo <kadogo@users.noreply.github.com>
-rw-r--r--cmd/gdu/app/app.go7
-rw-r--r--cmd/gdu/main.go1
-rw-r--r--gdu.1.md102
-rw-r--r--tui/keys.go21
-rw-r--r--tui/show.go1
-rw-r--r--tui/tui.go6
6 files changed, 36 insertions, 102 deletions
diff --git a/cmd/gdu/app/app.go b/cmd/gdu/app/app.go
index 472cecb..87c4e4e 100644
--- a/cmd/gdu/app/app.go
+++ b/cmd/gdu/app/app.go
@@ -46,6 +46,7 @@ type Flags struct {
CfgFile string `yaml:"-"`
LogFile string `yaml:"log-file"`
InputFile string `yaml:"input-file"`
+ ExportTree string `yaml:"export-file"`
OutputFile string `yaml:"output-file"`
IgnoreDirs []string `yaml:"ignore-dirs"`
IgnoreDirPatterns []string `yaml:"ignore-dir-patterns"`
@@ -265,6 +266,12 @@ func (a *App) createUI() (UI, error) {
})
}
+ if a.Flags.ExportTree != "" {
+ opts = append(opts, func(ui *tui.UI) {
+ ui.SetExportTree(a.Flags.ExportTree)
+ })
+ }
+
ui = tui.CreateUI(
a.TermApp,
a.Screen,
diff --git a/cmd/gdu/main.go b/cmd/gdu/main.go
index 04bca33..c78ff08 100644
--- a/cmd/gdu/main.go
+++ b/cmd/gdu/main.go
@@ -42,6 +42,7 @@ func init() {
flags.StringVarP(&af.LogFile, "log-file", "l", "/dev/null", "Path to a logfile")
flags.StringVarP(&af.OutputFile, "output-file", "o", "", "Export all info into file as JSON")
flags.StringVarP(&af.InputFile, "input-file", "f", "", "Import analysis from JSON file")
+ flags.StringVarP(&af.ExportTree, "export-file", "e", "", "Export all info into file as JSON when doing uppercase S")
flags.IntVarP(&af.MaxCores, "max-cores", "m", runtime.NumCPU(), fmt.Sprintf("Set max cores that GDU will use. %d cores available", runtime.NumCPU()))
flags.BoolVarP(&af.ShowVersion, "version", "v", false, "Print version")
diff --git a/gdu.1.md b/gdu.1.md
deleted file mode 100644
index e6d4dc6..0000000
--- a/gdu.1.md
+++ /dev/null
@@ -1,102 +0,0 @@
----
-date: {{date}}
-section: 1
-title: gdu
----
-
-# NAME
-
-gdu - Pretty fast disk usage analyzer written in Go
-
-# SYNOPSIS
-
-**gdu \[flags\] \[directory_to_scan\]**
-
-# DESCRIPTION
-
-Pretty fast disk usage analyzer written in Go.
-
-Gdu is intended primarily for SSD disks where it can fully utilize
-parallel processing. However HDDs work as well, but the performance gain
-is not so huge.
-
-# OPTIONS
-
-**-h**, **\--help**\[=false\] help for gdu
-
-**-i**, **\--ignore-dirs**=\[/proc,/dev,/sys,/run\] Absolute paths to
-ignore (separated by comma)
-
-**-I**, **\--ignore-dirs-pattern** Absolute path patterns to
-ignore (separated by comma)
-
-**-X**, **\--ignore-from** Read absolute path patterns to ignore from file
-
-**-l**, **\--log-file**=\"/dev/null\" Path to a logfile
-
-**-m**, **\--max-cores** Set max cores that GDU will use.
-
-**-c**, **\--no-color**\[=false\] Do not use colorized output
-
-**-x**, **\--no-cross**\[=false\] Do not cross filesystem boundaries
-
-**-H**, **\--no-hidden**\[=false\] Ignore hidden directories (beginning with dot)
-
-**-L**, **\--follow-symlinks**\[=false\] Follow symlinks for files, i.e. show the
-size of the file to which symlink points to (symlinks to directories are not followed)
-
-**-n**, **\--non-interactive**\[=false\] Do not run in interactive mode
-
-**-p**, **\--no-progress**\[=false\] Do not show progress in
-non-interactive mode
-
-**-s**, **\--summarize**\[=false\] Show only a total in non-interactive mode
-
-**-d**, **\--show-disks**\[=false\] Show all mounted disks
-
-**-a**, **\--show-apparent-size**\[=false\] Show apparent size
-
-**\--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
-
-**\--no-mouse**\[=false\] Do not use mouse
-
-**-f**, **\----input-file** Import analysis from JSON file. If the file is \"-\", read from standard input.
-
-**-o**, **\----output-file** Export all info into file as JSON. If the file is \"-\", write to standard output.
-
-**\--config-file**=\"$HOME/.gdu.yaml\" Read config from file
-
-**\--write-config**\[=false\] Write current configuration to file (default is $HOME/.gdu.yaml)
-
-**-g**, **\--const-gc**\[=false\] Enable memory garbage collection during analysis with constant level set by GOGC
-
-**\--enable-profiling**\[=false\] Enable collection of profiling data and provide it on http://localhost:6060/debug/pprof/
-
-**-v**, **\--version**\[=false\] Print version
-
-# FILE FLAGS
-
-Files and directories may be prefixed by a one-character
-flag with following meaning:
-
-**!**
-
-: An error occurred while reading this directory.
-
-**.**
-
-: An error occurred while reading a subdirectory, size may be not correct.
-
-**\@**
-
-: File is symlink or socket.
-
-**H**
-
-: Same file was already counted (hard link).
-
-**e**
-
-: Directory is empty.
diff --git a/tui/keys.go b/tui/keys.go
index 18e49e8..f534bd3 100644
--- a/tui/keys.go
+++ b/tui/keys.go
@@ -2,6 +2,10 @@ package tui
import (
"fmt"
+ "bytes"
+ "strconv"
+ "time"
+ "os"
"github.com/dundee/gdu/v5/pkg/fs"
"github.com/gdamore/tcell/v2"
@@ -244,6 +248,23 @@ func (ui *UI) handleMainActions(key *tcell.EventKey) *tcell.EventKey {
if ui.currentDir != nil {
ui.rescanDir()
}
+ case 'S':
+ var buff bytes.Buffer
+
+ buff.Write([]byte(`[1,2,{"progname":"gdu","progver":"`))
+ //~ buff.Write([]byte(build.Version))
+ buff.Write([]byte(`","timestamp":`))
+ buff.Write([]byte(strconv.FormatInt(time.Now().Unix(), 10)))
+ buff.Write([]byte("},\n"))
+
+ file, fileErr := os.Create(ui.exportTree)
+ if fileErr != nil {
+ fmt.Println(fileErr)
+ }
+
+ ui.topDir.EncodeJSON(&buff, true)
+ buff.Write([]byte("]\n"))
+ buff.WriteTo(file)
case 's':
ui.setSorting("size")
case 'C':
diff --git a/tui/show.go b/tui/show.go
index 765a6a6..4b14b1e 100644
--- a/tui/show.go
+++ b/tui/show.go
@@ -17,6 +17,7 @@ const helpText = ` [::b]up/down, k/j [white:black:-]Move cursor up/down
[::b]left, h [white:black:-]Go to parent directory
[::b]r [white:black:-]Rescan current directory
+ [::b]S [white:black:-]Export actual tree
[::b]/ [white:black:-]Search items by name
[::b]a [white:black:-]Toggle between showing disk usage and apparent size
[::b]B [white:black:-]Toggle bar alignment to biggest file or directory
diff --git a/tui/tui.go b/tui/tui.go
index ac7715a..5eaf8fd 100644
--- a/tui/tui.go
+++ b/tui/tui.go
@@ -35,6 +35,7 @@ type UI struct {
topDir fs.Item
topDirPath string
currentDirPath string
+ exportTree string
askBeforeDelete bool
showItemCount bool
showMtime bool
@@ -183,6 +184,11 @@ func (ui *UI) SetCurrentItemNameMaxLen(len int) {
ui.currentItemNameMaxLen = len
}
+// SetExportTree set the path where to export when doing the key "S"
+func (ui *UI) SetExportTree(path string) {
+ ui.exportTree = path
+}
+
// UseOldSizeBar uses the old size bar (# chars) instead of the new one (unicode block elements)
func (ui *UI) UseOldSizeBar() {
ui.useOldSizeBar = true