Skip to content

Commit 966e8d0

Browse files
committed
docs: add cargo install instructions and improve README
- Add cargo install method as primary installation option - Expand documentation with comprehensive usage examples - Add detailed trash directory management instructions - Include manual recovery procedures and best practices - Implement filename conflict resolution to prevent overwrites
1 parent 21a2ddb commit 966e8d0

File tree

2 files changed

+173
-1
lines changed

2 files changed

+173
-1
lines changed

README.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,166 @@
88

99
- Prevents accidental permanent deletion of files.
1010
- Moves deleted files to a designated trash directory.
11+
- List and manage files in the trash directory.
12+
- Clean up the trash directory when needed.
13+
14+
## Installation
15+
16+
### Using Cargo Package Manager
17+
18+
If you have Rust and Cargo installed, you can install `rmxt` directly from crates.io:
19+
20+
```bash
21+
cargo install rmxt
22+
```
23+
24+
### Build and Install from Source
25+
26+
Alternatively, you can build and install from source:
27+
28+
```bash
29+
cargo build --release
30+
sudo cp target/release/rmxt /usr/local/bin/
31+
```
32+
33+
## Setting up Shell Aliases
34+
35+
To use `rmxt` as a replacement for the traditional `rm` command, you can set up aliases in your shell configuration:
36+
37+
### Bash
38+
Add this line to your `~/.bashrc` or `~/.bash_profile`:
39+
```bash
40+
alias rm='rmxt'
41+
```
42+
43+
### Zsh
44+
Add this line to your `~/.zshrc`:
45+
```zsh
46+
alias rm='rmxt'
47+
```
48+
49+
### Fish
50+
Add this command to your Fish configuration:
51+
```fish
52+
alias rm='rmxt'
53+
```
54+
55+
After adding the alias, reload your shell configuration:
56+
- Bash/Zsh: `source ~/.bashrc` (or `~/.zshrc`)
57+
- Fish: `source ~/.config/fish/config.fish`
58+
59+
## Usage Examples
60+
61+
### Basic File Removal
62+
```bash
63+
# Remove a single file
64+
rmxt file.txt
65+
66+
# Remove multiple files
67+
rmxt file1.txt file2.txt file3.txt
68+
69+
# Remove files with patterns (if your shell supports globbing)
70+
rmxt *.log
71+
```
72+
73+
### Directory Operations
74+
```bash
75+
# Remove a directory and its contents recursively
76+
rmxt -r directory/
77+
78+
# Remove an empty directory
79+
rmxt -d empty_directory/
80+
81+
# Force remove without prompts
82+
rmxt -f file.txt
83+
```
84+
85+
### Managing the Trash Directory
86+
```bash
87+
# List all files in the trash
88+
rmxt list
89+
90+
# Clean up the trash directory (permanently delete all trashed files)
91+
rmxt tidy
92+
```
93+
94+
### Combined Options
95+
```bash
96+
# Recursively and forcefully remove a directory
97+
rmxt -rf directory/
98+
99+
# Remove empty directories with force
100+
rmxt -df empty_dir1/ empty_dir2/
101+
```
102+
103+
## Trash Directory Location
104+
105+
### Default Location
106+
The trash directory is located at:
107+
```
108+
~/.trash/
109+
```
110+
Where `~` represents your home directory (e.g., `/home/username/.trash/` on Linux, `/Users/username/.trash/` on macOS).
111+
112+
### Directory Structure
113+
```
114+
~/.trash/
115+
├── file1.txt
116+
├── document.pdf
117+
├── folder1/
118+
│ ├── nested_file.txt
119+
│ └── subfolder/
120+
└── script.sh
121+
```
122+
123+
## Manual Recovery
124+
125+
### Recovering Individual Files
126+
You can manually recover files from the trash directory:
127+
128+
```bash
129+
# Navigate to the trash directory
130+
cd ~/.trash/
131+
132+
# List all trashed files
133+
ls -la
134+
135+
# Move a file back to your desired location
136+
mv file.txt ~/Documents/
137+
138+
# Move a directory back
139+
mv folder1/ ~/Projects/
140+
```
141+
142+
### Recovering with Original Structure
143+
Since `rmxt` moves files directly to `~/.trash/`, files lose their original directory structure. To help identify files:
144+
145+
```bash
146+
# List files with details (timestamps can help identify recent deletions)
147+
ls -lat ~/.trash/
148+
149+
# Find files by name
150+
find ~/.trash/ -name "*.txt" -type f
151+
152+
# Find directories
153+
find ~/.trash/ -type d
154+
```
155+
156+
### Important Recovery Notes
157+
- Files in the trash retain their original names but lose their directory path
158+
- If multiple files with the same name are deleted, `rmxt` prevents overwriting by automatically appending a number to the filename (e.g., `file.txt`, `file.txt.1`, `file.txt.2`)
159+
- Use `rmxt list` to see all trashed items
160+
- Recovered files will have their original permissions intact
161+
162+
## Command Line Options
163+
164+
| Option | Description |
165+
|--------|-------------|
166+
| `-r, --recursive` | Remove directories and their contents recursively |
167+
| `-f, --force` | Force removal without prompts |
168+
| `-d, --dir` | Remove empty directories |
169+
| `list` | List all files in the trash directory |
170+
| `tidy` | Permanently delete all files in the trash directory |
11171

12172
## Warning
13173

src/main.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,19 @@ pub fn move_to_trash(path: &std::path::Path) -> Result<(), std::io::Error> {
5454
));
5555
}
5656
};
57-
let new_path = trash.join(file_name);
57+
58+
let mut new_path = trash.join(file_name);
59+
let mut count = 1;
60+
61+
while new_path.exists() {
62+
let file_stem = path.file_stem().unwrap_or_default().to_string_lossy();
63+
let extension = path
64+
.extension()
65+
.map(|ext| format!(".{}", ext.to_string_lossy()))
66+
.unwrap_or_default();
67+
new_path = trash.join(format!("{file_stem}-{count}{extension}"));
68+
count += 1;
69+
}
5870
rename(path, new_path)
5971
}
6072

0 commit comments

Comments
 (0)