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()