-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
106 lines (90 loc) · 2.44 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//Copyright (c) 2015, Neil Moore
//See LICENSE.txt for license information.
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"unicode"
"github.com/rjeczalik/notify"
"github.com/neil-ca-moore/language-tool/formats"
"github.com/neil-ca-moore/language-tool/replacer"
"github.com/neil-ca-moore/language-tool/strings"
)
func allClasses() []strings.Class {
var res []strings.Class = make([]strings.Class, 0)
res = append(res, strings.NewNaughty())
runeSets := map[string][]rune{
"emoji": []rune(strings.Emoji),
"NFC": []rune(strings.AccentedNFC()),
"NFD": []rune(strings.AccentedNFD()),
"NFKC": []rune(strings.AccentedNFKC()),
"NFKD": []rune(strings.AccentedNFKD()),
"katakana": strings.AllRunes(unicode.Katakana),
"khmer": strings.AllRunes(unicode.Khmer),
"Nl": strings.AllRunes(unicode.Nl),
"Lo": strings.AllRunes(unicode.Lo),
"Sc": strings.AllRunes(unicode.Sc),
"Greek": strings.AllRunes(unicode.Greek),
"Linear-B": strings.AllRunes(unicode.Linear_B),
"Arabic": strings.AllRunes(unicode.Arabic),
"Symb": strings.AllRunes(unicode.Symbol),
}
for tag, runes := range runeSets {
res = append(res, strings.NewRandomPicker(tag, 10, runes))
}
return res
}
func allFormats() []formats.Format {
return []formats.Format{
formats.Folder{},
formats.Text{},
}
}
func setUpFolderListener(path string, stop <-chan bool) {
os.RemoveAll(path)
os.Mkdir(path, os.ModePerm)
replacer := replacer.NewMakerRegistry(path)
for _, format := range allFormats() {
for _, class := range allClasses() {
replacer.Add(format, class)
}
}
c := make(chan notify.EventInfo, 1000)
if err := notify.Watch(path, c, notify.Rename, notify.Remove); err != nil {
log.Fatal(err)
}
defer notify.Stop(c)
go func() {
for {
select {
case event := <-c:
replacer.Replace(event.Path())
}
}
}()
<-stop
}
func main() {
help := flag.Bool("help", false, "Print help")
path := flag.String("path", "", "Path that is kept chock full of files and folders with nasty names")
flag.Parse()
if len(*path) != 0 {
absPath, err := filepath.Abs(*path)
if err != nil {
fmt.Println("error: path ", path, " doesn't work: ", err)
}
stopChan := make(chan bool)
go setUpFolderListener(absPath, stopChan)
fmt.Println("Press return key to stop")
var s string
fmt.Scanf("%s\n", s)
stopChan <- true
} else if *help {
flag.PrintDefaults()
} else {
flag.PrintDefaults()
}
}