added drxrx stuff

main
simonkellet 1 year ago
parent ea607dc33a
commit 92c27d3aa0
  1. BIN
      gls
  2. 29
      main.go

BIN
gls

Binary file not shown.

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

Loading…
Cancel
Save