Compare commits

..

3 Commits

Author SHA1 Message Date
Kim
e4c14e3eef test usage
All checks were successful
continuous-integration/drone/push Build is passing
2021-09-21 21:06:22 +02:00
Kim
8e55fde92b add usage 2021-09-21 21:05:54 +02:00
Kim
0e65c66a6f Update README.md 2021-09-21 20:53:50 +02:00
3 changed files with 28 additions and 3 deletions

View File

@ -67,4 +67,14 @@ steps:
- ls -la $HOME/.trash/
- trash_rm testfile2 testfile3
- 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

View File

@ -3,17 +3,18 @@
[![Build Status](https://drone.pyas.de/api/badges/Kim/trash/status.svg)](https://drone.pyas.de/Kim/trash)
## 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
- 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:
# .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
## 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_list` to list all files and dirs that you put in the trash in the last 30 days

View File

@ -7,11 +7,20 @@ TRASH_DIR="$HOME"/.trash
FILE_PATHS_FILE="$TRASH_DIR/.filepaths"
[ ! -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() {
find "$TRASH_DIR" ! -name ".filepaths" | tail -n +2
}
trash_put() {
usage "$#" "$0"
for FILE in $@; do
# Store old filepath for later restore
echo "$FILE $(readlink -f "$FILE")" >>"$FILE_PATHS_FILE"
@ -25,6 +34,8 @@ trash_empty() {
}
trash_restore() {
usage "$#" "$0"
for FILE_TO_RESTORE in "$@"; do
# Get old filepath for restore
OLD_PATH=$(grep "$FILE_TO_RESTORE" "$FILE_PATHS_FILE" | cut -d ' ' -f2)
@ -38,6 +49,9 @@ trash_restore() {
}
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
if ! echo "$FILE_TO_REMOVE" | grep "$HOME/.trash"
then FILEPATH_TO_REMOVE="$HOME/.trash/$FILE_TO_REMOVE"