This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4634d72
Showing
6 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
name: Build | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
watch: | ||
types: [started] | ||
|
||
jobs: | ||
Build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: Private Actions Checkout | ||
uses: actions/checkout@v2 | ||
- | ||
name: set tag | ||
id: tagID | ||
run: echo "dir=$(date +'%Y.%m.%d.%H')" >> $GITHUB_OUTPUT | ||
- | ||
name: Build with xgo | ||
uses: crazy-max/ghaction-xgo@v2 | ||
with: | ||
xgo_version: latest | ||
go_version: ${{ matrix.go_version }} | ||
dest: bin | ||
prefix: rm | ||
targets: android/386, android/amd64, android/arm, android/arm64, darwin/amd64, darwin/arm64, freebsd/386, freebsd/amd64, freebsd/arm, freebsd/arm64, linux/386, linux/amd64, linux/arm, linux/arm64, linux/mips, linux/mips64, linux/mips64le, linux/mipsle, linux/ppc64, linux/ppc64le, linux/riscv64, linux/s390x, netbsd/386, netbsd/amd64, netbsd/arm, netbsd/arm64, openbsd/386, openbsd/amd64, openbsd/arm, openbsd/arm64, openbsd/mips64, windows/386, windows/amd64, windows/arm, windows/arm64 | ||
v: true | ||
x: true | ||
race: false | ||
ldflags: -s -w -X main.versionData=${{ steps.tagID.outputs.dir }} | ||
buildmode: default | ||
trimpath: true | ||
- | ||
name: Delete old Releases | ||
uses: dev-drprasad/[email protected] | ||
with: | ||
repo: ${{ github.repository }} | ||
keep_latest: 3 | ||
delete_tag_pattern: "" | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }} | ||
- | ||
name: Make release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
files: "bin/**" | ||
body_path: README.md | ||
name: ${{ steps.tagID.outputs.dir }} | ||
tag_name: ${{ steps.tagID.outputs.dir }} | ||
draft: false | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }} | ||
|
||
- | ||
name: Get Data | ||
id: getDingData | ||
run: | | ||
set -ex | ||
# 输出仓库名 | ||
REPOSITORY="${{GITHUB.REPOSITORY}}" | ||
echo "REPOSITORY=${REPOSITORY#*/}" >> $GITHUB_OUTPUT | ||
# 获取用户仓库信息 | ||
# RESPONSE="$(curl -sLm 10 https://api.github.com/repos/${{ GITHUB.REPOSITORY }})" | ||
# 建议填写自己的 TOKEN | ||
RESPONSE="$(curl -sLm 10 https://api.github.com/repos/${{ GITHUB.REPOSITORY }} -H "Authorization: token ${{ SECRETS.TOKEN_GITHUB }}")" | ||
# 获取 用户仓库 设置的 描述,如果为空,可能是没有使用 TOKEN | ||
DESCRIPTION="$(jq -r .description <(echo ${RESPONSE}))" | ||
echo "DESCRIPTION=${DESCRIPTION}" >> $GITHUB_OUTPUT | ||
# 获取 用户仓库 设置的 URL, 如果没有就输出 Github 地址 | ||
URL="$(jq -r .homepage <(echo ${RESPONSE}))" | ||
if [[ "${URL}" == "null" || "${URL}" == "" ]]; then | ||
echo "URL=${{ GITHUB.SERVER_URL }}/${{ GITHUB.REPOSITORY }}" >> $GITHUB_OUTPUT | ||
else | ||
echo "URL=${URL}" >> $GITHUB_OUTPUT | ||
fi | ||
- | ||
name: Send dingding notify | ||
uses: zcong1993/actions-ding@master | ||
with: | ||
dingToken: ${{ SECRETS.DING_TOKEN }} | ||
secret: ${{ SECRETS.DING_SECRET }} | ||
body: | | ||
{ | ||
"msgtype": "link", | ||
"link": { | ||
"text": "${{ steps.getDingData.outputs.DESCRIPTION }}", | ||
"title": "${{ steps.getDingData.outputs.REPOSITORY }} WorkFlow ${{ GITHUB.JOB }} Success!", | ||
"picUrl": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png", | ||
"messageUrl": "${{ steps.getDingData.outputs.URL }}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 XRSec | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# SAFE DELETE | ||
安全的删除文件/文件夹 | ||
|
||
## Example | ||
|
||
```bash | ||
# download rm_release_url and mv to C:\Windows\System32\rmf.exe | ||
|
||
# wget rm_release_url -O /usr/local/bin/rmf | ||
|
||
sudo chmod +x /usr/local/bin/rmf | ||
|
||
# ~/.zshrc | ||
alias rm="echo 'use rmf'; rmf" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module SAFE_DELETE | ||
|
||
go 1.18 | ||
|
||
require ( | ||
github.com/Bios-Marcel/wastebasket v0.0.0-20220303211447-66c8977d7e8c | ||
github.com/sirupsen/logrus v1.9.0 | ||
github.com/spf13/cobra v1.6.1 | ||
) | ||
|
||
require ( | ||
github.com/inconshreveable/mousetrap v1.0.1 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
github.com/Bios-Marcel/wastebasket v0.0.0-20220303211447-66c8977d7e8c h1:iL0ThOLtIYorYuu0vgkV5adV1j+ACBw/31t8WSnP2fo= | ||
github.com/Bios-Marcel/wastebasket v0.0.0-20220303211447-66c8977d7e8c/go.mod h1:cMUKObvy+ER0V39PI0lQpKiFZHn6XPwqNKY+Kzlbvbc= | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= | ||
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= | ||
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= | ||
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= | ||
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= | ||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= | ||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= | ||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= | ||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/Bios-Marcel/wastebasket" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var versionData string | ||
|
||
var rootCmd = &cobra.Command{ | ||
Short: "Safe Alternative System rm", | ||
Long: "Safe Alternative System rm", | ||
Version: versionData, | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
for _, v := range args { | ||
if _, err := os.Stat(v); err != nil { | ||
if os.IsNotExist(err) { | ||
log.Errorf("文件不存在: %s", v) | ||
continue | ||
} | ||
log.Infof("文件不存在? : %s", v) | ||
continue | ||
} | ||
|
||
if err := wastebasket.Trash(v); err != nil { | ||
log.Errorf("Error: %v", err) | ||
return | ||
} | ||
log.Infof("Success: %v", v) | ||
} | ||
}, | ||
Example: "rm -rfi [file1] [file2] [file3]", | ||
} | ||
|
||
func main() { | ||
var temp string | ||
rootCmd.Flags().StringVarP(&temp, "recursive", "r", "recursive", "which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in).") | ||
rootCmd.Flags().StringVarP(&temp, "force", "f", "force", "which ignores non-existent files and overrides any confirmation prompts (effectively canceling -i), although it will not remove files from a directory if the directory is write-protected.") | ||
rootCmd.Flags().StringVarP(&temp, "interactive", "i", "interactive", "which asks for every deletion to be confirmed.") | ||
rootCmd.Flags().StringVarP(&temp, "directory", "d", "directory", "which deletes an empty directory, and only works if the specified directory is empty.") | ||
rootCmd.Flags().StringVarP(&temp, "one-file-system", "", "one-file-system", "only removes files on the same file system as the argument, and will ignore mounted file systems.") | ||
if err := rootCmd.Execute(); err != nil { | ||
log.Errorf("Error: %v", err) | ||
} | ||
} |