archive : add prune to delete old versions.
This commit is contained in:
parent
3095485355
commit
3bc8f5b3b3
|
@ -316,6 +316,7 @@ Command|Description
|
|||
`archive_fast [FILES]`|Like normal `archive` but with minimal compression.
|
||||
`archive_check [ARCHIVES]`|Check specified archives or all archives in current directory.
|
||||
`archive_name [ARCHIVES] [NAME]`|Rename specified archive ro specified name or simplify name for specified archive or simplify names for all archives.
|
||||
`archive_prune [NAME]`|Delete old versions of an archive, or all archives by default.
|
||||
`unarchive [ARCHIVES]`|Check specified or all archives and extract if they are correct.
|
||||
|
||||
## Autocomplete.
|
||||
|
|
|
@ -124,6 +124,33 @@ archive_check()
|
|||
fi
|
||||
}
|
||||
|
||||
# Delete old versions of an archives.
|
||||
# Usage: archive_prune [NAME]
|
||||
archive_prune()
|
||||
{
|
||||
local targets=("${@}")
|
||||
local count=0
|
||||
local total=${#}
|
||||
|
||||
# All archives by default.
|
||||
if [[ "${target}" = "" ]]; then
|
||||
targets=($(ls | grep -E ${_ARCHIVE_PATTERN}))
|
||||
total=${#targets[@]}
|
||||
fi
|
||||
|
||||
# Iterate each target.
|
||||
for target in "${targets[@]}"; do
|
||||
# Only work with files.
|
||||
[[ -f "${target}" ]] || continue
|
||||
|
||||
# Iterate counter.
|
||||
((count++))
|
||||
|
||||
local name="${target%_*}"
|
||||
# local copies=("$()")
|
||||
done
|
||||
}
|
||||
|
||||
# extract previously created archive with checksum validation.
|
||||
# usage: unarchive [FILES]
|
||||
unarchive()
|
||||
|
@ -198,7 +225,7 @@ archive_name()
|
|||
|
||||
# iterate each target.
|
||||
for target in "${targets[@]}"; do
|
||||
# only work with targets.
|
||||
# only work with files.
|
||||
[[ -f "${target}" ]] || continue
|
||||
|
||||
# iterate counter.
|
||||
|
|
|
@ -8,7 +8,7 @@ checksum()
|
|||
|
||||
if [[ "$action" =~ ^(n|new)$ ]]; then
|
||||
# create checksums for all files.
|
||||
find -type f | parallel sha1sum {} > "$file"
|
||||
find -type f | parallel sha1sum {} >> "$file"
|
||||
|
||||
# remove checksum file from resulting hashes.
|
||||
sed -i "/$file/d" "$file"
|
||||
|
|
Reference in a new issue