Name : add convention conversion.

This commit is contained in:
Dmitry Voronin 2023-12-17 23:46:41 +03:00
parent d6b7f08e13
commit ec1c3f5c39
3 changed files with 43 additions and 3 deletions

View file

@ -13,7 +13,7 @@ function archive() {
local date=$(_archive_date)
# Parse name.
local name=$(parse_camel ${target})
local name=$(parse_pascal ${target})
# create archive.
local hash=$(tar -c ${target} | pv -s $(/usr/bin/du -sb ${target} | awk '{print $1}') | xz -9e | tee ${name}.txz | sha1sum | cut -d\ -f1)
@ -39,7 +39,7 @@ function archive_fast() {
local date=$(_archive_date)
# Parse name.
local name=$(parse_camel "${target}")
local name=$(parse_pascal "${target}")
# create archive.
local hash=$(tar -c "${target}" | pv -s $(/usr/bin/du -sb "${target}" | awk '{print $1}') | gzip -1 | tee "${name}".tgz | sha1sum | cut -d\ -f1)
@ -159,7 +159,7 @@ function archive_name() {
# simplify name by default.
if [[ "${name}" = "" || ${count} -gt 1 ]]; then
name="${target%_*}"
name="$(parse_camel ${name})"
name="$(parse_pascal ${name})"
fi
# remove old name.

View file

@ -313,3 +313,31 @@ function name_fix_numbering() {
_iterate_targets process ${targets[@]}
}
# Rename dirs to `snake_case` and files to `PascalCase`. Careful with structured file names like archives!
# Usage: name_convention [FILES]
function name_convention() {
local IFS=$'\n'
local targets=(${@})
[[ "${targets}" = "" ]] && targets=($(ls))
process() {
if [[ -d "${target}" ]]; then
local new_name=$(parse_snake ${target})
[[ -e "${new_name}" ]] && return 0
mv -- ${target} ${new_name} && echo ${new_name}
else
local ext=".${target##*.}"
local name=${target%.*}
[[ "${ext}" = ".${target}" ]] && ext=""
local new_name="$(parse_pascal ${name})${ext}"
[[ -e "${new_name}" ]] && return 0
mv -- ${target} ${new_name} && echo ${new_name}
fi
}
_iterate_targets process ${targets[@]}
}

View file

@ -17,6 +17,12 @@ function parse_pascal() {
local parts=($(parse_simplify ${1}))
local result
# If already in Pascal.
if [[ "${#parts[@]}" = 1 ]]; then
echo "${parts[*]^}"
return 0
fi
for part in "${parts[@]}"; do
local word="${part,,}"
word="${word^}"
@ -63,6 +69,12 @@ function parse_camel() {
local parts=($(parse_simplify ${1}))
local result
# If already in camel.
if [[ "${#parts[@]}" = 1 ]]; then
echo "${parts[*],}"
return 0
fi
for part in "${parts[@]}"; do
local word="${part,,}"
word="${word^}"