bash : add archive_rename to rename archives.

This commit is contained in:
Dmitry Voronin 2023-10-29 20:47:01 +03:00
parent 904edf910d
commit 644b335458

View file

@ -146,6 +146,31 @@ unarchive()
done
}
# rename archive.
# usage: archive_rename [ARCHIVE] [NAME]
archive_rename()
{
# get params.
local target="${1}"
local name="${2}"
# check params.
if [[ "${target}" = "" || "${name}" = "" ]]; then
echo "usage: archive_rename [ARCHIVE] [NAME]"
return 1
fi
# remove old name.
local data="${target##*_}"
local new_name="${name}_${data}"
# prepare status.
local status="${target} -> ${new_name}"
# rename.
mv -- "${target}" "${new_name}" && echo "${status}" || echo -e "${color_red}${status}: error.${color_default}"
}
# export everything, primarily for use with parallel..
export -f archive archive_fast archive_check unarchive