archive : Add archive_rm.

This commit is contained in:
Dmitry Voronin 2023-12-10 04:31:03 +03:00
parent e1d78bbe08
commit db41c5eb82
2 changed files with 59 additions and 17 deletions

View file

@ -368,6 +368,47 @@ function archive_convert() {
done
}
# Delete specified or all archive files.
# Usage: archive_rm [FILES]
function archive_rm() {
local IFS=$'\n'
local targets=("${@}")
local total=${#}
local count=0
local failed=0
# set dafult value to target all supported archives.
if [[ "${targets}" = "" ]]; then
targets=($(ls | grep -E ${_archive_pattern}))
total=${#targets[@]}
fi
# iterate each target.
for target in "${targets[@]}"; do
# increment counter.
((count++))
# status info.
local status="[${count}/${total}] ${target}"
echo -e "${status}"
# Delete archive.
rm -- "${target}"
# Show error.
if [[ ${?} != 0 ]]; then
((failed++))
echo -e "${color_bred}${status}: Failed.${color_default}"
fi
done
# Show error.
if [[ ${failed} != 0 ]]; then
echo -e "${color_bred}Failed: ${failed}.${color_default}"
false
fi
}
# Parse archive file name to get: name, date, hash and format.
# Usage: _archive_parse <FILENAME>
function _archive_parse() {
@ -414,5 +455,5 @@ function _archive_date() {
date +%Y%m%d%H%M
}
complete -o filenames -F _archive_grep archive_check unarchive
complete -o filenames -F _archive_grep archive_check unarchive archive_rm
complete -o filenames -F _archive_name archive_name

View file

@ -27,6 +27,7 @@ Command|Description
`unarchive [FILES]`|Extract previously created archive with checksum validation.
`archive_name [ARCHIVE] [NAME]`|Rename archives. If no name specified, it simplifies archive's name. If no archives specified, apply to all archives.
`archive_convert`|Convert old archives to a new format. *TODO: remove me after some time when there won't be any old archives.*
`archive_rm [FILES]`|Delete specified or all archive files.
## Battery.
@ -107,12 +108,6 @@ Command|Description
`df`|Show only physical drives info.
`du [DIRS]`|Show combined size in SI. Current dir by default.
## Doc.
Command|Description
---|---
`doc_bash`|Generate a markdown file with all the help info. Outputs to `~/.doc/bash.md`.
## Docker.
Command|Description
@ -133,6 +128,12 @@ Command|Description
`dcpu [SERVICES]`|Docker compose pull & up specified services.
`dcul [SERVICES]`|Docker compose up & attach to logs for specified services.
## Doc.
Command|Description
---|---
`doc_bash`|Generate a markdown file with all the help info. Outputs to `~/.doc/bash.md`.
## Ffmpeg.
Command|Description
@ -268,7 +269,7 @@ Command|Description
Command|Description
---|---
`ps <PROCESS>`|Find process and filter.
`ps [PROCESS]`|Find process and filter.
## Recursive.
@ -344,7 +345,7 @@ Command|Description
Command|Description
---|---
`vdl [LINK]`|Download video from URL. When no [LINK] specified, it tries to update previously downloaded link.
`vdl [LINK]`|Download video from URL. When no `[LINK]` specified, it tries to update previously downloaded link.
`vdl_vk <LINK>`|Temporary fix for vk downloads.
`vdl_file <FILE>`|Download all videos from file with links.