From c45db5815f329af106a9c9d7839930c0179e26e2 Mon Sep 17 00:00:00 2001 From: home Date: Sun, 17 Dec 2023 21:15:50 +0300 Subject: [PATCH] Group : group by extension and year. --- .config/bash/module/group.sh | 38 ++++++++++++++++++++++++++++++++ .config/bash/module/recursive.sh | 6 +++++ .doc/bash.md | 16 +++++++++++--- 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 .config/bash/module/group.sh diff --git a/.config/bash/module/group.sh b/.config/bash/module/group.sh new file mode 100644 index 0000000..4209a20 --- /dev/null +++ b/.config/bash/module/group.sh @@ -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[@]} +} diff --git a/.config/bash/module/recursive.sh b/.config/bash/module/recursive.sh index 115fb60..91c071c 100644 --- a/.config/bash/module/recursive.sh +++ b/.config/bash/module/recursive.sh @@ -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. diff --git a/.doc/bash.md b/.doc/bash.md index e80b38f..3c66943 100644 --- a/.doc/bash.md +++ b/.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 `|Get my git repo. `gdc `|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 `|Parse data and output simplified format. `parse_camel `|Parse to CamelCase. +`parse_snake `|Parse to snake_case. `parse_alnum `|Parse data keeping only alphanumeric characters. ## Permissions.