Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -D and --delete flags #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` | ✅ | ✅ |
Expand Down
19 changes: 19 additions & 0 deletions filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -66,6 +67,11 @@ func main() {
return
}

if *delete != "" {
DeleteFromStore(*delete)
return
}

// Read from file store
entries, err := readFileStore()
if err != nil {
Expand Down