Compare commits
3 Commits
5519535b5d
...
e4c14e3eef
Author | SHA1 | Date | |
---|---|---|---|
e4c14e3eef | |||
8e55fde92b | |||
0e65c66a6f |
12
.drone.yml
12
.drone.yml
@ -67,4 +67,14 @@ steps:
|
|||||||
- ls -la $HOME/.trash/
|
- ls -la $HOME/.trash/
|
||||||
- trash_rm testfile2 testfile3
|
- trash_rm testfile2 testfile3
|
||||||
- trash_list
|
- trash_list
|
||||||
- ls -la $HOME/.trash/
|
- ls -la $HOME/.trash/
|
||||||
|
|
||||||
|
- name: test usage
|
||||||
|
depends_on:
|
||||||
|
- install
|
||||||
|
- test trash_restore
|
||||||
|
image: bash:latest
|
||||||
|
pull: if-not-exists
|
||||||
|
commands:
|
||||||
|
- . $HOME/.bashrc
|
||||||
|
- trash || true
|
@ -3,17 +3,18 @@
|
|||||||
[![Build Status](https://drone.pyas.de/api/badges/Kim/trash/status.svg)](https://drone.pyas.de/Kim/trash)
|
[![Build Status](https://drone.pyas.de/api/badges/Kim/trash/status.svg)](https://drone.pyas.de/Kim/trash)
|
||||||
|
|
||||||
## Installation:
|
## Installation:
|
||||||
Place the file in your desired path and it in your $HOME/.bashrc or in /etc/.bashrc:
|
the trash.sh file in your desired path and source it in your $HOME/.bashrc or in /etc/.bashrc:
|
||||||
|
|
||||||
. /path/to/trash.sh
|
. /path/to/trash.sh
|
||||||
|
|
||||||
|
- As the Script runs it first checks if $HOME/.trash/ (your trash bin) in your home dir exists and creates it if missing.
|
||||||
|
|
||||||
Add cleanup job to your cron:
|
Add cleanup job to your cron:
|
||||||
|
|
||||||
# .trash cleanup of all contents (files and dirs) older than 31 days every morning at 06:00
|
# .trash cleanup of all contents (files and dirs) older than 31 days every morning at 06:00
|
||||||
0 6 * * 0 find /home/YOURHOME/.trash/ -mtime +31 -delete
|
0 6 * * 0 find /home/YOURHOME/.trash/ -mtime +31 -delete
|
||||||
|
|
||||||
## Usage:
|
## Usage:
|
||||||
As the Script runs it first checks if $HOME/.trash/ (your trash bin) in your home dir exists and creates it if missing.
|
|
||||||
|
|
||||||
- `trash FILE1 DIR2 ...` or `trash_put FILE1 DIR2 ...` to move files and directories with relative or absolute paths to your .trash
|
- `trash FILE1 DIR2 ...` or `trash_put FILE1 DIR2 ...` to move files and directories with relative or absolute paths to your .trash
|
||||||
- `trash_list` to list all files and dirs that you put in the trash in the last 30 days
|
- `trash_list` to list all files and dirs that you put in the trash in the last 30 days
|
||||||
|
14
trash.sh
14
trash.sh
@ -7,11 +7,20 @@ TRASH_DIR="$HOME"/.trash
|
|||||||
FILE_PATHS_FILE="$TRASH_DIR/.filepaths"
|
FILE_PATHS_FILE="$TRASH_DIR/.filepaths"
|
||||||
[ ! -f "$FILE_PATHS_FILE" ] && touch "$FILE_PATHS_FILE"
|
[ ! -f "$FILE_PATHS_FILE" ] && touch "$FILE_PATHS_FILE"
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
local func_args=$1
|
||||||
|
local func_name="$2"
|
||||||
|
|
||||||
|
if [[ $func_args == 0 ]]; then echo -e "At least one argument required:\n$func_name FILE1 DIR2 ..."; return 1; fi
|
||||||
|
}
|
||||||
|
|
||||||
trash_list() {
|
trash_list() {
|
||||||
find "$TRASH_DIR" ! -name ".filepaths" | tail -n +2
|
find "$TRASH_DIR" ! -name ".filepaths" | tail -n +2
|
||||||
}
|
}
|
||||||
|
|
||||||
trash_put() {
|
trash_put() {
|
||||||
|
usage "$#" "$0"
|
||||||
|
|
||||||
for FILE in $@; do
|
for FILE in $@; do
|
||||||
# Store old filepath for later restore
|
# Store old filepath for later restore
|
||||||
echo "$FILE $(readlink -f "$FILE")" >>"$FILE_PATHS_FILE"
|
echo "$FILE $(readlink -f "$FILE")" >>"$FILE_PATHS_FILE"
|
||||||
@ -25,6 +34,8 @@ trash_empty() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
trash_restore() {
|
trash_restore() {
|
||||||
|
usage "$#" "$0"
|
||||||
|
|
||||||
for FILE_TO_RESTORE in "$@"; do
|
for FILE_TO_RESTORE in "$@"; do
|
||||||
# Get old filepath for restore
|
# Get old filepath for restore
|
||||||
OLD_PATH=$(grep "$FILE_TO_RESTORE" "$FILE_PATHS_FILE" | cut -d ' ' -f2)
|
OLD_PATH=$(grep "$FILE_TO_RESTORE" "$FILE_PATHS_FILE" | cut -d ' ' -f2)
|
||||||
@ -38,6 +49,9 @@ trash_restore() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
trash_rm() {
|
trash_rm() {
|
||||||
|
usage "$#" "$0"
|
||||||
|
#if [[ $# == 0 ]]; then echo -e "At least one argument required:\n$0 FILE1 DIR2 ..."; return 1; fi
|
||||||
|
|
||||||
for FILE_TO_REMOVE in "$@"; do
|
for FILE_TO_REMOVE in "$@"; do
|
||||||
if ! echo "$FILE_TO_REMOVE" | grep "$HOME/.trash"
|
if ! echo "$FILE_TO_REMOVE" | grep "$HOME/.trash"
|
||||||
then FILEPATH_TO_REMOVE="$HOME/.trash/$FILE_TO_REMOVE"
|
then FILEPATH_TO_REMOVE="$HOME/.trash/$FILE_TO_REMOVE"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user