summaryrefslogtreecommitdiff
path: root/backomp
diff options
context:
space:
mode:
Diffstat (limited to 'backomp')
-rwxr-xr-xbackomp19
1 files changed, 13 insertions, 6 deletions
diff --git a/backomp b/backomp
index aba6450..2aa873d 100755
--- a/backomp
+++ b/backomp
@@ -6,8 +6,8 @@ set -e
function flr(n, s) { return int(n / s) * s }
BEGIN {
- split("h d w m", arr)
- for (i = 1; i <= length(arr); ++i) {
+ len = split("h d w m", arr)
+ for (i = 1; i <= len; ++i) {
b = arr[i]
if (!match(retain, "([*0-9]+)" b, md))
@@ -64,8 +64,8 @@ run() {
backup() {
dest_dir="${1}"
src_path="${2}"
- retain="${3:-"*h*d*w*m"}"
- replace="${4:-"h"}"
+ retain="${3}"
+ replace="${4}"
[[ "$((dcount++))" -ne 0 ]] && echo
echo "[${dcount}] [${retain}] ${src_path} => ${dest_dir}"
@@ -96,15 +96,22 @@ backup() {
printf 'kept %s\n' "${keep[@]}"
}
+declare -A def_opts=(
+ ['retain']='*h*d*w*m'
+ ['replace']='h'
+)
declare -A opts
+
while IFS='=' read -r f1 f2; do
[[ -z "${f1}" ]] && continue
if [[ "${f1}" =~ ^\[(.*)]$ ]]; then
base_path="${BASH_REMATCH[1]}"
- opts=()
+ opts="$(declare -p def_opts | sed '1s/[^=]*=//')"
elif [[ "${f1}" == '$'* ]]; then
- opts["${f1:1}"]="${f2}"
+ opt="${f1:1}"
+ [[ "${f2}" == '-' ]] && opts["${opt}"]= ||
+ opts["${opt}"]="${f2:-"${def_opts["${opt}"]}"}"
else
backup "${base_path}/${f1}" "${f2}" \
"${opts['retain']}" "${opts['replace']}"