aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2025-01-24 16:23:46 -0800
committerRose Hogenson <rosehogenson@posteo.net>2025-01-24 16:23:46 -0800
commitf90d3e58162a51de6781ea5e98eec10c04adf123 (patch)
treeb6a933910b6a51f85c06f61e6d7074fc70ea6ee8
parentfbf42e9f6e0776725aa91207ad9c3c66ad04ddfb (diff)
downloadtrash-f90d3e58162a51de6781ea5e98eec10c04adf123.tar.zst
Add a flashy README (thanks ChatGPT)
-rw-r--r--README.md66
-rw-r--r--trash.go23
2 files changed, 84 insertions, 5 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..0c71606
--- /dev/null
+++ b/README.md
@@ -0,0 +1,66 @@
+# 🗑️ Trash
+
+A **blazingly fast** and **safe** alternative to `rm`, written in Go! 🚀
+
+## ✨ Features
+
+- 🛡️ **Safer deletions**: No more accidental data loss! Files and directories
+ are moved to your system's trash instead of being permanently deleted.
+- ⚡ **Blazingly fast**: Leverages the power of Go for
+ lightning-fast performance.
+- 📜 **XDG Trash Specification**: Fully compatible with the XDG Trash spec for
+ cross-platform support.
+- 💡 **Intuitive**: Seamlessly integrates into your workflow as a drop-in
+ replacement for `rm`.
+
+---
+
+## 🚀 Installation
+
+```
+go install gitlab.com/rhogenson/trash@latest
+```
+
+---
+
+## 🛠️ Usage
+
+Replace `rm` with `trash` in your terminal commands for a safer experience:
+
+```bash
+trash somefile1.txt somefile2.txt somefile3.txt
+trash somedirectory/
+```
+
+### Recovering Files
+
+Files can be recovered from your system's trash in the
+`~/.local/share/Trash/files/` directory:
+
+```bash
+ls ~/.local/share/Trash/files # List all trashed files
+mv ~/.local/share/Trash/files/somefile1.txt.* ./somefile1.txt # Restore a trashed file
+```
+
+---
+
+## 🌟 Why Use Trash CLI?
+
+- 🧘 **Peace of mind**: No more oops moments when using `rm`.
+- 🏃 **Fast and efficient**: Written in Go, optimized for performance.
+- 🌎 **Portable**: Compatible with the XDG Trash spec.
+
+---
+
+## 💻 Compatibility
+
+Trash CLI is compatible with:
+- Linux 🐧
+- macOS 🍎
+- WSL 🌐
+
+---
+
+## 📄 License
+
+This project is licensed under the GPLv3 License. See the [COPYING](COPYING) file for details.
diff --git a/trash.go b/trash.go
index 6a3e024..889bc69 100644
--- a/trash.go
+++ b/trash.go
@@ -1,6 +1,7 @@
package main
import (
+ "flag"
"fmt"
"net/url"
"os"
@@ -39,30 +40,42 @@ DeletionDate=%s
}
if err := os.Rename(fileName, trash+"/files/"+strings.TrimSuffix(filepath.Base(info.Name()), ".trashinfo")); err != nil {
os.Remove(info.Name())
- return fmt.Errorf("%s: trash: %s", fileName, err)
+ return fmt.Errorf("%s: %s", fileName, err)
}
return nil
}
func main() {
+ flag.Usage = func() {
+ fmt.Fprintln(os.Stderr, "Usage: trash [FILE]...")
+ flag.PrintDefaults()
+ }
+ flag.Parse()
+
+ if len(flag.Args()) == 0 {
+ fmt.Fprintln(os.Stderr, "trash: missing operand")
+ flag.Usage()
+ os.Exit(1)
+ }
+
trash := os.Getenv("HOME") + "/.local/share/Trash"
if xdgDataHome := os.Getenv("XDG_DATA_HOME"); xdgDataHome != "" {
trash = xdgDataHome + "/Trash"
}
if err := os.MkdirAll(trash+"/files", 0755); err != nil {
- fmt.Fprintln(os.Stderr, err)
+ fmt.Fprintln(os.Stderr, "trash: ", err)
os.Exit(1)
}
if err := os.MkdirAll(trash+"/info", 0755); err != nil {
- fmt.Fprintln(os.Stderr, err)
+ fmt.Fprintln(os.Stderr, "trash: ", err)
os.Exit(1)
}
now := time.Now().Format("2006-01-02T15:04:05")
success := true
- for _, fileName := range os.Args[1:] {
+ for _, fileName := range flag.Args() {
if err := trashFile(fileName, trash, now); err != nil {
- fmt.Fprintln(os.Stderr, err)
+ fmt.Fprintln(os.Stderr, "trash: ", err)
success = false
}
}