Parse : add extra case parsers.

This commit is contained in:
Dmitry Voronin 2023-12-17 21:35:02 +03:00
parent c45db5815f
commit d6b7f08e13
3 changed files with 63 additions and 5 deletions

View file

@ -18,6 +18,14 @@ To load Gnome settings run `dconf_load`.
# Conventions.
## File namings.
Directory names are `snake_case` so you don't have to release the Shift key 10 times per second when tabing deep for directory.
File names are `CamelCase` to differ from directories, also it works nice with things like my archives where underscore and dash separate extra file data.
File names are `PascalCase` to differ from directories, also it works nice with things like my archives where underscore and dash separate extra file data.
## Bash scripting.
### Variable names.
Use `SNAKE_CASE_UPPERCASE` for global vars *(careful!)* and `snake_case` for function local vars. For private vars and functions append upperscode like this: `_foo`.

View file

@ -10,9 +10,9 @@ function parse_simplify() {
-e "s/^_//" -e "s/_$//"
}
# Parse to CamelCase.
# Usage: parse_camel <STRING>
function parse_camel() {
# Parse to PascalCase.
# Usage: parse_pascal <STRING>
function parse_pascal() {
local IFS=${IFS}_-
local parts=($(parse_simplify ${1}))
local result
@ -41,6 +41,52 @@ function parse_snake() {
echo "${result#_}"
}
# Parse to kebab-case.
# Usage: parse_kebab <STRING>
function parse_kebab() {
local IFS=${IFS}_-
local parts=($(parse_simplify ${1}))
local result
for part in "${parts[@]}"; do
local word="${part,,}"
result="${result}-${word}"
done
echo "${result#-}"
}
# Parse to camelCase.
# Usage: parse_camel <STRING>
function parse_camel() {
local IFS=${IFS}_-
local parts=($(parse_simplify ${1}))
local result
for part in "${parts[@]}"; do
local word="${part,,}"
word="${word^}"
result="${result}${word}"
done
echo "${result,}"
}
# Parse to SNAKE_CASE_UPPERCASE.
# Usage: parse_snake_uppercase <STRING>
function parse_snake_uppercase() {
local IFS=${IFS}_-
local parts=($(parse_simplify ${1}))
local result
for part in "${parts[@]}"; do
local word="${part^^}"
result="${result}_${word}"
done
echo "${result#_}"
}
# Parse data keeping only alphanumeric characters.
# Usage: parse_alnum <STRING>
function parse_alnum() {

View file

@ -233,6 +233,7 @@ Command|Description
`name_postfix <OLD> <NEW> [FILES]`|Change file name postfix. All matching files by default.
`name_replace <OLD> <NEW> [FILES]`|Replace part of the name. All matching files by default.
`name_fix_numbering [FILES]`|Fix numbering for numbered files. I.e if there are 10 items and some of them start without zero, then append zero to it. 1..10 -> 01..10.
`name_convention [FILES]`|Rename dirs to `snake_case` and files to `PascalCase`. Careful with structured file names like archives!
## Ncdu.
@ -265,8 +266,11 @@ Command|Description
Command|Description
---|---
`parse_simplify <STRING>`|Parse data and output simplified format.
`parse_camel <STRING>`|Parse to CamelCase.
`parse_pascal <STRING>`|Parse to PascalCase.
`parse_snake <STRING>`|Parse to snake_case.
`parse_kebab <STRING>`|Parse to kebab-case.
`parse_camel <STRING>`|Parse to camelCase.
`parse_snake_uppercase <STRING>`|Parse to SNAKE_CASE_UPPERCASE.
`parse_alnum <STRING>`|Parse data keeping only alphanumeric characters.
## Permissions.