Group : group by extension and year.
This commit is contained in:
parent
43b1d7bc8e
commit
c45db5815f
38
.config/bash/module/group.sh
Normal file
38
.config/bash/module/group.sh
Normal file
|
@ -0,0 +1,38 @@
|
|||
# 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[@]}
|
||||
}
|
|
@ -26,6 +26,9 @@ function recursive() {
|
|||
|
||||
# run command.
|
||||
${*} || failed=${?}
|
||||
|
||||
# Add newline if not the last one.
|
||||
[[ "${count}" = "${total}" ]] || echo
|
||||
done
|
||||
|
||||
# return back on complete.
|
||||
|
@ -62,6 +65,9 @@ function recursive1() {
|
|||
|
||||
# run command.
|
||||
${*} || failed=${?}
|
||||
|
||||
# Add newline if not the last one.
|
||||
[[ "${count}" = "${total}" ]] || echo
|
||||
done
|
||||
|
||||
# return back on complete.
|
||||
|
|
16
.doc/bash.md
16
.doc/bash.md
|
@ -24,10 +24,10 @@ Command|Description
|
|||
`archive_fast [DIRS]`|Archive directories with fast compression. All directories by default.
|
||||
`archive_check [FILES]`|Check archives integrity. Checks all archives by default.
|
||||
`archive_prune [NAME]`|Delete old versions of archives. All archives by default.
|
||||
`unarchive [FILES]`|Extract previously created archive with checksum validation.
|
||||
`archive_name [ARCHIVE] [NAME]`|Rename archives. If no name specified, it simplifies archive's name. If no archives specified, apply to all archives.
|
||||
`archive_convert`|Convert old archives to a new format. *TODO: remove me after some time when there won't be any old archives.*
|
||||
`archive_rm [FILES]`|Delete specified or all archive files.
|
||||
`archive_xz [FILES]`|Recompress previously created archive_fast with better compression.
|
||||
`archive_name [ARCHIVE] [NAME]`|Rename archives. If no name specified, it simplifies archive's name. If no archives specified, apply to all archives.
|
||||
`unarchive [FILES]`|Extract previously created archive with checksum validation.
|
||||
|
||||
## Battery.
|
||||
|
||||
|
@ -43,6 +43,8 @@ Command|Description
|
|||
`bootstrap_texlive`|Install TeXLive.
|
||||
`bootstrap_grub`|Install grub theme.
|
||||
`bootstrap_ffmpeg`|Install ffmpeg.
|
||||
`bootstrap_editorconfig`|Install Editorconfig file (with tabs) in current directory.
|
||||
`bootstrap_editorconfig_space [AMOUNT]`|Install Editorconfig file (with specified spaces, 8 by default) in current directory.
|
||||
|
||||
## Cd.
|
||||
|
||||
|
@ -192,6 +194,13 @@ Command|Description
|
|||
`gg <REPO>`|Get my git repo.
|
||||
`gdc <COMMITHASH>`|See diff for a specific commit.
|
||||
|
||||
## Group.
|
||||
|
||||
Command|Description
|
||||
---|---
|
||||
`group_ext [FILES]`|Group files by extension.
|
||||
`group_year [FILES]`|Group files and dirs by year.
|
||||
|
||||
## Help.
|
||||
|
||||
Command|Description
|
||||
|
@ -257,6 +266,7 @@ Command|Description
|
|||
---|---
|
||||
`parse_simplify <STRING>`|Parse data and output simplified format.
|
||||
`parse_camel <STRING>`|Parse to CamelCase.
|
||||
`parse_snake <STRING>`|Parse to snake_case.
|
||||
`parse_alnum <STRING>`|Parse data keeping only alphanumeric characters.
|
||||
|
||||
## Permissions.
|
||||
|
|
Reference in a new issue