Skip to content

Instantly share code, notes, and snippets.

@Aaron-Macneill
Created April 12, 2018 15:13
Show Gist options
  • Save Aaron-Macneill/427a15b22d283cfdb345839d5d29c7f8 to your computer and use it in GitHub Desktop.
Save Aaron-Macneill/427a15b22d283cfdb345839d5d29c7f8 to your computer and use it in GitHub Desktop.
ls clone in go. It's slightly faster than ls in directories with lots of files
package main
import (
"fmt"
"github.com/fatih/color"
"io/ioutil"
)
var (
fileColor = color.New(color.FgCyan)
folderColor = color.New(color.FgBlue, color.Bold)
hiddenColor = color.New(color.FgRed)
)
func main() {
files, err := ioutil.ReadDir(".")
if err != nil {
panic(err)
}
for _, file := range files {
if file.Name()[0] == '.' {
hiddenColor.Printf("%dB | %s\n", file.Size(), file.Name())
continue
}
if file.IsDir() {
folderColor.Printf("%dB | %s\n", file.Size(), file.Name())
continue
} else {
fileColor.Printf("%dB | %s\n", file.Size(), file.Name())
}
}
fmt.Printf("\n")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment