functionusage(){ echo -e " Brief: move directory and files to ~/.local/trash Usage: alias rm=/path/to/saferm.sh rm <dir> rm <file> rm <file1> <file2> " }
functionmain(){ local now=$(date"+%Y%m%d%H%M%S") local destdir="${TRASHDIR}/${now}" mkdir${destdir}
local opt whilegetopts"h" opt do case$optin h) usage && exit 0 ;; \?) usage && exit 0 ;; esac done
local files="$*" local successfiles="" for file in${files};do mv${file}${destdir} && successfiles=${successfiles}" "${file} done if [[ -z "${successfiles}" ]];then echo -e "\033[31mNothing to do! Check the source filenames please!\033[0m" else echo -e "${successfiles} have been moved to \033[31m${destdir}\033[0m" fi }
functionusage(){ echo -e " Brief: Move directories or files to ~/.local/trash You can move 1-3 files with wildcard. More is unsupported. If file name contains space, use quotation mark please. Usage: alias rm=/path/to/saferm.sh rm <dir> rm <file> rm *.<filetype> rm <file1> <file2> <file3> " }
functionmain(){ local now=$(date"+%Y%m%d%H%M%S") local destdir="${TRASHDIR}/${now}" mkdir${destdir}
local opt whilegetopts"h" opt do case$optin h) usage && exit 0 ;; \?) usage && exit 0 ;; esac done
local file1="$1" local file2="$2" local file3="$3" local file4="$4" local successfiles="" [[ -n "${file1}" ]] && mv"${file1}"${destdir} && successfiles=${successfiles}" "${file1} [[ -n "${file2}" ]] && mv"${file2}"${destdir} && successfiles=${successfiles}" "${file2} [[ -n "${file3}" ]] && mv"${file3}"${destdir} && successfiles=${successfiles}" "${file3} [[ -n "${file4}" ]] && echo -e "\033[31mYou can move 1-3 files with wildcard. More is unsupported.\033[0m" if [[ -z "${successfiles}" ]];then echo -e "\033[31mNothing to do! Check the source filenames please!\033[0m" else echo -e "${successfiles} have been moved to \033[31m${destdir}\033[0m" fi }