Name : Skip archives when simplifying names.
This commit is contained in:
parent
c00fdc84b4
commit
d1774fa6cb
|
@ -267,6 +267,13 @@ function _archive_date() {
|
|||
date +%Y%m%d%H%M
|
||||
}
|
||||
|
||||
# Check if file is an archive.
|
||||
function _is_archive() {
|
||||
local out=$(echo "${*}" | grep -E ${_archive_pattern})
|
||||
|
||||
[[ "${out}" != "" ]]
|
||||
}
|
||||
|
||||
complete -o filenames -F _archive_grep archive_check unarchive archive_rm
|
||||
complete -o filenames -F _archive_grep_fast archive_xz
|
||||
complete -o filenames -F _archive_name archive_name
|
||||
|
|
|
@ -75,7 +75,7 @@ function _checksum_check() {
|
|||
|
||||
# Compare values.
|
||||
if [[ "${stored}" != "${actual}" ]]; then
|
||||
echo -e "${color_bred}${file}: Failed.${color_default}"
|
||||
_error "${file}: Failed."
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
|
|
@ -1,3 +1,37 @@
|
|||
# Rename dirs to `snake_case` and files to `PascalCase`. Careful with structured file names like archives!
|
||||
# Usage: name [FILES]
|
||||
function name() {
|
||||
local IFS=$'\n'
|
||||
local targets=(${@})
|
||||
[[ "${targets}" = "" ]] && targets=($(ls))
|
||||
|
||||
process() {
|
||||
# Skip archive.
|
||||
if $(_is_archive ${target}); then
|
||||
_warn "File is an archive, skip."
|
||||
return 0
|
||||
fi
|
||||
|
||||
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[@]}
|
||||
}
|
||||
|
||||
# Rename files to strip all special characters.
|
||||
# All files by default.
|
||||
# Usage: name_simple [FILES]
|
||||
|
@ -7,6 +41,12 @@ function name_simple() {
|
|||
[[ "${targets}" = "" ]] && targets=([^.]*)
|
||||
|
||||
process() {
|
||||
# Skip archive.
|
||||
if $(_is_archive ${target}); then
|
||||
_warn "File is an archive, skip."
|
||||
return 0
|
||||
fi
|
||||
|
||||
# parse new name.
|
||||
local ext=""
|
||||
local name="${target}"
|
||||
|
@ -314,30 +354,3 @@ 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 [FILES]
|
||||
function name() {
|
||||
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[@]}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ function _iterate_targets() {
|
|||
|
||||
# status info.
|
||||
local status="[${count}/${total}] ${target}"
|
||||
echo -e "${color_bwhite}${status}${color_default}"
|
||||
_info "${status}"
|
||||
|
||||
# Call function.
|
||||
${foo} "${target}"
|
||||
|
@ -43,7 +43,7 @@ function _iterate_targets() {
|
|||
# Show error.
|
||||
if [[ ${?} != 0 ]]; then
|
||||
((failed++))
|
||||
echo -e "${color_bred}${status}: Failed.${color_default}"
|
||||
_error "${status}: Failed."
|
||||
fi
|
||||
|
||||
# Add newline if not the last one.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
function vdl() {
|
||||
# Check that ffmpeg and ffprobe are available.
|
||||
if [[ "$(ffmpeg -version)" = "" ]] || [[ "$(ffprobe -version)" = "" ]]; then
|
||||
echo -e "${color_red}ffmpeg and ffprobe are required.${color_default}"
|
||||
_error "ffmpeg and ffprobe are required."
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
@ -14,7 +14,7 @@ function vdl() {
|
|||
|
||||
# If could not get [LINK] eventually, show an error and exit.
|
||||
if [[ "${target}" = "" ]]; then
|
||||
echo -e "${color_red}Could not determine [LINK] to download.${color_default}"
|
||||
_error "Could not determine [LINK] to download."
|
||||
help vdl
|
||||
return 2
|
||||
fi
|
||||
|
|
Reference in a new issue