Bash : Rename some private functions.
This commit is contained in:
parent
2fd9c70fd6
commit
249cb3cd69
|
@ -32,7 +32,7 @@ function checksum_check() {
|
||||||
local hashfile=".${target#./}.sha1"
|
local hashfile=".${target#./}.sha1"
|
||||||
|
|
||||||
# Skip if hash doesn't exist.
|
# 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.
|
# Calculate hash.
|
||||||
local stored=$(cat "${hashfile}" | cut -d\ -f1)
|
local stored=$(cat "${hashfile}" | cut -d\ -f1)
|
||||||
|
|
|
@ -7,8 +7,8 @@ function group_ext() {
|
||||||
|
|
||||||
process() {
|
process() {
|
||||||
local ext=${target##*.}
|
local ext=${target##*.}
|
||||||
[[ -d "${target}" ]] && { _skip "Is a directory."; return 0; }
|
[[ -d "${target}" ]] && { _iterate_skip "Is a directory."; return 0; }
|
||||||
[[ "${ext}" = "${target}" ]] && { _skip "No extension."; return 0; }
|
[[ "${ext}" = "${target}" ]] && { _iterate_skip "No extension."; return 0; }
|
||||||
|
|
||||||
mkdir ${ext} 2> /dev/null
|
mkdir ${ext} 2> /dev/null
|
||||||
|
|
||||||
|
|
|
@ -313,7 +313,7 @@ function name_fix_numbering() {
|
||||||
# Check that starts with a digit.
|
# Check that starts with a digit.
|
||||||
[[ "${target}" =~ ^[0-9] ]] || continue
|
[[ "${target}" =~ ^[0-9] ]] || continue
|
||||||
|
|
||||||
local digits=($(_parse_ints "${target}"))
|
local digits=($(parse_ints "${target}"))
|
||||||
local digit="${digits[0]}"
|
local digit="${digits[0]}"
|
||||||
digit=$((10#${digit}))
|
digit=$((10#${digit}))
|
||||||
|
|
||||||
|
@ -334,7 +334,7 @@ function name_fix_numbering() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Prepare new name.
|
# Prepare new name.
|
||||||
local digits=($(_parse_ints "${target}"))
|
local digits=($(parse_ints "${target}"))
|
||||||
local digit="${digits[0]}"
|
local digit="${digits[0]}"
|
||||||
digit=$((10#${digit}))
|
digit=$((10#${digit}))
|
||||||
local new_name=$(printf "%0${power}d" "${digit}")"${target#${digits[0]}}"
|
local new_name=$(printf "%0${power}d" "${digit}")"${target#${digits[0]}}"
|
||||||
|
|
|
@ -92,6 +92,11 @@ function parse_alnum() {
|
||||||
sed -e "s/[^[:alnum:]]//g"
|
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.
|
# Get name parts.
|
||||||
# Usage: _get_parts <STRING>
|
# Usage: _get_parts <STRING>
|
||||||
function _get_parts() {
|
function _get_parts() {
|
||||||
|
|
|
@ -22,7 +22,7 @@ function transcode() {
|
||||||
output="${output%.*}.${to}"
|
output="${output%.*}.${to}"
|
||||||
|
|
||||||
# Skip if file exists.
|
# Skip if file exists.
|
||||||
[[ -f "${output}" ]] && { _skip "Already exists."; return 0; }
|
[[ -f "${output}" ]] && { _iterate_skip "Already exists."; return 0; }
|
||||||
|
|
||||||
# Support multiple inputs.
|
# Support multiple inputs.
|
||||||
[[ "${to}" = "mp3" ]] && from=""
|
[[ "${to}" = "mp3" ]] && from=""
|
||||||
|
|
|
@ -8,11 +8,6 @@ function _mem_free() {
|
||||||
free -m | sed -n -e '2p' | awk '{print $7}'
|
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.
|
# Function-wrapper to iterate with specified function with provided files.
|
||||||
# By default Iterates on all non-hidden files and directories.
|
# 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).
|
# 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
|
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.
|
# Skip current iteration.
|
||||||
# Usage: _skip [MESSAGE]
|
# Usage: _iterate_skip [MESSAGE]
|
||||||
function _skip() {
|
function _iterate_skip() {
|
||||||
((skipped++))
|
((skipped++))
|
||||||
|
|
||||||
[[ "${*}" = "" ]] || echo -e "${color_byellow}${*}${color_default}"
|
[[ "${*}" = "" ]] || 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}"
|
||||||
|
}
|
||||||
|
|
Reference in a new issue