From 7033aa65a04e14e9f7c3ba01de47215d5866d421 Mon Sep 17 00:00:00 2001 From: home Date: Thu, 30 Nov 2023 04:53:57 +0300 Subject: [PATCH] archive : CamelCase for archive name. --- .README.md | 8 ++++++++ .config/bash/module/archive.sh | 12 ++++++++---- .config/bash/module/parse.sh | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/.README.md b/.README.md index 0250a7e..23c2d23 100644 --- a/.README.md +++ b/.README.md @@ -586,6 +586,14 @@ Command|Description `pack [FILES]`|Create desired file format from other files. `unpack [FILES]`|Attempt to extract file content. +## Parse. + +Command|Description +---|--- +`parse_simplify `|Return simplified string: only alnum, underscores and dashes. +`parse_camel `|Return simplified CamelCase string. +`parse_alnum `|Return string containing only alphanumeric characters. + ## Permissions. Command|Description diff --git a/.config/bash/module/archive.sh b/.config/bash/module/archive.sh index 4bf0456..8f4276e 100644 --- a/.config/bash/module/archive.sh +++ b/.config/bash/module/archive.sh @@ -30,11 +30,13 @@ archive() local status="[${count}/${total}] ${target}" echo -e "${status}" + local name=$(parse_camel "${target}") + # create archive. - tar -c "${target}" | pv -s $(du -sb "${target}" | awk '{print $1}') | xz -9e > "${target%/*}".txz + tar -c "${target}" | pv -s $(du -sb "${target}" | awk '{print $1}') | xz -9e > "${name}".txz # append hash to target name. - mv "${target%/*}".txz "${target%/*}"_${date}-$(pv "${target%/*}".txz | sha1sum | cut -d\ -f1).txz + mv "${name}".txz "${name}"_${date}-$(pv "${name}".txz | sha1sum | cut -d\ -f1).txz # Show error. if [[ ${?} != 0 ]]; then @@ -76,11 +78,13 @@ archive_fast() local status="[${count}/${total}] ${target}" echo -e "${status}" + local name=$(parse_camel "${target}") + # create archive. - tar -c "${target}" | pv -s $(du -sb "${target}" | awk '{print $1}') | gzip -1 > "${target%/*}".tgz + tar -c "${target}" | pv -s $(du -sb "${target}" | awk '{print $1}') | gzip -1 > "${name}".tgz # append hash to target name. - mv "${target%/*}".tgz "${target%/*}"_${date}-$(pv "${target%/*}".tgz | sha1sum | cut -d\ -f1).tgz + mv "${name}".tgz "${name}"_${date}-$(pv "${name}".tgz | sha1sum | cut -d\ -f1).tgz # Show error. if [[ $? != 0 ]]; then diff --git a/.config/bash/module/parse.sh b/.config/bash/module/parse.sh index 41d9554..9b5c1af 100644 --- a/.config/bash/module/parse.sh +++ b/.config/bash/module/parse.sh @@ -11,6 +11,20 @@ parse_simplify() -e "s/^_//" -e "s/_$//" } +parse_camel() +{ + local IFS=${IFS}_- + local parts=($(parse_simplify ${1})) + local result + + for part in "${parts[@]}"; do + local word="${part^}" + result="${result}${word}" + done + + echo "${result}" +} + # parse data keeping only alphanumeric characters. # usage: parse_alnum parse_alnum()