Skip to content

Commit

Permalink
mommy supports comments and better var names~ 💙
Browse files Browse the repository at this point in the history
  • Loading branch information
FWDekker committed Feb 8, 2023
1 parent 38d667d commit 2a73fc6
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .fpm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
--name mommy
--license unlicense
--architecture all
--depends coreutils --depends grep
--depends coreutils --depends awk --depends grep --depends sed
--description "Mommy's here to support you~"
--url "https://github.com/FWDekker/mommy"
--maintainer "Florine W. Dekker"
Expand Down
34 changes: 16 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ mommy knows her little girl can do better~
```

## configuration
mommy will carefully read the following variables from `~/.config/mommy/config.sh` (override using
mommy will carefully read the following variables from `~/.config/mommy/mommy.conf` (override using
`mommy -c ./my_config`)
to give you the bestest messages~
* `MOMMY_PET_NAME` is what mommy calls you~
* `MOMMY_PRONOUN` is what mommy uses for themselves~
* `MOMMY_ROLE` is how mommy calls themselves~
* `MOMMY_CAREGIVER` is how mommy calls themselves~
* `MOMMY_THEIR` is what mommy uses for themselves~
* `MOMMY_SWEETIE` is what mommy calls you~
* `MOMMY_SUFFIX` is how mommy will end all their messages~
* `MOMMY_CAPITALIZE` is `0` if mommy should start her sentences in lowercase, `1` for uppercase, and anything else to
change nothing~
Expand All @@ -80,26 +80,28 @@ to give you the bestest messages~ ❤

all these options take a `/`-separated list, and mommy will select the one they feel like using whenever they talk
to you~
also, inside variables, lines starting with \fI#\fP are ignored so you can comment and categorize your config~

in custom compliments and encouragements, you can ask mommy to use variables `%%PET_NAME%%`, `%%PRONOUN%%`, and
`%%ROLE%%`~

for example, if the config file looks like
```shell script
MOMMY_PET_NAME="boy/pet/baby"
MOMMY_PRONOUN="his/their"
MOMMY_ROLE="daddy"
MOMMY_CAREGIVER="daddy"
MOMMY_THEIR="his/their"
MOMMY_SWEETIE="boy/pet/baby"
MOMMY_SUFFIX="~/ :3/"
MOMMY_COMPLIMENTS_EXTRA="great job little %%PET_NAME%%/%%ROLE%% is proud of you"
MOMMY_COMPLIMENTS_EXTRA="great job, little %%SWEETIE%%/%%CAREGIVER%% is proud of you"
MOMMY_ENCOURAGEMENTS_EXTRA="
/%%ROLE%% is here for you
/%%ROLE%% will always love you
/%%ROLE%% is here if you want a hug
# encouragements~
/%%CAREGIVER%% is here for you
/%%CAREGIVER%% will always love you
/%%CAREGIVER%% is here if you want a hug
"
```
then mommy might compliment you with any of
* daddy loves his little baby~
* great job little baby :3
* great job, little baby :3
* daddy is proud of you

and so on~
Expand All @@ -125,13 +127,9 @@ on Debian-like machines you can run
sudo gem install fpm
sudo apt install build-essential squashfs-tools rpm gzip
```
after that, just run `./build.sh`, and outputs appear in `dist/`~

to build your own mommy, just run `./build.sh`, and outputs appear in `dist/`~

to install the requirements on a Debian-like machine, run

for a new release, make sure to update the version number in `./version` and `./README.md`, and update the date in
`src/main/resources/mommy.1`~
for a new release, make sure to update the version number in `./version` and `./README.md`~

to run tests, install [shellspec](https://github.com/shellspec/shellspec) and run `./test.sh`~

Expand Down
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set -e

# Load configuration
version=$(cat version)
manual_date=$(git log -1 --pretty="format:%cs" src/main/resources/mommy.1)

# Clean up
rm -rf build/
Expand All @@ -11,7 +12,7 @@ rm -rf dist/
# Prepare build
mkdir build/
cp src/main/sh/mommy src/main/resources/mommy.1 build/
find build/ -type f -exec sed -i "s/%%VERSION_NUMBER%%/$version/g" {} \;
find build/ -type f -exec sed -i "s/%%VERSION_NUMBER%%/$version/g;s/%%MANUAL_DATE%%/$manual_date/g" {} \;
gzip build/mommy.1

# Build packages
Expand Down
33 changes: 18 additions & 15 deletions src/main/resources/mommy.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH MOMMY "1" "2023-02-07" "mommy %%VERSION_NUMBER%%" "User Commands"
.TH MOMMY "1" "%%MANUAL_DATE%%" "mommy %%VERSION_NUMBER%%" "User Commands"


.SH NAME
Expand All @@ -22,14 +22,14 @@ alternatively, \fBmommy\fP shows a message depending on the exit code given in \


.SH CONFIGURATION
\fBmommy\fP will carefully read the following variables from \fI~/.config/mommy/config.sh\fP (override with
\fBmommy\fP will carefully read the following variables from \fI~/.config/mommy/mommy.conf\fP (override with
\fIconfig\fP) to give you the bestest messages~ ❤
.br
* \fIMOMMY_PET_NAME\fP is what \fBmommy\fP calls you~
* \fIMOMMY_SWEETIE\fP is what \fBmommy\fP calls you~
.br
* \fIMOMMY_PRONOUN\fP is what \fBmommy\fP uses for themselves~
* \fIMOMMY_THEIR\fP is the pronoun \fBmommy\fP uses for themselves~
.br
* \fIMOMMY_ROLE\fP is how \fBmommy\fP calls themselves~
* \fIMOMMY_CAREGIVER\fP is how \fBmommy\fP calls themselves~
.br
* \fIMOMMY_SUFFIX\fP is how \fBmommy\fP will end all their messages~
.br
Expand All @@ -52,40 +52,43 @@ else to change nothing~
.br
all these options take a /-separated list, and \fBmommy\fP will select the one they feel like using whenever they talk
to you~
also, inside variables, lines starting with \fI#\fP are ignored so you can comment and categorize your config~

.PP
in custom compliments and encouragements, you can ask \fBmommy\fP to use variables \fI%%PET_NAME%%\fP,
\fI%%PRONOUN%%\fP, and \fI%%ROLE%%\fP~
in custom compliments and encouragements, you can ask \fBmommy\fP to use variables \fI%%CAREGIVER%%\fP, \fI%%THEIR%%\fP,
and \fI%%SWEETIE%%\fP~

.PP
for example, if the \fIconfig\fP looks like
.RS
.br
\fIMOMMY_PET_NAME\fP="boy/pet/baby"
\fIMOMMY_CAREGIVER\fP="daddy"
.br
\fIMOMMY_PRONOUN\fP="his/their"
\fIMOMMY_THEIR\fP="his/their"
.br
\fIMOMMY_ROLE\fP="daddy"
\fIMOMMY_SWEETIE\fP="boy/pet/baby"
.br
\fIMOMMY_SUFFIX\fP="~/ :3/"
.br
\fIMOMMY_COMPLIMENTS_EXTRA\fP="great job little %%PET_NAME%%/%%ROLE%% is proud of you"
\fIMOMMY_COMPLIMENTS_EXTRA\fP="great job, little %%SWEETIE%%/%%CAREGIVER%% is proud of you"
.br
\fIMOMMY_ENCOURAGEMENTS_EXTRA\fP="
.br
/%%ROLE%% is here for you
# encouragements~
.br
/%%ROLE%% will always love you
/%%CAREGIVER%% is here for you
.br
/%%ROLE%% is here if you want a hug
/%%CAREGIVER%% will always love you
.br
/%%CAREGIVER%% is here if you want a hug
.br
"
.RE
then \fBmommy\fP might compliment you with any of
.br
* daddy loves his little baby~
.br
* great job little baby :3
* great job, little baby :3
.br
* daddy is proud of you
.br
Expand Down
92 changes: 58 additions & 34 deletions src/main/sh/mommy
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,63 @@

## Defaults
### Options
MOMMY_OPT_CONFIG_FILE="$HOME/.config/mommy/config.sh"
MOMMY_OPT_CONFIG_FILE="$HOME/.config/mommy/mommy.conf"
MOMMY_OPT_HELP=""
MOMMY_OPT_EVAL=""

### Configuration
MOMMY_PET_NAME="girl"
MOMMY_PRONOUN="her"
MOMMY_ROLE="mommy"
MOMMY_SUFFIX="~ ❤️"
MOMMY_CAREGIVER="mommy"
MOMMY_THEIR="her"
MOMMY_SWEETIE="girl"
MOMMY_SUFFIX="~"

MOMMY_CAPITALIZE="0"

MOMMY_COMPLIMENTS="
good %%PET_NAME%%
/that's a good %%PET_NAME%%
/%%ROLE%% is so proud of you
/%%ROLE%% thinks you deserve a special treat for that
/don't forget to take a break when you feel tired, little %%PET_NAME%%
/%%ROLE%% loves you, you are doing amazing
/%%ROLE%% knew you could do it
# generic~
/amazing work as always
# good X~
/good %%SWEETIE%%
/good job, %%SWEETIE%%
/that's a good %%SWEETIE%%
/who's my good %%SWEETIE%%
# proud~
/%%CAREGIVER%% is very proud of you
/%%CAREGIVER%% is so proud of you
/%%CAREGIVER%% is so very proud of you
/%%CAREGIVER%% knew you could do it
/%%CAREGIVER%% loves you, you are doing amazing
# reward~
/%%CAREGIVER%% thinks you deserve a special treat for that
"
MOMMY_COMPLIMENTS_EXTRA=""
MOMMY_COMPLIMENTS_ENABLED="1"

MOMMY_ENCOURAGEMENTS="
/%%ROLE%% knows %%PRONOUN%% little %%PET_NAME%% can do better
/%%ROLE%% is always here for you if you need %%PRONOUN%%
/aww, did %%ROLE%%'s %%PET_NAME%% make a big mess? %%ROLE%% can help you clean up
/just a little further, %%ROLE%% knows you can do it
/%%ROLE%% believes in you
/aww, come here, sit on my lap while you regain your courage
/%%ROLE%% promises whatever happens %%ROLE%% will be here for you
/%%ROLE%% believes in you because you're my good %%PET_NAME%%
# trust~
/%%CAREGIVER%% believes in you
/%%CAREGIVER%% knows you can do it
/%%CAREGIVER%% knows %%THEIR%% little %%SWEETIE%% can do better
# consolation~
/%%CAREGIVER%% knows it's hard, but it will be okay~
# fallback~
/%%CAREGIVER%% is always here for you
/%%CAREGIVER%% is always here for you if you need %%THEIR%%
/come here, sit on my lap while you regain your courage
/%%CAREGIVER%% promises that, whatever happens, %%CAREGIVER%% will be here for you
# encouragement~
/never give up, my love
/%%CAREGIVER%% knows you'll get there, don't worry
/just a little further, %%CAREGIVER%% knows you can do it
# clean up~
/did %%CAREGIVER%%'s %%SWEETIE%% make a big mess? %%CAREGIVER%% can help you clean up
"
MOMMY_ENCOURAGEMENTS_EXTRA=""
MOMMY_ENCOURAGEMENTS_ENABLED="1"
Expand All @@ -52,10 +76,10 @@ lists_join() {
printf "%s/" "$@" | head -c -1
}

# Removes all whitespace-only entries from the list in stdin. As a result, consecutive `/`s and leading and trailing
# `/`s are removed.
# Takes the list in stdin and removes both (1) all whitespace-only entries and (2) all lines starting with `#`. As a
# result of (1), consecutive `/`s and leading and trailing `/`s are removed.
list_sanitize() {
list="$(cat)/"
list="$(cat | grep -v "^#")/"

sanitized_list=""
while [ -n "$list" ]; do
Expand Down Expand Up @@ -151,16 +175,16 @@ capitalize_lines() {

# Reads stdin, and
# 1. replaces
# * `%%PET_NAME%%` with `$1`,
# * `%%SWEETIE%%` with `$1`,
# * `%%PRONOUN%%` with `$2`, and
# * `%%ROLE%%` with `$3`;
# * `%%CAREGIVER%%` with `$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() {
output=$(cat |
sed -e "s/%%PET_NAME%%/$1/g" -e "s/%%PRONOUN%%/$2/g" -e "s/%%ROLE%%/$3/g" |
sed -e "s/%%SWEETIE%%/$1/g" -e "s/%%PRONOUN%%/$2/g" -e "s/%%CAREGIVER%%/$3/g" |
capitalize_lines "$5" |
sed -e "1h;2,\$H;\$!d;g" -e "s/^\n*//" -e "s/\n*$//")
printf "%s" "$output" "$4"
Expand Down Expand Up @@ -206,16 +230,16 @@ encouragements=$(lists_join "$MOMMY_ENCOURAGEMENTS" "$MOMMY_ENCOURAGEMENTS_EXTRA
list_sanitize |
list_exclude_if_contains "$forbidden_words")

pet_names=$(printf "%s" "$MOMMY_PET_NAME" | list_sanitize)
pronouns=$(printf "%s" "$MOMMY_PRONOUN" | list_sanitize)
roles=$(printf "%s" "$MOMMY_ROLE" | list_sanitize)
suffixes=$(printf "%s" "$MOMMY_SUFFIX" | list_sanitize)
sweetie_list=$(printf "%s" "$MOMMY_SWEETIE" | list_sanitize)
pronoun_list=$(printf "%s" "$MOMMY_THEIR" | list_sanitize)
role_list=$(printf "%s" "$MOMMY_CAREGIVER" | list_sanitize)
suffix_list=$(printf "%s" "$MOMMY_SUFFIX" | list_sanitize)

# Randomize
pet_name=$(printf "%s" "$pet_names" | list_choose_random)
pronoun=$(printf "%s" "$pronouns" | list_choose_random)
role=$(printf "%s" "$roles" | list_choose_random)
suffix=$(printf "%s" "$suffixes" | list_choose_random)
pet_name=$(printf "%s" "$sweetie_list" | list_choose_random)
pronoun=$(printf "%s" "$pronoun_list" | list_choose_random)
role=$(printf "%s" "$role_list" | list_choose_random)
suffix=$(printf "%s" "$suffix_list" | list_choose_random)

compliment=$(printf "%s" "$compliments" | list_choose_random | fill_template_with_globals)
encouragement=$(printf "%s" "$encouragements" | list_choose_random | fill_template_with_globals)
Expand Down
48 changes: 48 additions & 0 deletions src/test/sh/mommy_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,54 @@ forward"
End
End

Describe "comments"
It "ignores lines starting with '#'"
echo "MOMMY_COMPLIMENTS='weaken
#egg
can';MOMMY_SUFFIX=''" > "$config"

When run "$mommy" -c "$config" true
The output should equal "weaken
can"
The status should be success
End

It "does not ignore lines starting with ' #'"
echo "MOMMY_COMPLIMENTS='dish
#seat
absence';MOMMY_SUFFIX=''" > "$config"

When run "$mommy" -c "$config" true
The output should equal "dish
#seat
absence"
The status should be success
End

It "does not ignore lines with a '#' not at the start"
echo "MOMMY_COMPLIMENTS='speed
lo#ud
home';MOMMY_SUFFIX=''" > "$config"

When run "$mommy" -c "$config" true
The output should equal "speed
lo#ud
home"
The status should be success
End

It "ignores the '/' in a comment line"
echo "MOMMY_COMPLIMENTS='figure
#penny/some
wear';MOMMY_SUFFIX=''" > "$config"

When run "$mommy" -c "$config" true
The output should equal "figure
wear"
The status should be success
End
End

Describe "toggling"
It "outputs nothing if a command passes but compliments are disabled"
echo "MOMMY_COMPLIMENTS_ENABLED='0';MOMMY_SUFFIX=''" > "$config"
Expand Down

0 comments on commit 2a73fc6

Please sign in to comment.