Skip to content

Commit

Permalink
fix: do not depend on lib to decode
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Oct 23, 2024
1 parent 57f5e0f commit 0c4a228
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 40 deletions.
13 changes: 1 addition & 12 deletions .github/workflows/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,11 @@ jobs:
with:
ref: ${{ github.sha }}

- name: Install Poetry
run: pipx install poetry

- name: Force correct branch on workflow sha
run: git checkout -B ${{ github.ref_name }} ${{ github.sha }}

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: 3.12.6
cache: poetry

- name: Install Dependencies
run: |
./bashdep.sh
poetry install --no-root --with dev --sync
run: ./bashdep.sh

- name: Run Tests
run: ./lib/bashunit --parallel `git ls-files "tests/*.sh"`
Expand Down
13 changes: 1 addition & 12 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ mdformat-gfm-alerts = "^1.0.1"
pyproject-fmt = "^2.4.3"
shellcheck-py = "^0.10.0.1"
shfmt-py = "^3.7.0.1"
unidecode = "^1.3.8"
yamllint = "^1.35.1"
45 changes: 30 additions & 15 deletions src/first_time_setup/utils/string.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,28 @@ set -euo pipefail
source 'src/first_time_setup/utils/colours.sh'

# @internal
# @arg $1 The error message.
string.error() {
echo -e "$(colour::fail "${1}")" >&2
return 1
string.decode.a() {
echo "${1}" | sed 'y/āáǎàâãäåĀÁǍÀÂÃÄÅ/aaaaaaaaAAAAAAAA/'
}

# @internal
string.unidecode.find() {
local pip poetry
pip=$(command -v unidecode 2>/dev/null)
poetry=$(poetry run which unidecode 2>/dev/null)
[[ -n ${pip} ]] && echo "${pip}" && return
[[ -n ${poetry} ]] && echo "${poetry}" && return
string.error "Unidecode not found. Install it with 'pip install unidecode'."
return 1
string.decode.e() {
echo "${1}" | sed 'y/ēéěèêëĒÉĚÈÊË/eeeeeeEEEEEE/'
}

# @internal
string.decode.i() {
echo "${1}" | sed 'y/īíǐìîïĪÍǏÌÎÏ/iiiiiiIIIIII/'
}

# @internal
string.decode.o() {
echo "${1}" | sed 'y/ōóǒòôõöŌÓǑÒÔÕÖ/oooooooOOOOOOO/'
}

# @internal
string.decode.u() {
echo "${1}" | sed 'y/ūúǔùûüǖǘǚǜŪÚǓÙÛÜǕǗǙǛ/uuuuuuuuuuUUUUUUUUUU/'
}

# @description Convert a string to lowercase.
Expand All @@ -34,9 +41,17 @@ string::lower() {
# @description Decode a string to ASCII.
# @arg $1 The string to decode.
string::decode() {
local -r unidecode=$(string.unidecode.find)
[[ -z ${unidecode} ]] && return 1
echo "${1}" | "${unidecode}"
local string="${1}"
local -r fx=(
string.decode.a
string.decode.e
string.decode.i
string.decode.o
string.decode.u
)
local fn
for fn in "${fx[@]}"; do string=$("${fn}" "${string}"); done
echo "${string}"
}

# @description Remove special characters from a string.
Expand Down

0 comments on commit 0c4a228

Please sign in to comment.