safe-rm 1.0.8 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintignore ADDED
@@ -0,0 +1,2 @@
1
+ /*
2
+ !/test
package/.eslintrc.js ADDED
@@ -0,0 +1,9 @@
1
+ const OFF = 'off'
2
+
3
+ module.exports = {
4
+ extends: require.resolve('@ostai/eslint-config'),
5
+ rules: {
6
+ 'prefer-object-spread': OFF,
7
+ 'import/no-unresolved': OFF
8
+ }
9
+ }
@@ -0,0 +1,27 @@
1
+ name: build
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ strategy:
8
+ matrix:
9
+ os: [ubuntu-latest, macos-latest]
10
+ node-version: [20.x]
11
+
12
+ runs-on: ${{ matrix.os }}
13
+
14
+ steps:
15
+ - uses: actions/checkout@v1
16
+ - name: Use Node.js ${{ matrix.node-version }}
17
+ uses: actions/setup-node@v1
18
+ with:
19
+ node-version: ${{ matrix.node-version }}
20
+ - name: npm install, build, and test
21
+ run: |
22
+ uname -a
23
+ npm install
24
+ npm run build --if-present
25
+ npm run test:dev
26
+ env:
27
+ CI: true
@@ -0,0 +1,35 @@
1
+ #!/bin/bash
2
+
3
+ # This is a sample configuration file for safe-rm.
4
+ # By default, you could copy this file to ~/.safe-rm/config
5
+
6
+ #
7
+ # If you want to use a trash directory other than the default system trash,
8
+ # uncomment the line after divider `-----`
9
+ # and set the path to the desired trash directory.
10
+ # By default, safe-rm will use the system trash.
11
+ # -----------------------------------------------
12
+ # export SAFE_RM_TRASH=/path/to/trash
13
+
14
+ #
15
+ # If you want to permanently delete files that are already in the trash,
16
+ # uncomment the line after divider `-----`
17
+ # It defaults to 'no'.
18
+ # Pay attention that any value that starts with 'y' or 'Y' will be treated as 'yes'.
19
+ # -----------------------------------------------
20
+ # export SAFE_RM_PERM_DEL_FILES_IN_TRASH=yes
21
+
22
+ #
23
+ # If you want to disable the use of AppleScript for moving files to the trash,
24
+ # uncomment the line after divider `-----`
25
+ # It defaults to 'yes'.
26
+ # By setting it to 'no', the "put-back" feature will be disabled for MacOS.
27
+ # -----------------------------------------------
28
+ # export SAFE_RM_USE_APPLESCRIPT=no
29
+
30
+ #
31
+ # If you want to change the configuration root directory of safe-rm, in order to
32
+ # - put the .gitignore file in a different directory other than `~/.safe-rm/`
33
+ # Uncomment the line after divider `-----`
34
+ # -----------------------------------------------
35
+ # export SAFE_RM_CONFIG_ROOT=/usr/local/etc/safe-rm
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ # safe-rm
2
+
1
3
  ```
2
4
  _______ _______ _______ _______ ______ __ __
3
5
  | || _ || || | | _ | | |_| |
@@ -8,31 +10,36 @@
8
10
  |_______||__| |__||___| |_______| |___| |_||_| |_|
9
11
  ```
10
12
 
11
- A much safer replacement of bash `rm` with **ALMOST FULL** features of the origin `rm` command.
13
+ [![Build Status](https://github.com/kaelzhang/shell-safe-rm/actions/workflows/nodejs.yml/badge.svg)](https://github.com/kaelzhang/shell-safe-rm/actions/workflows/nodejs.yml)
12
14
 
13
- Initially developed on Mac OS X, then tested on Linux.
15
+ [Safe-rm][safe-rm], a drop-in and much safer replacement of the unix [`rm`][rm] command with **ALMOST FULL** features of the original [`rm`][rm].
14
16
 
15
- Using `safe-rm`, the files or directories you choose to remove will move to `$HOME/.Trash` instead of simply deleting them. You could put them back whenever you want manually.
17
+ The project was initially developed for Mac OS X, and then tested on Linux.
16
18
 
17
- If a file or directory with the same name already exists in the Trash, the name of newly-deleted items will be ended with the current date and time.
19
+ ## Features
20
+ - Supports both MacOS and Linux with full test coverage.
21
+ - Using `safe-rm`, the files or directories you choose to remove will be moved to the system Trash instead of simply deleting them. You could put them back whenever you want manually.
22
+ - On MacOS, `safe-rm` will use [AppleScript][applescript] to delete files or directories as much as possible to enable the built-in "put-back" capability in the system Trash bin.
23
+ - On Linux, it also follows the operating system's conventions for handling duplicate files in the Trash to avoid overwriting
24
+ - Supports Custom [configurations](#configuration).
18
25
 
19
26
  ## Supported options
20
27
 
21
- For those implemented options, safe-rm will act **exactly the same** as the original `rm` command
22
-
23
- `-i`, `--interactive`
24
-
25
- `-f`, `--force`
26
-
27
- `-r`, `-R`, `--recursive`, `--Recursive`
28
+ For those implemented options, safe-rm will act **exactly the same** as the original `rm` command:
28
29
 
29
- `-v`, `--verbose`
30
-
31
- `--`
30
+ | Option | Brief | Description |
31
+ | ------ | ----- | ------------ |
32
+ | `-i`, `--interactive` | **Interactive** | Prompts you to confirm before removing each file |
33
+ | `-I`, `--interactive=once` | **Less Interactive** | Prompts only once before removing more than three files or when recursively removing directories |
34
+ | `-f`, `--force` | **Force** | Removes files without prompting for confirmation, ignoring nonexistent files and overriding file protections |
35
+ | `-r`, `-R`, `--recursive`, `--Recursive` | **Recursive** | Removes directories and their contents recursively. Required for deleting directories |
36
+ | `-v`, `--verbose` | **Verbose** | Displays detailed information about each file or directory being removed |
37
+ | `-d`, '--directory' | **Remove Empty Directories** | `safe-rm` can check and only remove empty directories specifically with this flag |
38
+ | `--` | **End of Options** | Used to indicate the end of options. Useful if a filename starts with a `-` |
32
39
 
33
40
  Combined short options are also supported, such as
34
41
 
35
- `-rf`, `-riv`, etc
42
+ `-rf`, `-riv`, `-rfv`, etc
36
43
 
37
44
  ## Usual Installation
38
45
 
@@ -46,22 +53,22 @@ and `/path/to` is where you git clone `shell-safe-rm` in your local machine.
46
53
 
47
54
  ## Permanent Installation
48
55
 
49
- If you have NPM (node) installed (RECOMMENDED):
56
+ If you have NPM ([NodeJS](https://nodejs.org/)) installed (RECOMMENDED):
50
57
 
51
58
  ```sh
52
59
  npm i -g safe-rm
53
60
  ```
54
61
 
55
- Or normally with `make`:
62
+ Or by using the source code, within the root of the current repo (not recommended, may be unstable):
56
63
 
57
64
  ```sh
58
- make && sudo make install
59
- # and enjoy
60
- ```
65
+ # If you have NodeJS installed
66
+ npm link
61
67
 
62
- For those who have no `make` command:
68
+ # If you don't have NodeJS or npm installed
69
+ make && sudo make install
63
70
 
64
- ```sh
71
+ # For those who have no `make` command:
65
72
  sudo sh install.sh
66
73
  ```
67
74
 
@@ -76,7 +83,7 @@ alias rm='safe-rm'
76
83
  After installation and alias definition, when you execute `rm` command in the Terminal, lines of below will be printed:
77
84
 
78
85
  ```sh
79
- > rm
86
+ $ rm
80
87
  safe-rm
81
88
  usage: rm [-f | -i] [-dPRrvW] file ...
82
89
  unlink file
@@ -86,7 +93,7 @@ which helps to tell safe-rm from the original rm.
86
93
 
87
94
  ## Uninstall
88
95
 
89
- First remove the `alias` line from your `~/.bashrc` file, then
96
+ First remove the `alias rm=...` line from your `~/.bashrc` file, then
90
97
 
91
98
  ```sh
92
99
  npm uninstall -g safe-rm
@@ -103,3 +110,91 @@ Or
103
110
  ```sh
104
111
  sudo sh uninstall.sh
105
112
  ```
113
+
114
+ # Advanced Sections
115
+
116
+ ## Configuration
117
+
118
+ Since 3.0.0, you could create a configuration file located at `~/.safe-rm/config` in your `$HOME` directory, to support
119
+ - defining your custom trash directory
120
+ - allowing `safe-rm` to permanently delete files and directories that are already in the trash
121
+ - disallowing `safe-rm` to use [AppleScript][applescript]
122
+
123
+ For the description of each config, you could refer to the sample file [here](./.safe-rm/config)
124
+
125
+ ```sh
126
+ # You could
127
+ cp -r ./.safe-rm ~/
128
+ ```
129
+
130
+ If you want to use a custom configuration file
131
+
132
+ ```sh
133
+ alias="SAFE_RM_CONFIG=/path/to/safe-rm.conf /path/to/shell-safe-rm/bin/rm.sh"
134
+ ```
135
+
136
+ Or if it is installed by npm:
137
+
138
+ ```sh
139
+ alias="SAFE_RM_CONFIG=/path/to/safe-rm.conf safe-rm"
140
+ ```
141
+
142
+ ### Disable `Put-back` Functionality on MacOS (MacOS only)
143
+
144
+ In `~/.safe-rm/config`
145
+
146
+ ```sh
147
+ export SAFE_RM_USE_APPLESCRIPT=no
148
+ ```
149
+
150
+ ### Change the Default Trach Bin Other Than System Default
151
+
152
+ ```sh
153
+ export SAFE_RM_TRASH=/path/to/trash
154
+ ```
155
+
156
+ ### Permanent Delete Files or Directories that Are Already in the Trash
157
+
158
+ ```sh
159
+ export SAFE_RM_PERM_DEL_FILES_IN_TRASH=yes
160
+ ```
161
+
162
+ ### Protect Files And Directories From Deleting
163
+
164
+ If you want to protect some certain files or directories from deleting by mistake, you could create a `.gitignore` file under the `"~/.safe-rm/"` directory, you could write [.gitignore rules](https://git-scm.com/docs/gitignore) inside the file.
165
+
166
+ If a path is matched by the rules that defined in `~/.safe-rm/.gitignore`, the path will be protected and could not be deleted by `safe-rm`
167
+
168
+ For example, in the `~/.safe-rm/.gitignore`
169
+
170
+ ```.gitignore
171
+ /path/to/be/protected
172
+ ```
173
+
174
+ And when executing
175
+
176
+ ```sh
177
+ $ safe-rm /path/to/be/protected # or
178
+ $ safe-rm /path/to/be/protected/foo # or
179
+ $ safe-rm -rf /path/to/be/protected/bar
180
+
181
+ # An error will occur
182
+ ```
183
+
184
+ But pay attention that, by adding the protected pattern above, if we:
185
+
186
+ ```sh
187
+ $ safe-rm -rf /path/to
188
+ ```
189
+
190
+ To keep the performance of `safe-rm` and avoid conducting unnecessary file system traversing, this would not prevent `/path/to/be/protected/foo` from removing.
191
+
192
+ Pay **ATTENTION** that:
193
+ - Before adding protected rules, i.e. placing the `.gitignore` inside the `"~/.safe-rm/"` directory, it requires `git` to be installed in your environment
194
+ - The protected rules file applies to the root directory (/), which This means that the patterns defined within it need to be relative to the root directory.
195
+ - Avoid adding `/` in the protected rules file, or everything will be protected
196
+
197
+
198
+ [applescript]: https://en.wikipedia.org/wiki/AppleScript
199
+ [rm]: https://en.wikipedia.org/wiki/Rm_(Unix)
200
+ [safe-rm]: https://github.com/kaelzhang/shell-safe-rm