Skip to content

Commit 5ee5b2a

Browse files
committed
-
1 parent 1d88c96 commit 5ee5b2a

File tree

7 files changed

+569
-95
lines changed

7 files changed

+569
-95
lines changed

README.md

+18-95
Original file line numberDiff line numberDiff line change
@@ -2,112 +2,35 @@
22

33
skip important files and dirs during rm;
44

5-
in the past, users have reported success in deleting their home dir, root dir,
6-
and much more; skip-rm helps you prevent such accidental deletions by checking
7-
filenames; you specify which files to and not to delete, and skip-rm does the
8-
rest for you;
5+
in the past, users have frequently reported success in deleting their home dir,
6+
root dir, and much more; skip-rm helps prevent such accidental deletions using
7+
filename checks; you specify which files to and not to delete and skip-rm does
8+
the rest for you;
99

1010
## install
1111

12-
skip-rm has a single script file and a few config files;
12+
this tool has several implementations:
1313

14-
the script file shall be installed into a dir listed in envar `PATH`:
14+
- `bash/README.md`;
1515

16-
cp skip-rm /usr/bin/
16+
- `go/README.md`;
1717

18-
the config files shall be installed into either system or user config dir;
19-
system config dir is `/etc/skip-rm`; user config dir is `~/.config/skip-rm`;
20-
user config has higher priority;
18+
these implementations are independent, and you can choose any one of them; but
19+
beware there may be minor differences among these implementations, which means
20+
they may not give exactly the same behavior; double check the source code, and
21+
make sure you understand what is happening before use; open an issue if needed;
2122

22-
to install into system config dir:
23+
the bash implementation has longer history and tends to be more stable; but it
24+
is very slow when there are a lot of filenames; the go implementation is newer
25+
and faster, but has a higher chance of malfunction; you are advised to do some
26+
dryrun (using a fake `rm`) before deploying this tool so as to not have a pity;
2327

24-
cp -r config/skip-rm /etc/
25-
26-
to install into user config dir:
27-
28-
cp -r config/skip-rm ~/.config/
29-
30-
## usage
31-
32-
to test with the default config (do not test with important files):
33-
34-
skip-rm {files-to-remove}
35-
36-
if everything is good, alias `rm` to `skip-rm`:
37-
38-
alias rm='skip-rm'
39-
40-
`skip-rm` is designed as a wrapper of and a drop-in replacement for `rm`; it is
41-
recommened to alias `rm` to `skip-rm` in bashrc; then simply run `rm` as usual,
42-
knowing important files and dirs will be protected from deletion;
43-
44-
## config
45-
46-
the main config file is `skip-rm.conf`, in json format:
47-
48-
{
49-
"command": "/bin/rm",
50-
"matcher": "glob",
51-
"mode": "blacklist",
52-
"blacklist": "~/.config/skip-rm/black.list",
53-
"whitelist": "~/.config/skip-rm/white.list"
54-
}
55-
56-
available config options are:
57-
58-
- *command*: the builtin rm command;
59-
60-
- *matcher*: filename matcher:
61-
62-
- *string*: match string verbatim;
63-
64-
- *glob*: match with glob patterns:
65-
66-
- `?` matches any single char (excluding slash `/`);
67-
68-
- `*` matches any string (excluding slash `/`);
69-
70-
- `**` matches any string (including slash `/`);
71-
72-
- `[...]`: matches any one of the enclosed characters;
73-
74-
- *regex*: match with regular expressions;
75-
76-
- *mode*: how to compare against a pre-defined list:
77-
78-
- *blacklist*: input filenames matching any pattern on the list are
79-
skipped; others are deleted;
80-
81-
- *whitelist*: input filenames matching any pattern on the list are
82-
deleted; others are skipped;
83-
84-
- *blacklist*: blacklist file path; the first tilde `~` is translated to home
85-
dir;
86-
87-
- *whitelist*: whitelist file path; the first tilde `~` is translated to home
88-
dir;
89-
90-
### blacklist and whitelist
91-
92-
blacklist and whitelist have the same format: each line specifies a pattern; the
93-
first tilde `~` in the pattern is translated to home dir;
94-
95-
each input filename is first converted to realpath (without symlink expansion),
96-
then compared with these patterns one by one, until a match is found or no match
97-
is found; therefore, when you are writing patterns, expect them to be matched
98-
against realpaths;
99-
100-
## depend
101-
102-
skip-rm depends on:
103-
104-
- [jq](https://github.com/stedolan/jq);
105-
106-
- [sed](https://www.gnu.org/software/sed/);
28+
these implementations share the same config files; a sample config is provided
29+
in `config` dir; the entire config has a json file plus some lists of patterns;
10730

10831
## license
10932

110-
Copyright (C) 2018 Cyker Way
33+
Copyright (C) 2018-2022 Cyker Way
11134

11235
This program is free software: you can redistribute it and/or modify it under
11336
the terms of the GNU General Public License as published by the Free Software

bash/README.md

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# skip-rm (bash)
2+
3+
skip important files and dirs during rm;
4+
5+
in the past, users have frequently reported success in deleting their home dir,
6+
root dir, and much more; skip-rm helps prevent such accidental deletions using
7+
filename checks; you specify which files to and not to delete and skip-rm does
8+
the rest for you;
9+
10+
## install
11+
12+
skip-rm has a single script file and a few config files;
13+
14+
the script file shall be installed into a dir listed in envar `PATH`:
15+
16+
cp skip-rm /usr/bin/
17+
18+
the config files shall be installed into either system or user config dir;
19+
system config dir is `/etc/skip-rm`; user config dir is `~/.config/skip-rm`;
20+
user config has higher priority;
21+
22+
to install into system config dir:
23+
24+
cp -r config/skip-rm /etc/
25+
26+
to install into user config dir:
27+
28+
cp -r config/skip-rm ~/.config/
29+
30+
## usage
31+
32+
to test with the default config (do not test with important files):
33+
34+
skip-rm {files-to-remove}
35+
36+
if everything is good, alias `rm` to `skip-rm`:
37+
38+
alias rm='skip-rm'
39+
40+
`skip-rm` is designed as a wrapper of and a drop-in replacement for `rm`; it is
41+
recommened to alias `rm` to `skip-rm` in bashrc; then simply run `rm` as usual,
42+
knowing important files and dirs will be protected from deletion;
43+
44+
## config
45+
46+
the main config file is `skip-rm.conf`, in json format:
47+
48+
{
49+
"command": "/bin/rm",
50+
"matcher": "glob",
51+
"mode": "blacklist",
52+
"blacklist": "~/.config/skip-rm/black.list",
53+
"whitelist": "~/.config/skip-rm/white.list"
54+
}
55+
56+
available config options are:
57+
58+
- *command*: the builtin rm command;
59+
60+
- *matcher*: filename matcher:
61+
62+
- *string*: match string verbatim;
63+
64+
- *glob*: match with glob patterns:
65+
66+
- `?` matches any single char (excluding slash `/`);
67+
68+
- `*` matches any string (excluding slash `/`);
69+
70+
- `**` matches any string (including slash `/`);
71+
72+
- `[...]`: matches any one of the enclosed characters;
73+
74+
- *regex*: match with regular expressions;
75+
76+
- *mode*: how to compare against a pre-defined list:
77+
78+
- *blacklist*: input filenames matching any pattern on the list are
79+
skipped; others are deleted;
80+
81+
- *whitelist*: input filenames matching any pattern on the list are
82+
deleted; others are skipped;
83+
84+
- *blacklist*: blacklist file path; the first tilde `~` is translated to home
85+
dir of current user;
86+
87+
- *whitelist*: whitelist file path; the first tilde `~` is translated to home
88+
dir of current user;
89+
90+
### blacklist and whitelist
91+
92+
blacklist and whitelist have the same format: each line specifies a pattern; the
93+
first tilde `~` in the pattern is translated to home dir of current user;
94+
95+
each input filename is first converted to realpath (without symlink expansion),
96+
then compared with these patterns one by one, until a match is found or no match
97+
is found; therefore, when you are writing patterns, expect them to be matched
98+
against realpaths;
99+
100+
## depend
101+
102+
this implementation depends on:
103+
104+
- [jq](https://github.com/stedolan/jq);
105+
106+
- [sed](https://www.gnu.org/software/sed/);
107+
108+
## license
109+
110+
Copyright (C) 2018-2022 Cyker Way
111+
112+
This program is free software: you can redistribute it and/or modify it under
113+
the terms of the GNU General Public License as published by the Free Software
114+
Foundation, either version 3 of the License, or (at your option) any later
115+
version.
116+
117+
This program is distributed in the hope that it will be useful, but WITHOUT ANY
118+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
119+
PARTICULAR PURPOSE. See the GNU General Public License for more details.
120+
121+
You should have received a copy of the GNU General Public License along with
122+
this program. If not, see <https://www.gnu.org/licenses/>.
123+

skip-rm bash/skip-rm

File renamed without changes.

go/README.md

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# skip-rm (go)
2+
3+
skip important files and dirs during rm;
4+
5+
in the past, users have frequently reported success in deleting their home dir,
6+
root dir, and much more; skip-rm helps prevent such accidental deletions using
7+
filename checks; you specify which files to and not to delete and skip-rm does
8+
the rest for you;
9+
10+
## install
11+
12+
skip-rm has a single executable file and a few config files;
13+
14+
to build the executable file (named `skip-rm`):
15+
16+
go build -o skip-rm .
17+
18+
the executable file shall be installed into a dir listed in envar `PATH`:
19+
20+
cp skip-rm /usr/bin/
21+
22+
the config files shall be installed into either system or user config dir;
23+
system config dir is `/etc/skip-rm`; user config dir is `~/.config/skip-rm`;
24+
user config has higher priority;
25+
26+
to install into system config dir:
27+
28+
cp -r config/skip-rm /etc/
29+
30+
to install into user config dir:
31+
32+
cp -r config/skip-rm ~/.config/
33+
34+
## usage
35+
36+
to test with the default config (do not test with important files):
37+
38+
skip-rm {files-to-remove}
39+
40+
if everything is good, alias `rm` to `skip-rm`:
41+
42+
alias rm='skip-rm'
43+
44+
`skip-rm` is designed as a wrapper of and a drop-in replacement for `rm`; it is
45+
recommened to alias `rm` to `skip-rm` in bashrc; then simply run `rm` as usual,
46+
knowing important files and dirs will be protected from deletion;
47+
48+
## config
49+
50+
the main config file is `skip-rm.conf`, in json format:
51+
52+
{
53+
"command": "/bin/rm",
54+
"matcher": "glob",
55+
"mode": "blacklist",
56+
"blacklist": "~/.config/skip-rm/black.list",
57+
"whitelist": "~/.config/skip-rm/white.list"
58+
}
59+
60+
available config options are:
61+
62+
- *command*: the builtin rm command;
63+
64+
- *matcher*: filename matcher:
65+
66+
- *string*: match string verbatim;
67+
68+
- *glob*: match with glob patterns:
69+
70+
- `?` matches any single char (excluding slash `/`);
71+
72+
- `*` matches any string (excluding slash `/`);
73+
74+
- `**` matches any string (including slash `/`);
75+
76+
- `[...]`: matches any one of the enclosed characters;
77+
78+
- *regex*: match with regular expressions;
79+
80+
- *mode*: how to compare against a pre-defined list:
81+
82+
- *blacklist*: input filenames matching any pattern on the list are
83+
skipped; others are deleted;
84+
85+
- *whitelist*: input filenames matching any pattern on the list are
86+
deleted; others are skipped;
87+
88+
- *blacklist*: blacklist file path; a leading tilde `~` is translated to home
89+
dir of current user;
90+
91+
- *whitelist*: whitelist file path; a leading tilde `~` is translated to home
92+
dir of current user;
93+
94+
### blacklist and whitelist
95+
96+
blacklist and whitelist have the same format: each line specifies a pattern; a
97+
leading tilde `~` in the pattern is translated to home dir of current user;
98+
99+
each input filename is first converted to realpath (without symlink expansion),
100+
then compared with these patterns one by one, until a match is found or no match
101+
is found; therefore, when you are writing patterns, expect them to be matched
102+
against realpaths;
103+
104+
## depend
105+
106+
this implementation depends on [go][] and its standard library (1.18 or newer);
107+
108+
## license
109+
110+
Copyright (C) 2018-2022 Cyker Way
111+
112+
This program is free software: you can redistribute it and/or modify it under
113+
the terms of the GNU General Public License as published by the Free Software
114+
Foundation, either version 3 of the License, or (at your option) any later
115+
version.
116+
117+
This program is distributed in the hope that it will be useful, but WITHOUT ANY
118+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
119+
PARTICULAR PURPOSE. See the GNU General Public License for more details.
120+
121+
You should have received a copy of the GNU General Public License along with
122+
this program. If not, see <https://www.gnu.org/licenses/>.
123+
124+
[go]: https://go.dev/

go/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module skiprm
2+
3+
go 1.18

0 commit comments

Comments
 (0)