diff --git a/.config/bash/module/Checksum.sh b/.config/bash/module/Checksum.sh index 6b2ddd0..725d571 100644 --- a/.config/bash/module/Checksum.sh +++ b/.config/bash/module/Checksum.sh @@ -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) diff --git a/.config/bash/module/Group.sh b/.config/bash/module/Group.sh index 4209a20..e744cc0 100644 --- a/.config/bash/module/Group.sh +++ b/.config/bash/module/Group.sh @@ -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 diff --git a/.config/bash/module/Name.sh b/.config/bash/module/Name.sh index 3372fef..11a791a 100644 --- a/.config/bash/module/Name.sh +++ b/.config/bash/module/Name.sh @@ -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]}}" diff --git a/.config/bash/module/Parse.sh b/.config/bash/module/Parse.sh index 2efe6b8..d4bd7f1 100644 --- a/.config/bash/module/Parse.sh +++ b/.config/bash/module/Parse.sh @@ -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 function _get_parts() { diff --git a/.config/bash/module/Transcode.sh b/.config/bash/module/Transcode.sh index 043a4d0..6d4e82f 100644 --- a/.config/bash/module/Transcode.sh +++ b/.config/bash/module/Transcode.sh @@ -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="" diff --git a/.config/bash/module/Util.sh b/.config/bash/module/Util.sh index ac2a6d9..6eac2cb 100644 --- a/.config/bash/module/Util.sh +++ b/.config/bash/module/Util.sh @@ -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 -function _error() { - echo -e "${color_bred}${*}${color_default}" - return 1 -} - -# Report a warning to stdout. -# Usage: _warn -function _warn() { - echo -e "${color_byellow}${*}${color_default}" -} - -# Report a debug to stdout. -# Usage: _debug -function _debug() { - echo -e "${color_bwhite}${*}${color_default}" -} - -# Report an info to stdout. -# Usage: _info -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 +function _error() { + >&2 echo -e "${color_bred}${*}${color_default}" + return 1 +} + +# Report a warning. +# Usage: _warn +function _warn() { + >&2 echo -e "${color_byellow}${*}${color_default}" +} + +# Report a debug. +# Usage: _debug +function _debug() { + >&2 echo -e "${color_bwhite}${*}${color_default}" +} + +# Report an info. +# Usage: _info +function _info() { + >&2 echo -e "${color_bwhite}${*}${color_default}" +}