2023-12-17 21:15:50 +03:00
|
|
|
# Group files by extension.
|
|
|
|
# Usage: group_ext [FILES]
|
|
|
|
function group_ext() {
|
|
|
|
local IFS=$'\n'
|
|
|
|
local targets=(${@})
|
|
|
|
[[ "${targets}" = "" ]] && targets=($(_ls_file))
|
|
|
|
|
|
|
|
process() {
|
|
|
|
local ext=${target##*.}
|
2024-01-03 18:50:59 +03:00
|
|
|
[[ -d "${target}" ]] && { _iterate_skip "Is a directory."; return 0; }
|
|
|
|
[[ "${ext}" = "${target}" ]] && { _iterate_skip "No extension."; return 0; }
|
2023-12-17 21:15:50 +03:00
|
|
|
|
|
|
|
mkdir ${ext} 2> /dev/null
|
|
|
|
|
|
|
|
mv -- ${target} ./${ext}/${target}
|
|
|
|
}
|
|
|
|
|
|
|
|
_iterate_targets process ${targets[@]}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Group files and dirs by year.
|
|
|
|
# Usage: group_year [FILES]
|
|
|
|
function group_year() {
|
|
|
|
local IFS=$'\n'
|
|
|
|
local targets=(${@})
|
|
|
|
[[ "${targets}" = "" ]] && targets=($(ls))
|
|
|
|
|
|
|
|
process() {
|
|
|
|
local year=$(stat --format=%y ${target})
|
|
|
|
year=${year%%-*}
|
|
|
|
|
|
|
|
mkdir ${year} 2> /dev/null
|
|
|
|
|
|
|
|
mv -- ${target} ./${year}/${target}
|
|
|
|
}
|
|
|
|
|
|
|
|
_iterate_targets process ${targets[@]}
|
|
|
|
}
|
2024-01-27 19:42:37 +03:00
|
|
|
|
|
|
|
# Copy files from current year to the named dir.
|
2024-02-12 01:52:37 +03:00
|
|
|
# Usage: group_year_copy <YEAR> [FILES]
|
|
|
|
function group_year_copy() {
|
2024-01-27 19:42:37 +03:00
|
|
|
local IFS=$'\n'
|
2024-02-12 01:52:37 +03:00
|
|
|
local selected_year="${1}"
|
|
|
|
local targets=(${@:2})
|
|
|
|
|
|
|
|
if [[ "${selected_year}" = "" ]]; then
|
|
|
|
help group_year_copy
|
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
# All files by default.
|
2024-01-27 19:42:37 +03:00
|
|
|
[[ "${targets}" = "" ]] && targets=($(ls))
|
|
|
|
|
2024-02-12 01:52:37 +03:00
|
|
|
mkdir ${selected_year} 2> /dev/null
|
2024-01-27 19:42:37 +03:00
|
|
|
|
|
|
|
process() {
|
|
|
|
local year=$(stat --format=%y ${target})
|
|
|
|
year=${year%%-*}
|
|
|
|
|
2024-02-12 01:52:37 +03:00
|
|
|
if [[ "${year}" = "${selected_year}" ]]; then
|
|
|
|
rcp -- ${target} ./${selected_year}/
|
2024-01-27 19:46:57 +03:00
|
|
|
else
|
|
|
|
_iterate_skip
|
|
|
|
fi
|
2024-01-27 19:42:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_iterate_targets process ${targets[@]}
|
|
|
|
}
|