Skip to content

Commit 8efa0bd

Browse files
committed
Pre-release v0.0.1
1 parent 9e14693 commit 8efa0bd

File tree

6 files changed

+70
-50
lines changed

6 files changed

+70
-50
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
fssize
2+
bin

README.md

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
- Ignore symlinks / hardlinks
2-
- Read home folder (Downloads, Documents, steam etc...) first
3-
4-
- Deleting (multiple selected) files
5-
- Special case for /swapfile, suggest or run clear swap thing
1+
Low on disk space? Use this tool to find the biggest files and folders on your Linux machine
62

73
[The command-line parser stops parsing after the first non-option](https://stackoverflow.com/a/25113485).\
8-
This is valid:
4+
This is valid:\
95
`fssize --ignore-hidden-files .`
106

11-
While this will not ignore hidden files:
7+
While this will not ignore hidden files:\
128
`fssize . --ignore-hidden-files`
13-
14-
Tabs: Files Folders

TODO.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- Ignore symlinks / hardlinks
2+
- Read home folder (Downloads, Documents, steam etc...) first
3+
4+
- Deleting (multiple selected) files
5+
- Special case for /swapfile, suggest or run clear swap thing

build-all-platforms.bash

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
bin=./bin
3+
4+
if [ ! -d $bin ]; then
5+
mkdir $bin
6+
fi
7+
8+
ldflags="-s -w"
9+
10+
# amd64
11+
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="$ldflags" -o $bin/fssize-linux-amd64
12+
13+
# i386
14+
GOOS=linux GOARCH=386 CGO_ENABLED=0 go build -ldflags="$ldflags" -o $bin/fssize-linux-i386
15+
16+
# arm64
17+
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags="$ldflags" -o $bin/fssize-linux-arm64
18+
19+
# arm
20+
GOOS=linux GOARCH=arm CGO_ENABLED=0 go build -ldflags="$ldflags" -o $bin/fssize-linux-arm

fssize.go

+41-35
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type FSSize struct {
2828
files []File
2929
folders []File
3030
packages []File // path = package name, sizeBytes = estimated size in kibibytes
31+
dpkgQueryWorked bool
3132
maxCount int
3233
ignoreHiddenFiles bool
3334
accumulating bool
@@ -41,8 +42,9 @@ type File struct {
4142

4243
func NewFSSize() *FSSize {
4344
return &FSSize{
44-
Box: tview.NewBox().SetBackgroundColor(tcell.NewRGBColor(46, 52, 54)),
45-
currentTab: Files,
45+
Box: tview.NewBox().SetBackgroundColor(tcell.NewRGBColor(46, 52, 54)),
46+
currentTab: Files,
47+
dpkgQueryWorked: true,
4648
}
4749
}
4850

@@ -78,6 +80,7 @@ func (fssize *FSSize) Draw(screen tcell.Screen) {
7880
}
7981

8082
tview.Print(screen, filesStyle+" Files [-:-:-:-]"+folderStyle+" Folders [-:-:-:-]"+packagesStyle+" Packages (dpkg-query) [-:-:-:-]", 0, 0, w, tview.AlignLeft, tcell.ColorDefault)
83+
tview.Print(screen, "<- Press Tab or Shift+Tab to switch ", 0, 0, w, tview.AlignRight, tcell.ColorDefault)
8184

8285
ptr := &fssize.files
8386
if fssize.currentTab == Folders {
@@ -86,46 +89,47 @@ func (fssize *FSSize) Draw(screen tcell.Screen) {
8689
ptr = &fssize.packages
8790
}
8891

89-
for i := 0; i < len(*ptr); i++ {
90-
if i+1 >= h-1 { // The bottom row is occupied by the bottom bar
91-
break
92-
}
92+
if fssize.currentTab == Packages && len(*ptr) == 0 {
93+
tview.Print(screen, "[::b]Failed to run dpkg-query", 0, h/2, w, tview.AlignCenter, tcell.ColorDefault)
94+
} else {
95+
for i := 0; i < len(*ptr); i++ {
96+
if i+1 >= h-1 { // The bottom row is occupied by the bottom bar
97+
break
98+
}
9399

94-
styleText := ""
95-
if i%2 == 0 {
96-
styleText = "[:#141414:]"
97-
}
100+
styleText := ""
101+
if i%2 == 0 {
102+
styleText = "[:#141414:]"
103+
}
98104

99-
var relPath string
100-
if fssize.rootFolderPath == "/" {
101-
relPath = (*ptr)[i].path
102-
} else {
103-
var err error
104-
relPath, err = filepath.Rel(fssize.rootFolderPath, (*ptr)[i].path)
105-
if err != nil {
105+
var relPath string
106+
if fssize.rootFolderPath == "/" {
106107
relPath = (*ptr)[i].path
108+
} else {
109+
var err error
110+
relPath, err = filepath.Rel(fssize.rootFolderPath, (*ptr)[i].path)
111+
if err != nil {
112+
relPath = (*ptr)[i].path
113+
}
107114
}
108-
}
109-
110-
prefix := ""
111-
if fssize.currentTab == Packages {
112-
prefix = "~"
113-
}
114-
_, sizePrintedLength := tview.Print(screen, styleText+"[::b]"+prefix+BytesToHumanReadableUnitString(uint64((*ptr)[i].sizeBytes), 3), 0, i+1, w, tview.AlignRight, tcell.ColorWhite)
115-
// Flawed when FilenameInvisibleCharactersAsCodeHighlighted does anything
116-
if len(relPath) > w-sizePrintedLength-1 {
117-
relPath = relPath[:max(0, w-sizePrintedLength-1-3)] + "[#606060]..."
118-
}
119115

120-
filenameText := FilenameInvisibleCharactersAsCodeHighlighted(relPath, styleText)
116+
prefix := ""
117+
if fssize.currentTab == Packages {
118+
prefix = "~"
119+
}
120+
_, sizePrintedLength := tview.Print(screen, styleText+"[::b]"+prefix+BytesToHumanReadableUnitString(uint64((*ptr)[i].sizeBytes), 3), 0, i+1, w, tview.AlignRight, tcell.ColorWhite)
121+
// Flawed when FilenameInvisibleCharactersAsCodeHighlighted does anything
122+
if len(relPath) > w-sizePrintedLength-1 {
123+
relPath = relPath[:max(0, w-sizePrintedLength-1-3)] + "[#606060]..."
124+
}
121125

122-
_, pathPrintedLength := tview.Print(screen, styleText+filenameText, 0, i+1, w-sizePrintedLength, tview.AlignLeft, tcell.NewRGBColor(200, 200, 200))
123-
//bruh := int32(max(20, 255-(i*8)))
124-
//tview.Print(screen, styleText+(*ptr)[i].path, 0, i, w, tview.AlignLeft, tcell.NewRGBColor(bruh, bruh, bruh))
126+
filenameText := FilenameInvisibleCharactersAsCodeHighlighted(relPath, styleText)
127+
_, pathPrintedLength := tview.Print(screen, styleText+filenameText, 0, i+1, w-sizePrintedLength, tview.AlignLeft, tcell.NewRGBColor(200, 200, 200))
125128

126-
if i%2 == 0 {
127-
for j := pathPrintedLength; j < w-sizePrintedLength; j++ {
128-
screen.SetContent(j, i+1, ' ', nil, tcell.StyleDefault.Background(tcell.NewRGBColor(0x14, 0x14, 0x14)))
129+
if i%2 == 0 {
130+
for j := pathPrintedLength; j < w-sizePrintedLength; j++ {
131+
screen.SetContent(j, i+1, ' ', nil, tcell.StyleDefault.Background(tcell.NewRGBColor(0x14, 0x14, 0x14)))
132+
}
129133
}
130134
}
131135
}
@@ -145,6 +149,7 @@ func (fssize *FSSize) Draw(screen tcell.Screen) {
145149
tview.Print(screen, "[:#00ff00:] Finished ", 0, h-1, w, tview.AlignLeft, tcell.ColorBlack)
146150
}
147151

152+
tview.Print(screen, programName+" "+version, 0, h-1, w, tview.AlignCenter, tcell.ColorBlack)
148153
tview.Print(screen, "Press 'q' to quit ", 0, h-1, w, tview.AlignRight, tcell.ColorBlack)
149154
}
150155

@@ -271,6 +276,7 @@ func (fssize *FSSize) AccumulatePackages() error {
271276
// According to the man page, --showformat has a short option '-f' since dpkg 1.13.1, so let's use the long option
272277
output, err := exec.Command("dpkg-query", "--show", "--showformat=${Installed-Size},${Package}\n").Output()
273278
if err != nil {
279+
fssize.dpkgQueryWorked = false
274280
return err
275281
}
276282

main.go

-6
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,6 @@ This outputs the estimated kibibyte (KiB) size of all packages`)
148148
return event
149149
})
150150

151-
/* go func() {
152-
for {
153-
app.QueueUpdateDraw(func() {})
154-
time.Sleep(30 * time.Millisecond)
155-
}
156-
}()*/
157151
fssize.app = app
158152

159153
fssize.AccumulatePackages()

0 commit comments

Comments
 (0)