Re-add the ability to view or edit the latest zet

Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
Oliver Davies 2025-09-30 02:09:40 +01:00
parent 5a64827825
commit df9fa52c21
3 changed files with 37 additions and 10 deletions

View file

@ -14,18 +14,29 @@ var editCmd = &cobra.Command{
Use: "edit",
Aliases: []string{"e"},
Short: "Edit a specific zettel",
Long: `zet edit|e ID`,
Long: `zet edit|e ID
zet edit|e latest
`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 1 {
fmt.Println("Error: No id provided")
os.Exit(1)
}
idInt, err := strconv.Atoi(args[0])
if err != nil {
os.Exit(1)
var id int
if args[0] == "latest" {
id = lib.GetLatestZet()
} else {
i, err := strconv.Atoi(args[0])
if err != nil {
os.Exit(1)
}
id = i
}
lib.EditZet(idInt)
lib.EditZet(id)
},
}

View file

@ -14,19 +14,29 @@ var viewCmd = &cobra.Command{
Use: "view",
Aliases: []string{"v"},
Short: "View a specific zettel",
Long: `zet view|v ID`,
Long: `zet view|v ID
zet view|v latest
`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 1 {
fmt.Println("Error: No id provided")
os.Exit(1)
}
idInt, err := strconv.Atoi(args[0])
var id int
if err != nil {
os.Exit(1)
if args[0] == "latest" {
id = lib.GetLatestZet()
} else {
i, err := strconv.Atoi(args[0])
if err != nil {
os.Exit(1)
}
id = i
}
fmt.Println(lib.ViewZet(idInt))
fmt.Println(lib.ViewZet(id))
},
}

View file

@ -82,6 +82,12 @@ func GetAllZets() []int {
return sorted
}
func GetLatestZet() int {
z := GetAllZets()
return z[len(z)-1]
}
func SearchZets(query string) []int {
zets, err := execGitCommand("grep", "-i", "--name-only", "--word-regex", query)