Compare commits

..

3 Commits
v1.0.0 ... main

Author SHA1 Message Date
37ee30ec03 added flag to set resursive depth for console output 2023-03-07 00:26:35 +01:00
Timon Ringwald
c4870bfe0d show version 2022-08-29 13:48:46 +02:00
Timon Ringwald
90265e7080 show exit option for file deletion in red 2022-08-17 13:19:57 +02:00
6 changed files with 25 additions and 33 deletions

24
.gitignore vendored
View File

@ -1,24 +1,2 @@
# ---> Go
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work
diskspace diskspace
output

View File

@ -32,7 +32,7 @@ func ls(args []string) {
for _, entry := range entries { for _, entry := range entries {
fmt.Println() fmt.Println()
fmt.Println(entry.StringRecursive(1)) fmt.Println(entry.StringRecursive(*RecursiveDirDepth))
} }
} }
@ -92,7 +92,7 @@ func exit() {
s := bufio.NewScanner(os.Stdin) s := bufio.NewScanner(os.Stdin)
s.Split(bufio.ScanRunes) s.Split(bufio.ScanRunes)
fmt.Print(Translate("exit? [y/N]: ")) fmt.Print(Translate("exit? [%s/%s]: ", "y", "N"))
if s.Scan() { if s.Scan() {
text := strings.ToLower(s.Text()) text := strings.ToLower(s.Text())
if text == "y" || text == "yes" { if text == "y" || text == "yes" {
@ -108,7 +108,7 @@ func exit() {
s := bufio.NewScanner(os.Stdin) s := bufio.NewScanner(os.Stdin)
s.Split(bufio.ScanRunes) s.Split(bufio.ScanRunes)
fmt.Print(Translate("Delete files? [y/N/c]: ")) fmt.Print(Translate("Delete files? [%s/%s/%s]: ", ColorRed.Sprint("y"), "n", "C"))
if s.Scan() { if s.Scan() {
text := strings.ToLower(s.Text()) text := strings.ToLower(s.Text())
if text == "y" || text == "yes" { if text == "y" || text == "yes" {

5
go.mod
View File

@ -2,7 +2,10 @@ module git.milar.in/milarin/diskspace
go 1.18 go 1.18
require github.com/fatih/color v1.13.0 require (
git.milar.in/milarin/buildinfo v1.0.0
github.com/fatih/color v1.13.0
)
require ( require (
github.com/mattn/go-colorable v0.1.9 // indirect github.com/mattn/go-colorable v0.1.9 // indirect

2
go.sum
View File

@ -1,3 +1,5 @@
git.milar.in/milarin/buildinfo v1.0.0 h1:tw98GupUYl/0a/3aPGuezhE4wseycOSsbcLp70hy60U=
git.milar.in/milarin/buildinfo v1.0.0/go.mod h1:arI9ZoENOgcZcanv25k9y4dKDUhPp0buJrlVerGruas=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=

11
main.go
View File

@ -12,6 +12,7 @@ import (
"syscall" "syscall"
"time" "time"
"git.milar.in/milarin/buildinfo"
"github.com/fatih/color" "github.com/fatih/color"
) )
@ -24,6 +25,8 @@ var (
ColorGreen = color.New(color.FgGreen) ColorGreen = color.New(color.FgGreen)
IconTheme = flag.String("i", "unicode", "icon theme (currently supported: default, unicode, nerd)") IconTheme = flag.String("i", "unicode", "icon theme (currently supported: default, unicode, nerd)")
ShowVersion = flag.Bool("v", false, "show version and exit")
RecursiveDirDepth = flag.Int("d", 1, "depth for recursively printing files of directories")
) )
// FIXME sometimes sorting not applied after removing items // FIXME sometimes sorting not applied after removing items
@ -34,6 +37,12 @@ var (
// TODO autocomplete on TAB (see arrow up issue: raw necessary?) // TODO autocomplete on TAB (see arrow up issue: raw necessary?)
func main() { func main() {
flag.Parse() flag.Parse()
if *ShowVersion {
buildinfo.Print(buildinfo.Options{})
return
}
rootPath := flag.Arg(0) rootPath := flag.Arg(0)
mounts, err := Mounts() mounts, err := Mounts()
@ -74,7 +83,7 @@ func main() {
showCurrentDir := true showCurrentDir := true
for { for {
if showCurrentDir { if showCurrentDir {
fmt.Println(Current.StringRecursive(1)) fmt.Println(Current.StringRecursive(*RecursiveDirDepth))
} }
fmt.Print("> ") fmt.Print("> ")

View File

@ -23,7 +23,6 @@ var Languages = map[string]map[string]string{
"Total size: %s": "Gesamtgröße: %s", "Total size: %s": "Gesamtgröße: %s",
"'%s' could not be found": "'%s' konnte nicht gefunden werden", "'%s' could not be found": "'%s' konnte nicht gefunden werden",
"Could not delete '%s': %s": "'%s' konnte nicht gelöscht werden: %s", "Could not delete '%s': %s": "'%s' konnte nicht gelöscht werden: %s",
"Delete files? [y/N/c]: ": "Dateien löschen? [y/N/c]: ",
"ambiguous path: %s": "Nicht eindeutiger Pfad: %s", "ambiguous path: %s": "Nicht eindeutiger Pfad: %s",
"possible paths:\n%s": "Mögliche Pfade:\n%s", "possible paths:\n%s": "Mögliche Pfade:\n%s",
"Commands:": "Befehle:", "Commands:": "Befehle:",
@ -33,7 +32,8 @@ var Languages = map[string]map[string]string{
"urm: unmark files for removal": "urm: Entmarkiere Dateien zur Löschung", "urm: unmark files for removal": "urm: Entmarkiere Dateien zur Löschung",
"exit: delete marked files and exit": "exit: Lösche markierte Dateien und beende Programm", "exit: delete marked files and exit": "exit: Lösche markierte Dateien und beende Programm",
"Use command 'exit' for exiting properly": "Nutze den Befehl 'exit', um das Programm ordnungsgemäß zu beenden", "Use command 'exit' for exiting properly": "Nutze den Befehl 'exit', um das Programm ordnungsgemäß zu beenden",
"exit? [y/N]: ": "Beenden? [y/N]: ", "Delete files? [%s/%s/%s]: ": "Dateien löschen? [%s/%s/%s]: ",
"exit? [%s/%s]: ": "Beenden? [%s/%s]: ",
}, },
"ja": { "ja": {
"fileCountFormat": "%d個", "fileCountFormat": "%d個",
@ -47,7 +47,6 @@ var Languages = map[string]map[string]string{
"Total size: %s": "全額: %s", "Total size: %s": "全額: %s",
"'%s' could not be found": "「%s」が見つかりませんでした", "'%s' could not be found": "「%s」が見つかりませんでした",
"Could not delete '%s': %s": "「%s」が削除できませんでした: %s", "Could not delete '%s': %s": "「%s」が削除できませんでした: %s",
"Delete files? [y/N/c]: ": "削除してほしいですか? [y/N/c]: ",
"ambiguous path: %s": "あいまいなパス: %s", "ambiguous path: %s": "あいまいなパス: %s",
"possible paths:\n%s": "可能なパス:\n%s", "possible paths:\n%s": "可能なパス:\n%s",
"Commands:": "コマンド:", "Commands:": "コマンド:",
@ -57,7 +56,8 @@ var Languages = map[string]map[string]string{
"urm: unmark files for removal": "urm: ファイルに削除のマークを除きます", "urm: unmark files for removal": "urm: ファイルに削除のマークを除きます",
"exit: delete marked files and exit": "exit: 削除のマークされたファイルを削除して終了", "exit: delete marked files and exit": "exit: 削除のマークされたファイルを削除して終了",
"Use command 'exit' for exiting properly": "「exit」コマンドを使って終了します", "Use command 'exit' for exiting properly": "「exit」コマンドを使って終了します",
"exit? [y/N]: ": "終了してほしいですか? [y/N]: ", "Delete files? [%s/%s/%s]: ": "削除してほしいですか? [%s/%s/%s]: ",
"exit? [%s/%s]: ": "終了してほしいですか? [%s/%s]: ",
}, },
} }