From 6659f6c00c0d151e7ac20e96f1b25a9329edd153 Mon Sep 17 00:00:00 2001 From: Justin Wyne <1986068+wyne@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:33:06 -0500 Subject: [PATCH] Add -D and --delete flags --- README.md | 2 +- filestore.go | 19 +++++++++++++++++++ main.go | 6 ++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a49c470..15beb0d 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,7 @@ Matching works similarly to zoxide and obeys the following rules: | `-R` reverse | ✅ | ✅ | | **Utility Flags** | | | | `-A`, `--add` | ✅ | ✅ | -| `-D`, `--delete` | ✅ | ❌ | +| `-D`, `--delete` | ✅ | ✅ | | **Internal Flags** | | | | `--sanitize` | ✅ | ✅ | | `--proc` | ✅ | ✅ | diff --git a/filestore.go b/filestore.go index e2748b3..70116bc 100644 --- a/filestore.go +++ b/filestore.go @@ -181,3 +181,22 @@ func AddToStore(path string) { // Write updated entries back to the file writeFileStore(entries) } + +// DeleteFromStore removes an entry from the store +func DeleteFromStore(path string) { + entries, err := readFileStore() + if err != nil { + return + } + + // Find and remove the entry + for i, entry := range entries { + if entry.Path == path { + // Remove the entry by slicing + entries = append(entries[:i], entries[i+1:]...) + // Write updated entries back to the file + writeFileStore(entries) + return + } + } +} diff --git a/main.go b/main.go index f7a96c1..a8b0305 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ func main() { // Internal flags add := flag.StringP("add", "A", "", "Internal: Add path to the store") + delete := flag.StringP("delete", "D", "", "Internal: Delete path from the store") sanitize := flag.BoolP("sanitize", "", false, "Internal: Sanitize command before processing") proc := flag.BoolP("proc", "", false, "Internal: Process a zsh-hook command") @@ -66,6 +67,11 @@ func main() { return } + if *delete != "" { + DeleteFromStore(*delete) + return + } + // Read from file store entries, err := readFileStore() if err != nil {