Browse Source

List files with colour

Lucas Stadler 9 years ago
parent
commit
0bc1ff7929
1 changed files with 3 additions and 0 deletions
  1. 3 0
      go/explore/explore.go

+ 3 - 0
go/explore/explore.go

12
var options struct {
12
var options struct {
13
	listFiles bool
13
	listFiles bool
14
}
14
}
15
var lsOpts = []string{"--color=auto", "--group-directories-first"}
15
16
16
func init() {
17
func init() {
17
	flag.BoolVar(&options.listFiles, "l", false, "Always list files")
18
	flag.BoolVar(&options.listFiles, "l", false, "Always list files")
39
40
40
	if options.listFiles {
41
	if options.listFiles {
41
		cmd := exec.Command("ls", dir)
42
		cmd := exec.Command("ls", dir)
43
		cmd.Args = append(cmd.Args, lsOpts...)
42
		cmd.Stdin = os.Stdin
44
		cmd.Stdin = os.Stdin
43
		cmd.Stdout = os.Stdout
45
		cmd.Stdout = os.Stdout
44
		cmd.Stderr = os.Stderr
46
		cmd.Stderr = os.Stderr
67
69
68
		if len(rs) == 0 {
70
		if len(rs) == 0 {
69
			cmd = exec.Command("ls", dir)
71
			cmd = exec.Command("ls", dir)
72
			cmd.Args = append(cmd.Args, lsOpts...)
70
		} else {
73
		} else {
71
			if options.listFiles {
74
			if options.listFiles {
72
				fmt.Println()
75
				fmt.Println()