|
1 | 1 | # rmxt |
2 | 2 |
|
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. |
6 | 4 |
|
7 | 5 | ## Features |
8 | 6 |
|
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 |
13 | 13 |
|
14 | 14 | ## Installation |
15 | 15 |
|
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 |
20 | 17 | ```bash |
21 | 18 | cargo install rmxt |
22 | 19 | ``` |
23 | 20 |
|
24 | | -### Build and Install from Source |
25 | | - |
26 | | -Alternatively, you can build and install from source: |
27 | | - |
| 21 | +### From Source |
28 | 22 | ```bash |
| 23 | +git clone https://github.com/santoshxshrestha/rmxt |
| 24 | +cd rmxt |
29 | 25 | cargo build --release |
30 | 26 | sudo cp target/release/rmxt /usr/local/bin/ |
31 | 27 | ``` |
32 | 28 |
|
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 |
60 | 30 |
|
61 | | -### Basic File Removal |
| 31 | +### Basic File Operations |
62 | 32 | ```bash |
63 | | -# Remove a single file |
| 33 | +# Remove files (move to trash) |
64 | 34 | rmxt file.txt |
65 | | - |
66 | | -# Remove multiple files |
67 | 35 | rmxt file1.txt file2.txt file3.txt |
68 | | - |
69 | | -# Remove files with patterns (if your shell supports globbing) |
70 | 36 | rmxt *.log |
71 | | -``` |
72 | 37 |
|
73 | | -### Directory Operations |
74 | | -```bash |
75 | | -# Remove a directory and its contents recursively |
| 38 | +# Remove directories recursively |
76 | 39 | rmxt -r directory/ |
77 | 40 |
|
78 | | -# Remove an empty directory |
| 41 | +# Remove empty directories |
79 | 42 | rmxt -d empty_directory/ |
80 | 43 |
|
81 | | -# Force remove without prompts |
| 44 | +# Force removal without prompts |
82 | 45 | rmxt -f file.txt |
| 46 | + |
| 47 | +# Combined options |
| 48 | +rmxt -rf directory/ # Recursive + force |
| 49 | +rmxt -df empty_dir1/ empty_dir2/ # Directory + force |
83 | 50 | ``` |
84 | 51 |
|
85 | | -### Managing the Trash Directory |
| 52 | +### Trash Management |
86 | 53 | ```bash |
87 | | -# List all files in the trash |
| 54 | +# List all files in trash with details |
88 | 55 | rmxt list |
89 | 56 |
|
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) |
91 | 67 | rmxt tidy |
92 | 68 | ``` |
93 | 69 |
|
94 | 70 | ### Permanent Deletion (Bypass Trash) |
95 | 71 | ```bash |
96 | | -# Permanently delete a file (bypass trash directory) |
| 72 | +# Permanently delete without using trash |
97 | 73 | rmxt -i file.txt |
98 | | - |
99 | | -# Permanently delete multiple files |
100 | 74 | rmxt -i file1.txt file2.txt |
101 | 75 |
|
102 | | -# Permanently delete a directory and its contents |
| 76 | +# Permanently delete directory |
103 | 77 | rmxt -ir directory/ |
| 78 | + |
| 79 | +# Permanently delete with force |
| 80 | +rmxt -ifr directory/ |
104 | 81 | ``` |
105 | 82 |
|
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! |
107 | 84 |
|
108 | | -### Combined Options |
109 | | -```bash |
110 | | -# Recursively and forcefully remove a directory |
111 | | -rmxt -rf directory/ |
| 85 | +## Command Reference |
112 | 86 |
|
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 | |
115 | 96 |
|
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 | |
119 | 106 |
|
120 | | -## Trash Directory Location |
| 107 | +## Trash Location |
121 | 108 |
|
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: |
128 | 110 |
|
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 |
139 | 114 |
|
140 | | -## Manual Recovery |
| 115 | +The exact location is managed by the system's trash implementation, ensuring compatibility with your desktop environment's trash functionality. |
141 | 116 |
|
142 | | -### Recovering Individual Files |
143 | | -You can manually recover files from the trash directory: |
| 117 | +## File Recovery |
144 | 118 |
|
| 119 | +### Using Commands |
145 | 120 | ```bash |
146 | | -# Navigate to the trash directory |
147 | | -cd ~/.trash/ |
| 121 | +# List what's in trash |
| 122 | +rmxt list |
148 | 123 |
|
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 |
151 | 128 |
|
152 | | -# Move a file back to your desired location |
153 | | -mv file.txt ~/Documents/ |
| 129 | +# Recover specific file |
| 130 | +rmxt recover document.pdf |
154 | 131 |
|
155 | | -# Move a directory back |
156 | | -mv folder1/ ~/Projects/ |
| 132 | +# Recover all files |
| 133 | +rmxt recover-all |
157 | 134 | ``` |
158 | 135 |
|
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 |
161 | 141 |
|
| 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`: |
162 | 148 | ```bash |
163 | | -# List files with details (timestamps can help identify recent deletions) |
164 | | -ls -lat ~/.trash/ |
| 149 | +alias rm='rmxt' |
| 150 | +``` |
165 | 151 |
|
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 | +``` |
168 | 157 |
|
169 | | -# Find directories |
170 | | -find ~/.trash/ -type d |
| 158 | +### PowerShell (Windows) |
| 159 | +Add to your PowerShell profile: |
| 160 | +```powershell |
| 161 | +Set-Alias rm rmxt |
171 | 162 | ``` |
172 | 163 |
|
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 |
189 | 168 |
|
190 | | -### Subcommands |
| 169 | +# Fish |
| 170 | +source ~/.config/fish/config.fish |
| 171 | +``` |
191 | 172 |
|
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: |
197 | 176 |
|
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 |
199 | 182 |
|
200 | | -The current implementation of `rmxt` relies heavily on the use of `unwrap()` for error handling. This means: |
| 183 | +## Development Status & Limitations |
201 | 184 |
|
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 |
204 | 188 |
|
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 |
206 | 194 |
|
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 |
209 | 202 |
|
210 | 203 | ## License |
211 | 204 |
|
212 | 205 | 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 |
0 commit comments