Compare commits

..

No commits in common. "e4c14e3eefa2d89ec673245b07fa20b08b239e12" and "5519535b5da3d889471336baa47b7a14fd51709c" have entirely different histories.

3 changed files with 3 additions and 28 deletions

View File

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

View File

@ -3,18 +3,17 @@
[![Build Status](https://drone.pyas.de/api/badges/Kim/trash/status.svg)](https://drone.pyas.de/Kim/trash)
## 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
- 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,20 +7,11 @@ 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"
@ -34,8 +25,6 @@ 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)
@ -49,9 +38,6 @@ 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"