Skip to content

Commit 8500f74

Browse files
authored
Feat/support short option (#13)
* feat: add support for short options * chore: bump version to 1.7.0
1 parent de652d5 commit 8500f74

3 files changed

Lines changed: 61 additions & 46 deletions

File tree

README.md

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ In other words when you run `rm -rf file directory/`
4444
You will have files/dir the trash first,
4545
then you can decide to delete or clean them later on.
4646

47-
# Really Remove
48-
49-
If you don't really care to move it to Trash first.
50-
51-
Use `rm --rm`, e.g. `rm --rm file directory/`
52-
53-
Or, you can just use `/bin/rm` directly.
54-
5547
# Additional features
5648

5749
```
@@ -63,24 +55,51 @@ rm --empty-trash Empty all trash directories
6355
rm --show-trash-path Display all trash directory paths
6456
```
6557

58+
# Really Remove
59+
60+
If you don't really care to move it to Trash first.
61+
62+
rm-safely provide bypass to your OS rm via `--rm` option.
63+
64+
That means, use `rm --rm`
65+
66+
For examples:
67+
68+
- remove files and directy with OS rm.
69+
70+
`rm --rm file directory/`
71+
72+
- see the OS rm --help
73+
74+
```rm --rm --help
75+
/bin/rm: illegal option -- -
76+
usage: rm [-f | -i] [-dIPRrvWx] file ...
77+
unlink [--] file
78+
```
79+
80+
`--rm` is nothing special other than execute `/bin/rm` from current shell.
81+
82+
Or, you could just `/bin/rm` directly.
83+
6684
# Uninstall
6785

6886
`curl -fsSL https://raw.githubusercontent.com/zdk/rm-safely/main/rm-safely | bash -s uninstall`
6987

70-
# Appendix
71-
72-
> [!IMPORTANT]
73-
>
74-
> In case of switching to root user,
75-
>
76-
> 1. Please keep in mind that _the rm-safely alias is installed in current user only_.
77-
> 2. Always use `sudo -s` to keep current shell alias to root prompt, then run `rm` in the next step.
78-
>
79-
> Otherwise, chance you will bypass this alias and execute standard `/bin/rm` as your own risk.
80-
81-
> [!NOTE]
82-
>
83-
> - Main goal of rm-safely is to write it in a pure shell script.
84-
> - Alternative tools:
85-
> - https://github.com/MilesCranmer/rip2 (rust)
86-
> - https://github.com/Byron/trash-rs (rust)
88+
# Notes
89+
90+
- Main goal of rm-safely is to write it in a pure shell script
91+
as a gateway and a suppliment to rm, not a replacement.
92+
93+
- Alternative tools:
94+
95+
- https://github.com/MilesCranmer/rip2 (rust)
96+
- https://github.com/Byron/trash-rs (rust)
97+
- https://github.com/kaelzhang/shell-safe-rm (bash)
98+
- https://github.com/hitzhangjie/rm (go)
99+
100+
[Important Reminder],
101+
102+
Regarding the normal bahaviour of unix alias,
103+
104+
- Please keep in mind, _the rm-safely alias is available in current user only_.
105+
- So please always use `sudo -s` to switch to root user, then run `rm` in the next step.

rm-safely

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
VERSION="1.6.0"
3+
VERSION="1.7.0"
44
HOOK_FILE="$HOME/.rm-safely"
55

66
GREEN='\033[0;32m'
@@ -166,7 +166,7 @@ rm() {
166166
echo "All trash directories are empty"
167167
fi
168168
;;
169-
--list-trash)
169+
--list-trash|-l)
170170
local has_files=0
171171
echo "Trash Contents:"
172172
echo "==============="
@@ -199,7 +199,7 @@ rm() {
199199
echo "Trash is empty"
200200
fi
201201
;;
202-
--undo)
202+
--undo|-u)
203203
local entry
204204
entry=$(pop_from_undo_stack)
205205
if [ $? -ne 0 ]; then
@@ -246,7 +246,7 @@ rm() {
246246
return 1
247247
fi
248248
;;
249-
--restore)
249+
--restore|-s)
250250
shift
251251
if [ -z "$1" ]; then
252252
echo "ERROR: Please provide a hash to restore"
@@ -312,7 +312,7 @@ rm() {
312312
return 1
313313
fi
314314
;;
315-
--show-trash-path)
315+
--show-trash-path|-p)
316316
echo "Home trash: $HOME_TRASH_DIR"
317317
echo "All trash directories:"
318318
get_all_trash_dirs
@@ -328,15 +328,15 @@ Usage: rm [options] [files...]
328328
Files on the same filesystem as \$HOME go to ~/.local/share/Trash
329329
Files on other filesystems go to <mountpoint>/.Trash-<uid>
330330
331-
Special options:
332-
--rm Skip trash, execute real 'rm'
333-
--list-trash Show trash contents from all filesystems
334-
--restore <hash> Restore a file from trash using its hash
335-
--undo Restore the last deleted files
336-
--empty-trash Empty all trash directories
337-
--show-trash-path Display all trash directory paths
338-
--version Show version information
339-
--help Show this help
331+
Options:
332+
--rm Skip trash, execute real 'rm'
333+
--list-trash, -l Show trash contents from all filesystems
334+
--restore <hash>, -s Restore a file from trash using its hash
335+
--undo, -u Restore the last deleted files
336+
--empty-trash Empty all trash directories
337+
--show-trash-path, -p Display all trash directory paths
338+
--version Show version information
339+
--help Show this help
340340
HELP
341341
;;
342342
*)

test_rm-safely.sh

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env zsh
1+
#!/usr/bin/env bash
22

33
set -e
44

@@ -29,7 +29,7 @@ bash "$OLDPWD/rm-safely" install >/dev/null 2>&1 || true
2929
print_pass "Installation complete"
3030

3131
print_header "Testing in bash"
32-
bash <<'BASH_TEST'
32+
if bash <<'BASH_TEST'; then
3333
# shellcheck source=/dev/null
3434
source "$HOME/.rm-safely"
3535
@@ -61,16 +61,14 @@ else
6161
exit 1
6262
fi
6363
BASH_TEST
64-
65-
if [ $? -eq 0 ]; then
6664
print_pass "All bash tests passed"
6765
else
6866
print_fail "Bash tests failed"
6967
fi
7068

7169
if command -v zsh >/dev/null 2>&1; then
7270
print_header "Testing in zsh"
73-
zsh <<'ZSH_TEST'
71+
if zsh <<'ZSH_TEST'; then
7472
source "$HOME/.rm-safely"
7573
7674
# Test basic functionality
@@ -101,8 +99,6 @@ else
10199
exit 1
102100
fi
103101
ZSH_TEST
104-
105-
if [ $? -eq 0 ]; then
106102
print_pass "All zsh tests passed"
107103
else
108104
print_fail "Zsh tests failed"

0 commit comments

Comments
 (0)