Skip to content

GasinAn/recycle-bin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 

Repository files navigation

recycle-bin

Simple and Stupid Linux Bash Recycle Bin

del() {
    while [ $# -gt 0 ]; do
        oldpath=$(realpath -s "$1")
        olddir=$(dirname "$oldpath")
        oldname=$(basename "$oldpath")
        newdir=~/.recycle_bin/$(date -I)
        newname=$(date -Ins)-"$oldname"
        mvbksh=$newdir/.mvbk."$newname".sh

        mkdir -p $newdir
        mv "$1" $newdir/"$newname"

        mvbksh_lines=(
            "#!/bin/bash"
            ""
            "set -e"
            ""
            "if [ -e '$olddir/$oldname' ]; then"
            "    echo '\"$olddir/$oldname\" exists!'"
            "    echo 'Fail to move back.'"
            "    exit 1"
            "fi"
            ""
            "mkdir -p '$olddir'"
            "mv '$newdir/$newname' '$olddir/$oldname'"
            "rm '$mvbksh'"
        )
        printf "%s\n" "${mvbksh_lines[@]}" > "$mvbksh"
        chmod u+x "$mvbksh"

        shift
    done
}

License

GLWT(Good Luck With That) Public License

About

Simple and Stupid Linux Bash Recycle Bin

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published