Skip to content

Commit

Permalink
Obey an .ffrc file for skipping annoying directories and files.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawnMilo committed May 28, 2015
1 parent 5a2b11c commit 17233b8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.swp
.ffrc
37 changes: 32 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"path"
"path/filepath"
"runtime"
"strings"
"sync"
)

var path string // path to search
var dir string // path to search
var args []string
var wg sync.WaitGroup

var skip []string

var filenames chan rec

type rec struct {
Expand All @@ -35,18 +39,34 @@ func isDir(path string) bool {

func init() {
// Set up command-line flags.
flag.StringVar(&path, "p", ".", "path")
flag.StringVar(&dir, "p", ".", "path")
flag.Parse()
// Validate flags.
if !isDir(path) {
log.Fatal(path, "is not a valid path.")
if !isDir(dir) {
log.Fatal(dir, "is not a valid path.")
}
args = flag.Args()
if len(args) == 0 {
log.Fatal("no arguments passed")
}
filenames = make(chan rec)
runtime.GOMAXPROCS(runtime.NumCPU())

// Read rc file if available.
cwd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
rc, err := ioutil.ReadFile(path.Join(cwd, ".ffrc"))
skip = []string{}
if err != nil {
return
}
for _, bad := range strings.Split(string(rc), "\n") {
if bad != "" {
skip = append(skip, bad)
}
}
}

func check() {
Expand All @@ -57,6 +77,13 @@ func check() {
print = false
break
}

for _, bad := range skip {
if strings.Contains(r.path, bad) {
print = false
break
}
}
}
if print {
fmt.Println(r.path)
Expand All @@ -81,7 +108,7 @@ func main() {
wg.Add(1)
go check()
}
filepath.Walk(path, walker)
filepath.Walk(dir, walker)
close(filenames)
wg.Wait()
}

0 comments on commit 17233b8

Please sign in to comment.