added drxrx stuff

This commit is contained in:
simonkellet 2023-07-26 21:39:01 +01:00
parent ea607dc33a
commit 92c27d3aa0
2 changed files with 21 additions and 8 deletions

BIN
gls

Binary file not shown.

29
main.go
View File

@ -71,8 +71,24 @@ func GetFileModTime(fi fs.FileInfo) (mod string) {
return mod
}
func GetFileType() {
//TODO: this function returns the dxrxrx stuff!
func GetFilePerm(file fs.FileInfo) (perms string) {
perms = ""
mode := file.Mode()
//Owner
perms += (string(mode.String()[0])) //d at the start for dir
for i := 1; i < 4; i++ {
perms += (string(mode.String()[i]))
}
//Group
for i := 4; i < 7; i++ {
perms += (string(mode.String()[i]))
}
//Other
for i := 7; i < 10; i++ {
perms += (string(mode.String()[i]))
}
return perms
}
func PrintHeaders() {
@ -96,7 +112,6 @@ func PrintWithoutL(content []fs.DirEntry, isFlagAEnable *bool) {
} else {
fileOutput.Printf(" %s ", item.Name())
}
}
fmt.Println()
}
@ -105,14 +120,12 @@ func PrintWithL(content []fs.DirEntry, isFlagAEnable *bool) {
dirOutput := color.New(color.FgMagenta, color.Bold)
fileOutput := color.New(color.FgWhite, color.Bold)
//print headers
PrintHeaders()
for _, item := range content {
//we now need extra info from the files
fi, err := os.Stat(item.Name())
check(err)
fType := item.Type().String()
fPerm := GetFilePerm(fi)
fDirSize := "-"
fSize := GetFileSize(fi)
fModTime := GetFileModTime(fi)
@ -123,9 +136,9 @@ func PrintWithL(content []fs.DirEntry, isFlagAEnable *bool) {
}
//check if item is dir
if item.IsDir() {
dirOutput.Printf("%s %7s %7s\t%s\n", fType, fDirSize, fModTime, item.Name()) //leave this
dirOutput.Printf("%s %7s %7s\t%s\n", fPerm, fDirSize, fModTime, item.Name())
} else {
fmt.Printf("%7s %7s %4s", fType, fSize, fModTime)
fmt.Printf("%7s %7s %4s", fPerm, fSize, fModTime)
fileOutput.Printf("\t%s\n", item.Name())
}