This repository has been archived on 2024-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
linux/.config/bash/module/group.sh

39 lines
815 B
Bash
Raw Normal View History

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##*.}
[[ -d "${target}" ]] && { _skip "Is a directory."; return 0; }
[[ "${ext}" = "${target}" ]] && { _skip "No extension."; return 0; }
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[@]}
}