Compare commits
No commits in common. "e4c14e3eefa2d89ec673245b07fa20b08b239e12" and "5519535b5da3d889471336baa47b7a14fd51709c" have entirely different histories.
e4c14e3eef
...
5519535b5d
10
.drone.yml
10
.drone.yml
@ -68,13 +68,3 @@ steps:
|
|||||||
- 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,18 +3,17 @@
|
|||||||
[![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:
|
||||||
the trash.sh file in your desired path and source it in your $HOME/.bashrc or in /etc/.bashrc:
|
Place the file in your desired path and 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,20 +7,11 @@ 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"
|
||||||
@ -34,8 +25,6 @@ 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)
|
||||||
@ -49,9 +38,6 @@ 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