find-todos: allow for search other than TODO

like `find-todos -s IDEA`

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2017-08-29 13:24:27 -04:00
parent b898fc1bf5
commit d8b23b86fa
Signed by: vbatts
GPG Key ID: 10937E57733F1362
1 changed files with 10 additions and 12 deletions

View File

@ -10,14 +10,10 @@ import (
"strings"
)
var (
NoteDir string
flNoteDir *string
flNotePat *string
err error
)
func main() {
var NoteDir string
var err error
if len(os.Getenv("NOTEDIR")) > 0 {
NoteDir, err = filepath.Abs(os.Getenv("NOTEDIR"))
if err != nil {
@ -27,11 +23,13 @@ func main() {
} else {
NoteDir = filepath.Join(os.Getenv("HOME"), "Notes")
}
flNoteDir = flag.String("d", NoteDir, "directory of notes")
flNotePat = flag.String("p", "Tasks*.md", "file pattern")
flNoteDir := flag.String("d", NoteDir, "directory of notes")
flNoteFilePat := flag.String("p", "Tasks*.md", "file pattern")
flNoteTodoPat := flag.String("s", "TODO", "search for pattern in files")
flag.Parse()
matches, err := filepath.Glob(filepath.Join(*flNoteDir, *flNotePat))
matches, err := filepath.Glob(filepath.Join(*flNoteDir, *flNoteFilePat))
if err != nil {
fmt.Println(err)
os.Exit(1)
@ -55,10 +53,10 @@ func main() {
os.Exit(1)
}
count++
if strings.Contains(line, "TODO") {
if strings.Contains(line, *flNoteTodoPat) {
fmt.Printf("%s:%d\t%s\n", filepath.Base(match), count, strings.TrimRight(line, " \n"))
trimmed := strings.TrimSpace(line)
if strings.HasSuffix(trimmed, ":") || strings.HasSuffix(trimmed, "TODO") {
if strings.HasSuffix(trimmed, ":") || strings.HasSuffix(trimmed, *flNoteTodoPat) {
i := strings.IndexRune(line, rune(trimmed[0]))
for {
buf, err := rdr.Peek(i + 1)