52160345bf
Complete implementation of note management CLI with all core features: Commands: - add: Create new notes in $EDITOR with auto-generated filenames - list: Display all notes with titles, paths, and tags - search: Full-text search via ripgrep, tag-based filtering - tags: List all tags with occurrence counts - edit: Fuzzy search and edit notes by title - rm: Move notes to trash with confirmation prompt Features: - Automatic depository structure initialization (.jade/trash/) - Configurable tag prefix (default '+') - Parse title from first # heading (filename fallback) - Extract tags anywhere in content - Parse both [[wiki-links]] and [markdown](links) - Trash system with timestamps to prevent conflicts Technical: - Global config at ~/.config/jade/config.yml - Per-depository settings support - Ripgrep integration for fast search - $EDITOR integration for note editing - Comprehensive README with usage examples
73 lines
1.5 KiB
Go
73 lines
1.5 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"git.jnss.me/joakim/jadedepo/internal/engine"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
searchTag string
|
|
|
|
searchCmd = &cobra.Command{
|
|
Use: "search [query]",
|
|
Short: "Search notes by content or tags",
|
|
Run: searchNotes,
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
searchCmd.Flags().StringVarP(&searchTag, "tag", "t", "", "Search by tag")
|
|
rootCmd.AddCommand(searchCmd)
|
|
}
|
|
|
|
func searchNotes(cmd *cobra.Command, args []string) {
|
|
jd, err := engine.GetInstance()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
var results []string
|
|
|
|
// Search by tag if flag is provided
|
|
if searchTag != "" {
|
|
results, err = jd.SearchByTag(searchTag)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error searching by tag: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
} else {
|
|
// Search by content
|
|
if len(args) == 0 {
|
|
fmt.Fprintf(os.Stderr, "Error: query required when not searching by tag\n")
|
|
os.Exit(1)
|
|
}
|
|
query := strings.Join(args, " ")
|
|
results, err = jd.SearchContent(query)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error searching: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
if len(results) == 0 {
|
|
fmt.Println("No matches found")
|
|
return
|
|
}
|
|
|
|
fmt.Printf("Found %d match(es):\n\n", len(results))
|
|
for _, path := range results {
|
|
// Load note to get title
|
|
note, err := engine.LoadNote(jd.Config.DepoPath, path, jd.Config.TagPrefix)
|
|
if err != nil {
|
|
fmt.Printf(" %s\n", path)
|
|
continue
|
|
}
|
|
fmt.Printf(" %s (%s)\n", note.Title, path)
|
|
}
|
|
}
|