Bash : Rename some private functions.

This commit is contained in:
Dmitry Voronin 2024-01-03 18:50:59 +03:00
parent 2fd9c70fd6
commit 249cb3cd69
6 changed files with 39 additions and 39 deletions

View file

@ -32,7 +32,7 @@ function checksum_check() {
local hashfile=".${target#./}.sha1"
# Skip if hash doesn't exist.
[[ -f "${hashfile}" ]] || { _skip "No hash found."; return 0; }
[[ -f "${hashfile}" ]] || { _iterate_skip "No hash found."; return 0; }
# Calculate hash.
local stored=$(cat "${hashfile}" | cut -d\ -f1)

View file

@ -7,8 +7,8 @@ function group_ext() {
process() {
local ext=${target##*.}
[[ -d "${target}" ]] && { _skip "Is a directory."; return 0; }
[[ "${ext}" = "${target}" ]] && { _skip "No extension."; return 0; }
[[ -d "${target}" ]] && { _iterate_skip "Is a directory."; return 0; }
[[ "${ext}" = "${target}" ]] && { _iterate_skip "No extension."; return 0; }
mkdir ${ext} 2> /dev/null

View file

@ -313,7 +313,7 @@ function name_fix_numbering() {
# Check that starts with a digit.
[[ "${target}" =~ ^[0-9] ]] || continue
local digits=($(_parse_ints "${target}"))
local digits=($(parse_ints "${target}"))
local digit="${digits[0]}"
digit=$((10#${digit}))
@ -334,7 +334,7 @@ function name_fix_numbering() {
fi
# Prepare new name.
local digits=($(_parse_ints "${target}"))
local digits=($(parse_ints "${target}"))
local digit="${digits[0]}"
digit=$((10#${digit}))
local new_name=$(printf "%0${power}d" "${digit}")"${target#${digits[0]}}"

View file

@ -92,6 +92,11 @@ function parse_alnum() {
sed -e "s/[^[:alnum:]]//g"
}
# Parse integers from mixed string.
function parse_ints() {
echo "${*}" | tr '\n' ' ' | sed -e 's/[^0-9]/ /g' -e 's/^ *//g' -e 's/ *$//g' | tr -s ' ' | sed 's/ /\n/g'
}
# Get name parts.
# Usage: _get_parts <STRING>
function _get_parts() {

View file

@ -22,7 +22,7 @@ function transcode() {
output="${output%.*}.${to}"
# Skip if file exists.
[[ -f "${output}" ]] && { _skip "Already exists."; return 0; }
[[ -f "${output}" ]] && { _iterate_skip "Already exists."; return 0; }
# Support multiple inputs.
[[ "${to}" = "mp3" ]] && from=""

View file

@ -8,11 +8,6 @@ function _mem_free() {
free -m | sed -n -e '2p' | awk '{print $7}'
}
# Parse integers from mixed string.
function _parse_ints() {
echo "${*}" | tr '\n' ' ' | sed -e 's/[^0-9]/ /g' -e 's/^ *//g' -e 's/ *$//g' | tr -s ' ' | sed 's/ /\n/g'
}
# Function-wrapper to iterate with specified function with provided files.
# By default Iterates on all non-hidden files and directories.
# List of variables available to FUNCTION: target - current file, count - current item index, total - sum of targets, failed - count of previously failed items, skipped - count of skipped files, status - status line (not recommended to use).
@ -69,36 +64,36 @@ function _iterate_targets() {
fi
}
# Report an error to stdout.
# Always returns code 1.
# Usage: _error <MESSAGE>
function _error() {
echo -e "${color_bred}${*}${color_default}"
return 1
}
# Report a warning to stdout.
# Usage: _warn <MESSAGE>
function _warn() {
echo -e "${color_byellow}${*}${color_default}"
}
# Report a debug to stdout.
# Usage: _debug <MESSAGE>
function _debug() {
echo -e "${color_bwhite}${*}${color_default}"
}
# Report an info to stdout.
# Usage: _info <MESSAGE>
function _info() {
echo -e "${color_bwhite}${*}${color_default}"
}
# Skip current iteration.
# Usage: _skip [MESSAGE]
function _skip() {
# Usage: _iterate_skip [MESSAGE]
function _iterate_skip() {
((skipped++))
[[ "${*}" = "" ]] || echo -e "${color_byellow}${*}${color_default}"
}
# Report an error.
# Always returns code 1.
# Usage: _error <MESSAGE>
function _error() {
>&2 echo -e "${color_bred}${*}${color_default}"
return 1
}
# Report a warning.
# Usage: _warn <MESSAGE>
function _warn() {
>&2 echo -e "${color_byellow}${*}${color_default}"
}
# Report a debug.
# Usage: _debug <MESSAGE>
function _debug() {
>&2 echo -e "${color_bwhite}${*}${color_default}"
}
# Report an info.
# Usage: _info <MESSAGE>
function _info() {
>&2 echo -e "${color_bwhite}${*}${color_default}"
}