mirror of
https://github.com/vbatts/utils.git
synced 2024-12-04 22:45:42 +00:00
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:
parent
b898fc1bf5
commit
d8b23b86fa
1 changed files with 10 additions and 12 deletions
|
@ -10,14 +10,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
NoteDir string
|
|
||||||
flNoteDir *string
|
|
||||||
flNotePat *string
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
var NoteDir string
|
||||||
|
var err error
|
||||||
|
|
||||||
if len(os.Getenv("NOTEDIR")) > 0 {
|
if len(os.Getenv("NOTEDIR")) > 0 {
|
||||||
NoteDir, err = filepath.Abs(os.Getenv("NOTEDIR"))
|
NoteDir, err = filepath.Abs(os.Getenv("NOTEDIR"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -27,11 +23,13 @@ func main() {
|
||||||
} else {
|
} else {
|
||||||
NoteDir = filepath.Join(os.Getenv("HOME"), "Notes")
|
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()
|
flag.Parse()
|
||||||
|
|
||||||
matches, err := filepath.Glob(filepath.Join(*flNoteDir, *flNotePat))
|
matches, err := filepath.Glob(filepath.Join(*flNoteDir, *flNoteFilePat))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -55,10 +53,10 @@ func main() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
count++
|
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"))
|
fmt.Printf("%s:%d\t%s\n", filepath.Base(match), count, strings.TrimRight(line, " \n"))
|
||||||
trimmed := strings.TrimSpace(line)
|
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]))
|
i := strings.IndexRune(line, rune(trimmed[0]))
|
||||||
for {
|
for {
|
||||||
buf, err := rdr.Peek(i + 1)
|
buf, err := rdr.Peek(i + 1)
|
||||||
|
|
Loading…
Reference in a new issue