Last active
June 26, 2024 10:07
-
-
Save ericcornelissen/1a3dc9ed7d9a03e0c386751545915687 to your computer and use it in GitHub Desktop.
Simple bash script to help standardize written language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# --- Helpers --- | |
replace_perserving_capitalization() { | |
file="${1}" | |
from="${2}" | |
to="${3}" | |
fh="$(echo "${from}" | cut -c 1-1)" | |
ft="$(echo "${from}" | cut -c 2-)" | |
th="$(echo "${to}" | cut -c 1-1)" | |
tt="$(echo "${to}" | cut -c 2-)" | |
sed -ri "s/${fh}${ft}/${th}${tt}/g" "${file}" | |
sed -ri "s/${fh^}${ft}/${th^}${tt}/g" "${file}" | |
} | |
# --- Replacers --- | |
avoid_very() { | |
file="${1}" | |
replace() { | |
if [[ "${2}" != ^a ]]; then | |
sed -ri "s/(A|a) very ${1}/\1n ${2}/g" "${file}" | |
fi | |
sed -i "s/very ${1}/${2}/g" "${file}" | |
} | |
replace 'accurate' 'exact' | |
replace 'afraid' 'fearful' | |
replace 'angry' 'furious' | |
replace 'bad' 'atrocious' | |
replace 'beautiful' 'exquisite' | |
replace 'big' 'immense' | |
replace 'boring' 'dull' | |
replace 'bright' 'luminous' | |
replace 'calm' 'serene' | |
replace 'careful' 'cautious' | |
replace 'clean' 'spotless' | |
replace 'clever' 'brilliant' | |
replace 'cold' 'freezing' | |
replace 'colorful' 'vibrant' | |
replace 'competetive' 'cutthroat' | |
replace 'confused' 'perplexed' | |
replace 'crowded' 'bustling' | |
replace 'cute' 'adorable' | |
replace 'dear' 'cherished' | |
replace 'detailed' 'meticulous' | |
replace 'different' 'disparate' | |
replace 'dry' 'parched' | |
replace 'dull' 'tedious' | |
replace 'eager' 'keen' | |
replace 'empty' 'desolate' | |
replace 'exciting' 'exhilarating' | |
replace 'evil' 'wicked' | |
replace 'fast' 'quick' | |
replace 'fat' 'obese' | |
replace 'glad' 'overjoyed' | |
replace 'good' 'excellent' | |
replace 'happy' 'ecstatic' | |
replace 'hard' 'difficult' | |
replace 'large' 'huge' | |
replace 'lazy' 'indolent' | |
replace 'light' 'luminous' | |
replace 'little' 'tiny' | |
replace 'lively' 'animated' | |
replace 'long-term' 'enduring' | |
replace 'loud' 'deafening' | |
replace 'loved' 'adored' | |
replace 'neat' 'immaculate' | |
replace 'necessary' 'essential' | |
replace 'nervous' 'apprehensive' | |
replace 'nice' 'kind' | |
replace 'noisy' 'deafening' | |
replace 'often' 'frequently' | |
replace 'old' 'ancient' | |
replace 'painful' 'excruciating' | |
replace 'poor' 'destitute' | |
replace 'quiet' 'silent' | |
replace 'rainy' 'pouring' | |
replace 'rich' 'wealthy' | |
replace 'risky' 'preilous' | |
replace 'roomy' 'spacious' | |
replace 'scared' 'petrified' | |
replace 'shiny' 'gleaming' | |
replace 'short' 'brief' | |
replace 'shy' 'timid' | |
replace 'simple' 'basic' | |
replace 'slow' 'sluggish' | |
replace 'smart' 'intelligent' | |
replace 'smelly' 'pungent' | |
replace 'smooth' 'sleek' | |
replace 'strong' 'unyielding' | |
replace 'stupid' 'idiotic' | |
replace 'tasty' 'delicious' | |
replace 'thin' 'gaunt' | |
replace 'tired' 'exhausted' | |
replace 'tall' 'towering' | |
replace 'ugly' 'hideous' | |
replace 'upset' 'distraught' | |
replace 'valuable' 'precious' | |
replace 'weak' 'frail' | |
replace 'wicked' 'villenous' | |
replace 'willing' 'eager' | |
replace 'worried' 'distressed' | |
} | |
british() { | |
file="${1}" | |
lang="${2}" | |
if [[ "${lang}" != "EN-gb" && "${lang}" != "EN-us" ]]; then | |
echo "Unknown language code '${lang}' (must be EN-gb or EN-us)" | |
exit 2 | |
fi | |
suffix() { | |
if [[ "${lang}" == "EN-gb" ]]; then | |
sed -ri "s/([^[:space:]])${1}/\1${2}/g" "${file}" | |
else | |
sed -ri "s/([^[:space:]])${2}/\1${1}/g" "${file}" | |
fi | |
} | |
suffix 'eling' 'elling' | |
suffix 'eled' 'elled' | |
suffix 'eler' 'eller' | |
# suffix 'ize' 'ise' | |
suffix 'yze' 'yse' | |
suffix 'ization' 'isation' | |
replace() { | |
if [[ "${lang}" == "EN-gb" ]]; then | |
replace_perserving_capitalization "${file}" "${1}" "${2}" | |
else | |
replace_perserving_capitalization "${file}" "${2}" "${1}" | |
fi | |
} | |
replace 'behavior' 'behaviour' | |
replace 'center' 'centre' | |
replace 'color' 'colour' | |
replace 'defense' 'defence' | |
replace 'dialog' 'dialogue' | |
replace 'favor' 'favour' | |
replace 'flavor' 'flavour' | |
replace 'gray' 'grey' | |
replace 'honor' 'honour' | |
replace 'offense' 'offence' | |
replace 'pretense' 'pretence' | |
} | |
contractions() { | |
file="${1}" | |
replace() { | |
replace_perserving_capitalization "${file}" "${1}" "${2}" | |
} | |
replace "aren't" 'are not' | |
replace "can't" 'can not' | |
replace "couldn't" 'could not' | |
replace "didn't" 'did not' | |
replace "doesn't" 'does not' | |
replace "don't" 'do not' | |
replace "hadn't" 'had not' | |
replace "hasn't" 'has not' | |
replace "haven't" 'have not' | |
replace "he'd" 'he had' | |
replace "he'll" 'he will' | |
replace "he's" 'he is' | |
replace "I'd" 'I had' | |
replace "I'll" 'I will' | |
replace "I'm" 'I am' | |
replace "I've" 'I have' | |
replace "isn't" 'is not' | |
replace "it's" 'it is' | |
replace "let's" 'let us' | |
replace "mightn't" 'might not' | |
replace "mustn't" 'must not' | |
replace "shan't" 'shall not' | |
replace "she'd" 'she had' | |
replace "she'll" 'she will' | |
replace "she's" 'she is' | |
replace "shouldn't" 'should not' | |
replace "that's" 'that is' | |
replace "there's" 'there is' | |
replace "they'd" 'they would' | |
replace "they'll" 'they will' | |
replace "they're" 'they are' | |
replace "we'd" 'we had' | |
replace "we're" 'we are' | |
replace "we've" 'we have' | |
replace "weren't" 'were not' | |
replace "what'll" 'what will' | |
replace "what're" 'what are' | |
replace "what's" 'what is' | |
replace "what've" 'what have' | |
replace "where's" 'where is' | |
replace "who'd" 'who had' | |
replace "who'll" 'who will' | |
replace "who're" 'who are' | |
replace "who's" 'who is' | |
replace "who've" 'who have' | |
replace "won't" 'will not' | |
replace "wouldn't" 'would not' | |
replace "you'd" 'you had' | |
replace "you'll" 'you will' | |
replace "you're" 'you are' | |
replace "you've" 'you have' | |
} | |
# --- Program --- | |
for file in "$@"; do | |
echo "Processing ${file}" | |
avoid_very "${file}" | |
british "${file}" 'EN-us' | |
contractions "${file}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment