Skip to content

Commit

Permalink
merge pull request #34 from FWDekker/dev~ 🧡
Browse files Browse the repository at this point in the history
mommy supports advanced pronoun grammar~ ❤️
  • Loading branch information
FWDekker authored Feb 24, 2023
2 parents 86c2ae2 + 21095f8 commit a55d3e6
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 50 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
create-release:
runs-on: ubuntu-latest
needs: [build-linux, build-macos, build-freebsd, build-netbsd, build-openbsd]
if: github.ref == 'refs/heads/main' # For other branches, artifacts are attached to the workflow run as `dist.zip`

steps:
- uses: actions/checkout@v3
Expand All @@ -24,7 +25,7 @@ jobs:
with:
name: dist
- name: Extract version number
run: echo "VERSION=\"$(cat ./version)\"" >> $GITHUB_ENV
run: echo "VERSION=$(cat ./version)" >> $GITHUB_ENV
- name: Extract release notes
id: extract-release-notes
uses: ffurrer2/extract-release-notes@v1
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
## [Unreleased]


## [1.1.0] -- 2023-02-24
* _breaking_: mommy supports different pronoun forms.
instead of `MOMMY_THEIR="her"` and using variable `%%THEIR%%`, you should now write `MOMMY_PRONOUN="she her her"` and use variables `%%THEY%%`, `%%THEM%%`, and `%%THEIR`~


## [1.0.0] -- 2023-02-23
* _breaking_: mommy no longer supports multi-line templates and variables~
* mommy is even faster now with much simpler code~
Expand Down
63 changes: 35 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,28 @@ or specify a different config file with `mommy -c ./my_config.sh [other options]

### config file format
mommy executes the config file as a shell script and keeps the environment variables.
so, to change the value of `MOMMY_PRONOUN`, add the following line to your config file:
so, to change the value of `MOMMY_SWEETIE`, add the following line to your config file:
```shell
MOMMY_PRONOUN="their"
MOMMY_SWEETIE="catgirl"
```
make sure you do not put spaces around the `=`~

### available settings
| variable | description | list? | default |
|--------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------|--------------|
| `MOMMY_CAREGIVER` | what mommy calls herself | yes | `mommy` |
| `MOMMY_THEIR` | mommy's pronoun for herself | yes | `her` |
| `MOMMY_SWEETIE` | what mommy calls you | yes | `girl` |
| `MOMMY_SUFFIX` | what mommy puts at the end of each sentence | yes | `~` |
| `MOMMY_CAPITALIZE` | `0` to start sentences in lowercase, `1` for uppercase, anything else to change nothing | no | `0` |
| `MOMMY_COLOR` | color of mommy's text. you can use any [xterm color code](https://upload.wikimedia.org/wikipedia/commons/1/15/Xterm_256color_chart.svg), or write `lolcat` to use [lolcat](https://github.com/busyloop/lolcat) (install separately). specify multiple colors separated by `/` to randomly select one. set to empty string for your terminal's default color. | yes | `005` |
| `MOMMY_COMPLIMENTS` | default compliment templates | yes | <various> |
| `MOMMY_COMPLIMENTS_EXTRA` | additional compliment templates you can specify | yes | <empty> |
| `MOMMY_COMPLIMENTS_ENABLED` | `1` to enable compliments, anything else to disable | no | `1` |
| `MOMMY_ENCOURAGEMENTS` | default encouragement templates | yes | <various> |
| `MOMMY_ENCOURAGEMENTS_EXTRA` | additional encouragement templates you can specify | yes | <empty> |
| `MOMMY_ENCOURAGEMENTS_ENABLED` | `1` to enable encouragements, anything else to disable | no | `1` |
| `MOMMY_FORBIDDEN_WORDS` | mommy will not use templates that contain forbidden / trigger words | yes | <empty> |
| variable | description | list? | default |
|--------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------|---------------|
| `MOMMY_CAREGIVER` | what mommy calls herself | yes | `mommy` |
| `MOMMY_PRONOUNS` | mommy's pronouns for herself. should be three words separated by spaces, as in `they them their` (subject, object, possessive) | yes | `she her her` |
| `MOMMY_SWEETIE` | what mommy calls you | yes | `girl` |
| `MOMMY_SUFFIX` | what mommy puts at the end of each sentence | yes | `~` |
| `MOMMY_CAPITALIZE` | `0` to start sentences in lowercase, `1` for uppercase, anything else to change nothing | no | `0` |
| `MOMMY_COLOR` | color of mommy's text. you can use any [xterm color code](https://upload.wikimedia.org/wikipedia/commons/1/15/Xterm_256color_chart.svg), or write `lolcat` to use [lolcat](https://github.com/busyloop/lolcat) (install separately). specify multiple colors separated by `/` to randomly select one. set to empty string for your terminal's default color. | yes | `005` |
| `MOMMY_COMPLIMENTS` | default compliment templates | yes | <various> |
| `MOMMY_COMPLIMENTS_EXTRA` | additional compliment templates you can specify | yes | <empty> |
| `MOMMY_COMPLIMENTS_ENABLED` | `1` to enable compliments, anything else to disable | no | `1` |
| `MOMMY_ENCOURAGEMENTS` | default encouragement templates | yes | <various> |
| `MOMMY_ENCOURAGEMENTS_EXTRA` | additional encouragement templates you can specify | yes | <empty> |
| `MOMMY_ENCOURAGEMENTS_ENABLED` | `1` to enable encouragements, anything else to disable | no | `1` |
| `MOMMY_FORBIDDEN_WORDS` | mommy will not use templates that contain forbidden / trigger words | yes | <empty> |

### lists
some of these settings support lists.
Expand All @@ -91,10 +91,15 @@ elements that contain whitespace only, and elements that start with a `#` are ig
then mommy will sometimes call you `girl`, and sometimes `kitten`~
* if you set
```shell
MOMMY_PRONOUN="their
faer/#her/its"
MOMMY_CAREGIVER="mommy
mummy/#daddy/caregiver"
```
then mommy will use pronouns `their`, `faer`, and `its`, but not `her`~
then mommy will call herself `mommy`, `mummy`, or `caregiver`, but not `daddy`~
* if you set
```shell
MOMMY_PRONOUNS="she her her/they them their"
```
then mommy may choose between `mommy knows she loves her girl` and `mommy knows they love their girl`~
* if you set
```shell
MOMMY_FORBIDDEN_WORDS="cat/dog"
Expand All @@ -108,14 +113,16 @@ similarly so for encouragements~

### template variables
inside compliments and encouragements, you can put placeholders that contain the random values that mommy chose.
for example, if you add the compliment `%%CAREGIVER%% loves you`, and `MOMMY_CAREGIVER=your mommy`, then mommy outputs
`your mommy loves you`~
for example, if you add the compliment `%%CAREGIVER%% loves you`, and have `MOMMY_CAREGIVER=your mommy`, then mommy
outputs `your mommy loves you`~

| variable | description |
|-----------------|-----------------------------|
| `%%CAREGIVER%%` | what mommy calls herself |
| `%%THEIR%%` | mommy's pronoun for herself |
| `%%SWEETIE%%` | what mommy calls you |
| variable | description |
|-----------------|---------------------------------------------------|
| `%%CAREGIVER%%` | what mommy calls herself |
| `%%THEY%%` | mommy's subject pronoun (e.g. he, she, they) |
| `%%THEM%%` | mommy's object pronoun (e.g. him, her, them) |
| `%%THEIR%%` | mommy's possessive pronoun (e.g. his, her, their) |
| `%%SWEETIE%%` | what mommy calls you |

### renaming the mommy executable
if you want to write `daddy npm test` instead of `mommy npm test`, you can just create a symlink.
Expand Down Expand Up @@ -178,7 +185,7 @@ RPS1="\$(mommy -s \$? 2>&1)"
```
### other shells
as a generic method, in any POSIX shell (including `sh`, `ash`, `dash`, `bash`) you can change the prompt itself to
as a generic method, in any posix shell (including `sh`, `ash`, `dash`, `bash`) you can change the prompt itself to
contain a message from mommy by setting the `$PS1` variable:
```shell
export PS1="\$(mommy -s \$? 2>&1)$PS1"
Expand Down
30 changes: 24 additions & 6 deletions src/main/sh/mommy
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ MOMMY_OPT_CONFIG_FILE="$HOME/.config/mommy/config.sh"

### Configuration
MOMMY_CAREGIVER="mommy"
MOMMY_THEIR="her"
MOMMY_PRONOUNS="she her her"
MOMMY_SWEETIE="girl"
MOMMY_SUFFIX="~"
MOMMY_COLOR="005"
Expand Down Expand Up @@ -57,6 +57,7 @@ it's okay to make mistakes
# fallback~
%%CAREGIVER%% is always here for you
%%CAREGIVER%% is always here for you if you need %%THEM%%
come here, sit on my lap while we figure this out together
# encouragement~
Expand Down Expand Up @@ -149,22 +150,39 @@ capitalize() {
return 0
}

# Given the whitespace-separated list of three words in `$1`, stores the three words in `$they`, `$them`, and `$their`,
# respectively.
split_pronouns() {
they="${1%% *}"
remainder="${1#* }"
them="${remainder%% *}"
their="${remainder##* }"

return 0
}

# Reads stdin, and
# 1. replaces
# * `%%SWEETIE%%` with a random entry from `$1`,
# * `%%THEIR%%` with a random entry from `$2`, and
# * `%%THEY%%` with the first word in `$2`,
# * `%%THEM%%` with the second word in `$2`,
# * `%%THEIR%%` with the third word in `$2`, and
# * `%%CAREGIVER%%` with a random entry from `$3`;
# 2. applies `capitalize_lines` using `$5` as the choice parameter;
# 3. removes leading and trailing newlines;
# 4. appends `$4`; and
# 5. writes to stdout.
fill_template() {
sweetie="$(echo "$1" | list_sanitize | list_choose)"
their="$(echo "$2" | list_sanitize | list_choose)"
split_pronouns "$(echo "$2" | list_sanitize | list_choose)"
caregiver="$(echo "$3" | list_sanitize | list_choose)"
suffix="$(echo "$4" | list_sanitize | list_choose)"

template="$(cat | sed -e "s/%%SWEETIE%%/$sweetie/g" -e "s/%%THEIR%%/$their/g" -e "s/%%CAREGIVER%%/$caregiver/g")"
template="$(cat | sed -e "s/%%SWEETIE%%/$sweetie/g" \
-e "s/%%THEY%%/$they/g" \
-e "s/%%THEM%%/$them/g" \
-e "s/%%THEIR%%/$their/g" \
-e "s/%%CAREGIVER%%/$caregiver/g")"

printf "%s" "$template" "$suffix" | capitalize "$5"
return 0
Expand All @@ -181,7 +199,7 @@ while getopts "hvc:e:s:-:" OPTION; do
# Workaround for long options: https://stackoverflow.com/a/28466267/
if [ "$OPTION" = "-" ]; then
OPTION="${OPTARG%%=*}"
OPTARG="${OPTARG#$OPT}"
OPTARG="${OPTARG#$OPTION}"
OPTARG="${OPTARG#=}"
fi

Expand Down Expand Up @@ -243,7 +261,7 @@ else
echo "$templates" |
list_sanitize "$forbidden_words" |
list_choose |
fill_template "$MOMMY_SWEETIE" "$MOMMY_THEIR" "$MOMMY_CAREGIVER" "$MOMMY_SUFFIX" "$MOMMY_CAPITALIZE" |
fill_template "$MOMMY_SWEETIE" "$MOMMY_PRONOUNS" "$MOMMY_CAREGIVER" "$MOMMY_SUFFIX" "$MOMMY_CAPITALIZE" |
color_cat "$color" >&2
exit "$command_exit_code"
fi
Loading

0 comments on commit a55d3e6

Please sign in to comment.