Skip to content

Commit ce595cd

Browse files
authored
Merge pull request #2 from santoshxshrestha/tidy
feat: tidy <delete content that are of more then 30 days in the trash…
2 parents b858eaf + 8761bc1 commit ce595cd

File tree

5 files changed

+167
-140
lines changed

5 files changed

+167
-140
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rmxt"
3-
version = "0.1.5"
3+
version = "0.1.6"
44
edition = "2024"
55
authors = ["Santosh Shrestha <santoshxshrestha@gmail.com> "]
66
description = "A replacement for the 'rm' command with a trash feature for safer file deletion."

README.md

Lines changed: 135 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,212 +1,211 @@
11
# rmxt
22

3-
`rmxt` is a safer, recoverable alternative to the traditional `rm` command. Instead of permanently deleting files, `rmxt` moves them to a trash directory, allowing you to recover them later if needed.
4-
5-
> **Note:** We do not move empty directories to the trash directory because they serve no purpose and can be recreated easily if needed.
3+
A safer, recoverable alternative to the traditional `rm` command that moves files to the system trash instead of permanently deleting them.
64

75
## Features
86

9-
- Prevents accidental permanent deletion of files.
10-
- 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.
7+
- **Cross-platform trash support** - Works on Linux, macOS, and Windows
8+
- **File recovery** - Restore individual files or all files from trash
9+
- **Trash management** - List, purge, and automatically clean old files
10+
- **Shell integration** - Drop-in replacement for `rm` command
11+
- **Safety first** - Prevents accidental permanent deletion
12+
- **Flexible options** - Force, recursive, and bypass modes available
1313

1414
## Installation
1515

16-
### Using Cargo Package Manager
17-
18-
If you have Rust and Cargo installed, you can install `rmxt` directly from crates.io:
19-
16+
### From crates.io
2017
```bash
2118
cargo install rmxt
2219
```
2320

24-
### Build and Install from Source
25-
26-
Alternatively, you can build and install from source:
27-
21+
### From Source
2822
```bash
23+
git clone https://github.com/santoshxshrestha/rmxt
24+
cd rmxt
2925
cargo build --release
3026
sudo cp target/release/rmxt /usr/local/bin/
3127
```
3228

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
29+
## Commands & Usage
6030

61-
### Basic File Removal
31+
### Basic File Operations
6232
```bash
63-
# Remove a single file
33+
# Remove files (move to trash)
6434
rmxt file.txt
65-
66-
# Remove multiple files
6735
rmxt file1.txt file2.txt file3.txt
68-
69-
# Remove files with patterns (if your shell supports globbing)
7036
rmxt *.log
71-
```
7237

73-
### Directory Operations
74-
```bash
75-
# Remove a directory and its contents recursively
38+
# Remove directories recursively
7639
rmxt -r directory/
7740

78-
# Remove an empty directory
41+
# Remove empty directories
7942
rmxt -d empty_directory/
8043

81-
# Force remove without prompts
44+
# Force removal without prompts
8245
rmxt -f file.txt
46+
47+
# Combined options
48+
rmxt -rf directory/ # Recursive + force
49+
rmxt -df empty_dir1/ empty_dir2/ # Directory + force
8350
```
8451

85-
### Managing the Trash Directory
52+
### Trash Management
8653
```bash
87-
# List all files in the trash
54+
# List all files in trash with details
8855
rmxt list
8956

90-
# Clean up the trash directory (permanently delete all trashed files)
57+
# Recover specific file from trash
58+
rmxt recover filename.txt
59+
60+
# Recover all files from trash to their original locations
61+
rmxt recover-all
62+
63+
# Permanently delete specific file from trash
64+
rmxt purge filename.txt
65+
66+
# Clean trash (remove files older than 30 days)
9167
rmxt tidy
9268
```
9369

9470
### Permanent Deletion (Bypass Trash)
9571
```bash
96-
# Permanently delete a file (bypass trash directory)
72+
# Permanently delete without using trash
9773
rmxt -i file.txt
98-
99-
# Permanently delete multiple files
10074
rmxt -i file1.txt file2.txt
10175

102-
# Permanently delete a directory and its contents
76+
# Permanently delete directory
10377
rmxt -ir directory/
78+
79+
# Permanently delete with force
80+
rmxt -ifr directory/
10481
```
10582

106-
> **⚠️ Warning:** When using the `-i, --ignore` option, files are permanently deleted and cannot be recovered from the trash directory. Use with caution!
83+
> **⚠️ Warning:** The `-i, --ignore` flag permanently deletes files without moving them to trash. Use with caution!
10784
108-
### Combined Options
109-
```bash
110-
# Recursively and forcefully remove a directory
111-
rmxt -rf directory/
85+
## Command Reference
11286

113-
# Remove empty directories with force
114-
rmxt -df empty_dir1/ empty_dir2/
87+
### Global Flags
88+
| Flag | Long Form | Description |
89+
|------|-----------|-------------|
90+
| `-i` | `--ignore` | Permanently delete without using trash |
91+
| `-r` | `--recursive` | Remove directories and contents recursively |
92+
| `-f` | `--force` | Force removal without prompts |
93+
| `-d` | `--dir` | Remove empty directories |
94+
| `-h` | `--help` | Show help information |
95+
| `-V` | `--version` | Show version information |
11596

116-
# Permanently and forcefully remove a directory
117-
rmxt -ifr directory/
118-
```
97+
### Subcommands
98+
| Command | Description |
99+
|---------|-------------|
100+
| `list` | Show all files in trash with deletion timestamps and original paths |
101+
| `recover <name>` | Restore specific file from trash to its original location |
102+
| `recover-all` | Restore all files from trash to their original locations |
103+
| `purge <name>` | Permanently delete specific file from trash |
104+
| `tidy` | Permanently delete files older than 30 days from trash |
105+
| `help` | Show help message or help for specific subcommand |
119106

120-
## Trash Directory Location
107+
## Trash Location
121108

122-
### Default Location
123-
The trash directory is located at:
124-
```
125-
~/.trash/
126-
```
127-
Where `~` represents your home directory (e.g., `/home/username/.trash/` on Linux, `/Users/username/.trash/` on macOS).
109+
Files are moved to the system trash directory using platform-native locations:
128110

129-
### Directory Structure
130-
```
131-
~/.trash/
132-
├── file1.txt
133-
├── document.pdf
134-
├── folder1/
135-
│ ├── nested_file.txt
136-
│ └── subfolder/
137-
└── script.sh
138-
```
111+
- **Linux**: `~/.local/share/Trash/files/`
112+
- **macOS**: `~/.Trash/`
113+
- **Windows**: Recycle Bin
139114

140-
## Manual Recovery
115+
The exact location is managed by the system's trash implementation, ensuring compatibility with your desktop environment's trash functionality.
141116

142-
### Recovering Individual Files
143-
You can manually recover files from the trash directory:
117+
## File Recovery
144118

119+
### Using Commands
145120
```bash
146-
# Navigate to the trash directory
147-
cd ~/.trash/
121+
# List what's in trash
122+
rmxt list
148123

149-
# List all trashed files
150-
ls -la
124+
# Sample output:
125+
# Name: document.pdf
126+
# Original Location: /home/user/Documents
127+
# Deleted At: 2024-01-15 14:30:22
151128

152-
# Move a file back to your desired location
153-
mv file.txt ~/Documents/
129+
# Recover specific file
130+
rmxt recover document.pdf
154131

155-
# Move a directory back
156-
mv folder1/ ~/Projects/
132+
# Recover all files
133+
rmxt recover-all
157134
```
158135

159-
### Recovering with Original Structure
160-
Since `rmxt` moves files directly to `~/.trash/`, files lose their original directory structure. To help identify files:
136+
### Important Recovery Notes
137+
- Files are restored to their original locations when possible
138+
- Original file permissions and timestamps are preserved
139+
- If the original directory no longer exists, recovery may fail
140+
- Use `rmxt list` to see available files and their original paths
161141

142+
## Shell Integration
143+
144+
Replace `rm` with `rmxt` by adding aliases to your shell configuration:
145+
146+
### Bash/Zsh
147+
Add to `~/.bashrc` or `~/.zshrc`:
162148
```bash
163-
# List files with details (timestamps can help identify recent deletions)
164-
ls -lat ~/.trash/
149+
alias rm='rmxt'
150+
```
165151

166-
# Find files by name
167-
find ~/.trash/ -name "*.txt" -type f
152+
### Fish Shell
153+
Add to `~/.config/fish/config.fish`:
154+
```fish
155+
alias rm='rmxt'
156+
```
168157

169-
# Find directories
170-
find ~/.trash/ -type d
158+
### PowerShell (Windows)
159+
Add to your PowerShell profile:
160+
```powershell
161+
Set-Alias rm rmxt
171162
```
172163

173-
### Important Recovery Notes
174-
- Files in the trash retain their original names but lose their directory path
175-
- 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`)
176-
- Use `rmxt list` to see all trashed items
177-
- Recovered files will have their original permissions intact
178-
179-
## Command Line Options
180-
181-
| Option | Description |
182-
|--------|-------------|
183-
| `-i, --ignore` | Don't put the file in trash, remove it permanently |
184-
| `-r, --recursive` | Remove directories and their contents recursively |
185-
| `-f, --force` | Force removal without prompts |
186-
| `-d, --dir` | Remove empty directories |
187-
| `-h, --help` | Print help information |
188-
| `-V, --version` | Print version information |
164+
After adding aliases, reload your shell:
165+
```bash
166+
# Bash/Zsh
167+
source ~/.bashrc # or ~/.zshrc
189168

190-
### Subcommands
169+
# Fish
170+
source ~/.config/fish/config.fish
171+
```
191172

192-
| Command | Description |
193-
|---------|-------------|
194-
| `list` | List all files in the trash directory |
195-
| `tidy` | Permanently delete all files in the trash directory |
196-
| `help` | Print help message or help for specific subcommand |
173+
## Dependencies
174+
175+
This project uses the following key dependencies:
197176

198-
## Warning
177+
- **[chrono](https://crates.io/crates/chrono)** - Date and time handling for trash cleanup
178+
- **[clap](https://crates.io/crates/clap)** - Command-line argument parsing with derive macros
179+
- **[trash](https://crates.io/crates/trash)** - Cross-platform system trash integration
180+
- **[walkdir](https://crates.io/crates/walkdir)** - Recursive directory traversal
181+
- **[dirs](https://crates.io/crates/dirs)** - Platform-specific directory utilities
199182

200-
The current implementation of `rmxt` relies heavily on the use of `unwrap()` for error handling. This means:
183+
## Development Status & Limitations
201184

202-
- If any operation (e.g., file I/O, directory creation) fails, the program will panic and terminate abruptly.
203-
- There is no graceful recovery or fallback mechanism in place for unexpected errors.
185+
### Current Limitations
186+
- The implementation uses `unwrap()` for error handling, which may cause panics on unexpected errors
187+
- Limited graceful error recovery in some edge cases
204188

205-
However, this is a work in progress, and the logic will be refactored to convert the code into a safer implementation. Future updates will:
189+
### Planned Improvements
190+
- Replace `unwrap()` calls with proper error propagation using `Result` and `?` operator
191+
- Enhanced error messages and recovery mechanisms
192+
- Additional configuration options for trash behavior
193+
- More robust file conflict resolution
206194

207-
- Replace `unwrap()` with proper error propagation using `Result` and the `?` operator.
208-
- Introduce robust error handling to ensure the program can recover gracefully from unexpected failures.
195+
## Contributing
196+
197+
Contributions are welcome! Please feel free to:
198+
- Report bugs and issues
199+
- Suggest new features
200+
- Submit pull requests
201+
- Improve documentation
209202

210203
## License
211204

212205
This project is licensed under the [MIT License](LICENSE).
206+
207+
## Repository
208+
209+
- **Homepage**: https://github.com/santoshxshrestha/rmxt
210+
- **Documentation**: https://github.com/santoshxshrestha/rmxt#readme
211+
- **Issues**: https://github.com/santoshxshrestha/rmxt/issues

src/args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub enum Commands {
3434
#[command(name = "list")]
3535
List,
3636

37-
/// Clean up the trash directory
37+
/// Clean up the trash directory by removing files older than 30 days
3838
#[command(name = "tidy")]
3939
Tidy,
4040

0 commit comments

Comments
 (0)