From 786b970013b4d2dbb71f8629c9b04e575112242c Mon Sep 17 00:00:00 2001 From: "Florine W. Dekker" Date: Sat, 28 Jan 2023 17:17:23 +0100 Subject: [PATCH 1/6] =?UTF-8?q?mommy=20compliments=20you=20with=20varying?= =?UTF-8?q?=20sentences~=20=F0=9F=92=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.sh | 2 +- src/mommy | 113 ++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 93 insertions(+), 22 deletions(-) diff --git a/build.sh b/build.sh index 2e30100..c6887ca 100755 --- a/build.sh +++ b/build.sh @@ -17,5 +17,5 @@ mkdir dist/ for target in apk deb rpm sh tar; do echo "# Build $target" - fpm -t $target -p dist/mommy-$version.$target --version $version + fpm -t "$target" -p "dist/mommy-$version.$target" --version "$version" done diff --git a/src/mommy b/src/mommy index 7967983..07bfabe 100755 --- a/src/mommy +++ b/src/mommy @@ -1,40 +1,111 @@ #!/bin/sh -choose_random_option() { - count=$(expr $(echo "$1" | grep -o "/" | wc -l) + 1) +## Defaults +MOMMYS_CONFIG_FILE="$HOME/.config/mommy/config.sh" +MOMMYS_LITTLE="girl" +MOMMYS_PRONOUNS="her" +MOMMYS_ROLES="mommy" +MOMMYS_SUFFIX="~ ❤️" +MOMMYS_COMPLIMENTS=\ +"Good %%LITTLE%%\ +/That's a good %%LITTLE%%\ +/%%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 %%LITTLE%%\ +/%%ROLE%% loves you, you are doing amazing\ +/%%ROLE%% knew you could do it" +MOMMYS_COMPLIMENTS_EXTRA="" +MOMMYS_ENCOURAGEMENTS=\ +"%%ROLE%% knows %%PRONOUN%% little %%LITTLE%% can do better\ +/%%ROLE%% is always here for you if you need %%PRONOUN%%\ +/Aww, did %%ROLE%%'s %%LITTLE%% make a big mess? I can help you clean up\ +/Just a little further, I know you can do it\ +/%%ROLE%% believes in you\ +/Aww, come here, sit on my lap while you regain your courage\ +/I promise whatever happens %%ROLE%% will be here for you\ +/I believe in you because you're my good %%LITTLE%%" +MOMMYS_ENCOURAGEMENTS_EXTRA="" + + +## Functions +# Reads stdin, converts to sentence case, and writes to stdout. +to_sentence_case() { + input=$(cat) + echo "$(echo "$input" | cut -c1 | tr "[:lower:]" "[:upper:]")$(echo "$input" | cut -c2-)" +} + +# Splits `$1` by `/`, and writes a random part to stdout. +choose_random() { + count=$(echo "$1/" | grep -o "/" | wc -l) idx=$(shuf -i 1-"$count" -n 1) echo "$1" | cut -d "/" -f "$idx" return 0 } -# Defaults -MOMMYS_LITTLE="girl" -MOMMYS_PRONOUNS="her" -MOMMYS_ROLES="mommy" +# If `$2` is the empty string, writes `$1` to stdout; otherwise, writes `$1/$2` to stdout. +append_with_delimiter_if_not_empty() { + if [ "$2" = "" ]; then + echo "$1" + else + echo "$1/$2" + fi + return 0 +} + +# Takes `$1`, replaces +# * `%%LITTLE%%` with `$2`, +# * `%%PRONOUN%%` with `$3`, and +# * `%%ROLE%%` with `$4`; +# appends `$5`; and converts the output to sentence case. +fill_template() { + echo "$1$5" | sed -e "s/%%LITTLE%%/$2/g" -e "s/%%PRONOUN%%/$3/g" -e "s/%%ROLE%%/$4/g" | to_sentence_case + return 0 +} + + +## Load configuration +# shellcheck source=/dev/null +test -f "$MOMMYS_CONFIG_FILE" && . "$MOMMYS_CONFIG_FILE" -# Load configuration -FILE="$HOME/.config/mommy/config.sh" && test -f $FILE && . $FILE +compliments=$(append_with_delimiter_if_not_empty "$MOMMYS_COMPLIMENTS" "$MOMMYS_COMPLIMENTS_EXTRA") +encouragements=$(append_with_delimiter_if_not_empty "$MOMMYS_ENCOURAGEMENTS" "$MOMMYS_ENCOURAGEMENTS_EXTRA") # Randomize -little=$(choose_random_option "$MOMMYS_LITTLE") -pronoun=$(choose_random_option "$MOMMYS_PRONOUNS") -role=$(choose_random_option "$MOMMYS_ROLES") -message="\n$role knows $pronoun little $little can do better~ ❤️" - -# Help the little one :3 -if [ $# -eq 0 ]; then - echo "$message" -elif [ $1 = "-h" ] || [ $1 = "--help" ]; then +little=$(choose_random "$MOMMYS_LITTLE") +pronoun=$(choose_random "$MOMMYS_PRONOUNS") +role=$(choose_random "$MOMMYS_ROLES") +suffix=$(choose_random "$MOMMYS_SUFFIX") + +compliment=$(fill_template "$(choose_random "$compliments")" "$little" "$pronoun" "$role" "$suffix") +encouragement=$(fill_template "$(choose_random "$encouragements")" "$little" "$pronoun" "$role" "$suffix") + + +## Output +if [ "$1" = "-0" ]; then + echo "$compliment" +elif [ "$1" = "-1" ]; then + echo "$encouragement" >&2 +elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then global_man_path="/usr/share/man/man1/mommy.1" local_man_path="$(dirname -- "$0")/mommy.1" - if [ -f $local_man_path ]; then + if [ -f "$local_man_path" ]; then man -l "$local_man_path" | cat - elif [ -f $global_man_path ]; then + elif [ -f "$global_man_path" ]; then man mommy | cat else - echo "$role could not find the manual for $pronoun little $little~" + echo "$role could not find the manual for $pronoun little $little~" >&2 fi else - $@ || echo "$message" + # shellcheck disable=SC2068 + $@ + command_exit_code=$? + + if [ $command_exit_code -eq 0 ]; then + echo "$compliment" + return 0 + else + echo "$encouragement" >&2 + return $command_exit_code + fi fi From 2c76aa8b228253ed52fb7ea0d7948bd790ff6d9a Mon Sep 17 00:00:00 2001 From: "Florine W. Dekker" Date: Sat, 28 Jan 2023 21:25:41 +0100 Subject: [PATCH 2/6] =?UTF-8?q?mommy=20cleaned=20up=20the=20docs=20and=20a?= =?UTF-8?q?=20lot=20of=20code~=20=F0=9F=92=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++- src/mommy | 129 +++++++++++++++++++++++++---------------- src/mommy.1 | 164 +++++++++++++++++++++++++++++++--------------------- 3 files changed, 183 insertions(+), 118 deletions(-) diff --git a/README.md b/README.md index fe4e6ef..6c14bf0 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,18 @@ # mommy mommy's here to support you~ ❤️ +mommy was inspired by [cargo-mommy](https://github.com/Gankra/cargo-mommy)~ + ## Installation -Download the [latest release](https://github.com/FWDekker/mommy/releases/latest) for your platform and install as usual~ +download the [latest release](https://github.com/FWDekker/mommy/releases/latest) for your platform and install as usual~ -For example, on Debian-like systems (including Ubuntu), run +for example, on Debian-like systems (including Ubuntu), run ```shell sudo apt install ./mommy-0.0.2.deb ``` ## Usage -Run any command you want, but prepend it with `mommy`~ +run any command you want, but prepend it with `mommy`~ ```shell $> mommy npm test diff --git a/src/mommy b/src/mommy index 07bfabe..f3595f5 100755 --- a/src/mommy +++ b/src/mommy @@ -1,104 +1,133 @@ #!/bin/sh ## Defaults -MOMMYS_CONFIG_FILE="$HOME/.config/mommy/config.sh" -MOMMYS_LITTLE="girl" -MOMMYS_PRONOUNS="her" -MOMMYS_ROLES="mommy" -MOMMYS_SUFFIX="~ ❤️" -MOMMYS_COMPLIMENTS=\ -"Good %%LITTLE%%\ -/That's a good %%LITTLE%%\ +MOMMY_CONFIG_FILE="$HOME/.config/mommy/config.sh" + +MOMMY_PET_NAME="girl" +MOMMY_PRONOUN="her" +MOMMY_ROLE="mommy" +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 %%LITTLE%%\ +/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" -MOMMYS_COMPLIMENTS_EXTRA="" -MOMMYS_ENCOURAGEMENTS=\ -"%%ROLE%% knows %%PRONOUN%% little %%LITTLE%% can do better\ +/%%ROLE%% knew you could do it\ +" +MOMMY_COMPLIMENTS_EXTRA="" +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 %%LITTLE%% make a big mess? I can help you clean up\ -/Just a little further, I know you can do it\ +/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\ -/I promise whatever happens %%ROLE%% will be here for you\ -/I believe in you because you're my good %%LITTLE%%" -MOMMYS_ENCOURAGEMENTS_EXTRA="" +/aww, come here, sit on my lap while you regain your courage\ +/%%ROLE%% promises whatever happens I will be here for you\ +/%%ROLE%% believes in you because you're my good %%PET_NAME%%\ +" +MOMMY_ENCOURAGEMENTS_EXTRA="" ## Functions -# Reads stdin, converts to sentence case, and writes to stdout. -to_sentence_case() { +# Reads stdin; if `$1` is `0`, the first character is changed to lowercase, otherwise the first character is changed to +# uppercase; and writes to stdout. +capitalize() { input=$(cat) - echo "$(echo "$input" | cut -c1 | tr "[:lower:]" "[:upper:]")$(echo "$input" | cut -c2-)" + if [ "$1" -eq "0" ]; then + from="[:upper:]" + to="[:lower:]" + else + from="[:lower:]" + to="[:upper:]" + fi + + echo "$(echo "$input" | cut -c 1 | tr "$from" "$to")$(echo "$input" | cut -c 2-)" + return 0 } -# Splits `$1` by `/`, and writes a random part to stdout. +# Splits stdin by `/`, and writes a random part to stdout. choose_random() { - count=$(echo "$1/" | grep -o "/" | wc -l) + list=$(cat) + + count=$(echo "$list/" | grep -o "/" | wc -l) idx=$(shuf -i 1-"$count" -n 1) - echo "$1" | cut -d "/" -f "$idx" + + echo "$list" | cut -d "/" -f "$idx" return 0 } -# If `$2` is the empty string, writes `$1` to stdout; otherwise, writes `$1/$2` to stdout. -append_with_delimiter_if_not_empty() { - if [ "$2" = "" ]; then - echo "$1" - else - echo "$1/$2" - fi +# Joins all input arguments using `/` as the delimiter and writes to stdout, removes consecutive `/`s, and removes +# leading and trailing `/`es. Respects the word splitting of the inputs to determine where to place the delimiter. +join_by_slash() { + printf "%s/" "$@" | tr -s "/" | sed -e "1h;2,\$H;\$!d;g" -e "s/^\/*//" -e "s/\/*$//" return 0 } -# Takes `$1`, replaces -# * `%%LITTLE%%` with `$2`, -# * `%%PRONOUN%%` with `$3`, and -# * `%%ROLE%%` with `$4`; -# appends `$5`; and converts the output to sentence case. +# Reads stdin, and +# 1. replaces +# * `%%PET_NAME%%` with `$1`, +# * `%%PRONOUN%%` with `$2`, and +# * `%%ROLE%%` with `$3`; +# 2. appends `$4`; +# 3. applies `capitalize` using `$5` as the choice parameter; and +# 4. writes to stdout. fill_template() { - echo "$1$5" | sed -e "s/%%LITTLE%%/$2/g" -e "s/%%PRONOUN%%/$3/g" -e "s/%%ROLE%%/$4/g" | to_sentence_case + cat | sed -e "s/%%PET_NAME%%/$1/g" -e "s/%%PRONOUN%%/$2/g" -e "s/%%ROLE%%/$3/g" | sed "s/$/$4/" | capitalize "$5" + return 0 +} + +# Reads stdin and invokes `fill_template` using the expected global parameters. +fill_template_with_globals() { + cat | fill_template "$pet_name" "$pronoun" "$role" "$suffix" "$MOMMY_CAPITALIZE" return 0 } ## Load configuration # shellcheck source=/dev/null -test -f "$MOMMYS_CONFIG_FILE" && . "$MOMMYS_CONFIG_FILE" +test -f "$MOMMY_CONFIG_FILE" && . "$MOMMY_CONFIG_FILE" -compliments=$(append_with_delimiter_if_not_empty "$MOMMYS_COMPLIMENTS" "$MOMMYS_COMPLIMENTS_EXTRA") -encouragements=$(append_with_delimiter_if_not_empty "$MOMMYS_ENCOURAGEMENTS" "$MOMMYS_ENCOURAGEMENTS_EXTRA") +compliments=$(join_by_slash "$MOMMY_COMPLIMENTS" "$MOMMY_COMPLIMENTS_EXTRA") +encouragements=$(join_by_slash "$MOMMY_ENCOURAGEMENTS" "$MOMMY_ENCOURAGEMENTS_EXTRA") # Randomize -little=$(choose_random "$MOMMYS_LITTLE") -pronoun=$(choose_random "$MOMMYS_PRONOUNS") -role=$(choose_random "$MOMMYS_ROLES") -suffix=$(choose_random "$MOMMYS_SUFFIX") +pet_name=$(echo "$MOMMY_PET_NAME" | choose_random) +pronoun=$(echo "$MOMMY_PRONOUN" | choose_random) +role=$(echo "$MOMMY_ROLE" | choose_random) +suffix=$(echo "$MOMMY_SUFFIX" | choose_random) -compliment=$(fill_template "$(choose_random "$compliments")" "$little" "$pronoun" "$role" "$suffix") -encouragement=$(fill_template "$(choose_random "$encouragements")" "$little" "$pronoun" "$role" "$suffix") +compliment=$(echo "$compliments" | choose_random | fill_template_with_globals) +encouragement=$(echo "$encouragements" | choose_random | fill_template_with_globals) ## Output if [ "$1" = "-0" ]; then echo "$compliment" + return 0 elif [ "$1" = "-1" ]; then echo "$encouragement" >&2 + return 1 elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then global_man_path="/usr/share/man/man1/mommy.1" local_man_path="$(dirname -- "$0")/mommy.1" if [ -f "$local_man_path" ]; then + echo "" man -l "$local_man_path" | cat + return 0 elif [ -f "$global_man_path" ]; then man mommy | cat + return 0 else - echo "$role could not find the manual for $pronoun little $little~" >&2 + echo "%%ROLE%% could not find the manual for %%PRONOUN%% little %%PET_NAME%%" | fill_template_with_globals >&2 + return 1 fi else - # shellcheck disable=SC2068 - $@ + "$@" command_exit_code=$? if [ $command_exit_code -eq 0 ]; then diff --git a/src/mommy.1 b/src/mommy.1 index 15dc658..e311d3c 100644 --- a/src/mommy.1 +++ b/src/mommy.1 @@ -2,86 +2,120 @@ .SH NAME -mommy \- here to support you~ +mommy - here to support you~ .SH SYNOPSIS -.B mommy -.RI [\| "command" \|] +\fBmommy\fP [\fIcommand\fP] .br -.B mommy -.BR \-h \||\| \-\-help +\fBmommy\fP \fB-0\fP +.br +\fBmommy\fP \fB-1\fP + + .SH DESCRIPTION -.B mommy -displays encouraging messages when -.I command -fails~ +\fBmommy\fP displays a compliment when \fIcommand\fP succeeds and an encouraging message when \fIcommand\fP fails~ .PP -.B mommy -will carefully read -.I ~/.config/mommy/config.sh -to give you the bestest messages~ ❤ - -.TS -tab (@); -l lx. -*@T{ -.I MOMMYS_LITTLE -is what -.B mommy -calls you~ (default: "girl") -T} -*@T{ -.I MOMMYS_PRONOUNS -is what -.B mommy -uses for themselves~ (default: "her") -T} -*@T{ -.I MOMMYS_ROLES -is what role -.B mommy -will have~ (default: "mommy") -T} -.TE +alternatively, \fBmommy\fP will compliment you if you set \fI-0\fP, and will encourage you if you set \fI-1\fP~ .PP -All these options can take a /-separated list, and -.B mommy -will select the one they feel like using whenever they talk to you~ +\fBmommy\fP will carefully read the following variables from \fI~/.config/mommy/config.sh\fP to give you the bestest +messages~ ❤ +.br +* \fIMOMMY_PET_NAME\fP is what \fBmommy\fP calls you~ +.br +* \fIMOMMY_PRONOUN\fP is what \fBmommy\fP uses for themselves~ +.br +* \fIMOMMY_ROLE\fP is how \fBmommy\fP calls themselves~ +.br +* \fIMOMMY_SUFFIX\fP is how \fBmommy\fP will end all their messages~ +.br +* \fIMOMMY_CAPITALIZE\fP is `0` if \fBmommy\fP should start her sentences in lowercase, and `1` for uppercase~ +.br +* \fIMOMMY_COMPLIMENTS\fP is the compliment \fBmommy\fP should give you if you did a good job~ +.br +* \fIMOMMY_COMPLIMENTS_EXTRA\fP is where you can add your own compliments without removing the default ones~ +.br +* \fIMOMMY_ENCOURAGEMENTS\fP is the encouragement \fBmommy\fP should give you if you need help~ +.br +* \fIMOMMY_ENCOURAGEMENTS_EXTRA\fP is where you can add your own encouragements without removing the default ones~ +.br +all these options take a /-separated list, and \fBmommy\fP will select the one they feel like using whenever they talk +to you~ .PP -For example, if the file -.I ~/.config/mommy/config.sh -looks like +in custom compliments and encouragements, you can ask \fBmommy\fP to use variables \fI%%PET_NAME%%\fP, +\fI%%PRONOUN%%\fP, and \fI%%ROLE%%\fP~ +be careful with trailing newlines because \fBmommy\fP doesn't remove those for you~ +.PP +for example, if the file \fI~/.config/mommy/config.sh\fP looks like .RS -.TS -tab (@); -l lx. -MOMMY_LITTLE=@boy/pet/baby -MOMMY_PRONOUNS=@his/their -MOMMY_ROLES=@daddy -.TE +.br +\fIMOMMY_PET_NAME\fP="boy/pet/baby" +.br +\fIMOMMY_PRONOUN\fP="his/their" +.br +\fIMOMMY_ROLE\fP="daddy" +.br +\fIMOMMY_SUFFIX\fP="~/ :3/" +.br +\fIMOMMY_COMPLIMENTS_EXTRA\fP="great job little %%PET_NAME%%/%%ROLE%% is proud of you" +.br +\fIMOMMY_ENCOURAGEMENTS_EXTRA\fP="\\ +.br +%%ROLE%% is here for you\\ +.br +/%%ROLE%% will always love you\\ +.br +/%%ROLE%% is here if you want a hug" .RE +then \fBmommy\fP might compliment you with any of +.br +* daddy loves his little baby~ +.br +* great job little baby :3 +.br +* daddy is proud of you +.br +and so on~ + + +.SH EXAMPLES +.PP +$ mommy true +.br +Good girl~ + +.PP +$ mommy false +.br +Mommy believes in you~ -then -.B mommy -might say any of -.TS -tab (@); -l lx. -*@T{ -daddy loves his little baby~ ❤ -T} -*@T{ -daddy loves their little pet~ ❤ -T} -*@T{ -daddy loves their little boy~ ❤ -T} -.TE +.PP +$ false || mommy +.br +Good girl~ + +.PP +$ true && mommy +.br +Mommy believes in you~ + +.PP +$ command1 | command2 | command 3 | command 4 || ./mommy -1 && ./mommy -0 +.br +[if any command fails] +.br +Mommy believes in you~ + +.PP +$ command1 | command2 | command 3 | command 4 || ./mommy -1 && ./mommy -0 +.br +[if all commands succeed] +.br +Good girl~ .SH BUGS From f43854b885dc1413972aab2f6c2ed1ac0b5deab4 Mon Sep 17 00:00:00 2001 From: "Florine W. Dekker" Date: Sun, 29 Jan 2023 17:24:06 +0100 Subject: [PATCH 3/6] =?UTF-8?q?mommy=20updated=20the=20readme=20just=20for?= =?UTF-8?q?=20you~=20=F0=9F=A4=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 138 ++++++++++++++++++++++++++++++++-------------------- src/mommy | 34 ++++++------- src/mommy.1 | 15 +++--- 3 files changed, 109 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index 6c14bf0..b55eff8 100644 --- a/README.md +++ b/README.md @@ -1,75 +1,105 @@ # mommy mommy's here to support you~ ❤️ -mommy was inspired by [cargo-mommy](https://github.com/Gankra/cargo-mommy)~ - -## Installation -download the [latest release](https://github.com/FWDekker/mommy/releases/latest) for your platform and install as usual~ - -for example, on Debian-like systems (including Ubuntu), run -```shell -sudo apt install ./mommy-0.0.2.deb -``` - -## Usage -run any command you want, but prepend it with `mommy`~ - ```shell -$> mommy npm test - -> little-girls-tests@1.4.13 test -> mocha -r ts-node/register -r jsdom-global/register src/**/*.spec.ts - - +$ mommy npm test - my tests :3 - 1) maths +[bunch of failing tests here] +mommy knows her little girl can do better~ +``` - 0 passing (8ms) - 1 failing - - 1) my tests :3 - maths: - - AssertionError: expected 7 to equal 6 - + expected - actual - - -7 - +6 - - at Context. (src/test/Path.spec.ts:10:26) - at processImmediate (node:internal/timers:471:21) +## description +put `mommy` before any command you want to run and mommy displays a compliment if it succeeds and an encouraging message +if it fails~ + +alternatively, mommy will compliment you if you run `mommy -0`, and will encourage you if you run `mommy -1`~ + +mommy will carefully read the following variables from `~/.config/mommy/config.sh` 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_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~ +* `MOMMY_COMPLIMENTS` is the compliment mommy should give you if you did a good job~ +* `MOMMY_COMPLIMENTS_EXTRA` is where you can add your own compliments without removing the default ones~ +* `MOMMY_ENCOURAGEMENTS` is the encouragement mommy should give you if you need help~ +* `MOMMY_ENCOURAGEMENTS_EXTRA` is where you can add your own encouragements without removing the default ones~ + +all these options take a `/`-separated list, and mommy will select the one they feel like using whenever they talk +to you~ + +in custom compliments and encouragements, you can ask mommy to use variables `%%PET_NAME%%`, `%%PRONOUN%%`, and +`%%ROLE%%`~ +be careful with trailing newlines because mommy doesn't remove those for you~ + +for example, if the file `~/.config/mommy/config.sh` looks like +```shell script +MOMMY_PET_NAME="boy/pet/baby" +MOMMY_PRONOUN="his/their" +MOMMY_ROLE="daddy" +MOMMY_SUFFIX="~/ :3/" +MOMMY_COMPLIMENTS_EXTRA="great job little %%PET_NAME%%/%%ROLE%% 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" +``` +then mommy might compliment you with any of +* daddy loves his little baby~ +* great job little baby :3 +* daddy is proud of you +and so on~ +## examples +```shell +$ mommy true +good girl~ +``` +```shell +$ mommy false +mommy knows her little girl can do better~ +``` -mommy knows her little girl can do better~ ❤ +```shell +$ false || mommy +good girl~ +``` +```shell +$ true && mommy +mommy knows her little girl can do better~ ``` -## Configuration -Mommy will carefully read `~/.config/mommy/config.sh` to give you the bestest messages~ ❤ +```shell +$ command1 | command2 | command 3 | command 4 || ./mommy -1 && ./mommy -0 +[if any command fails] +mommy knows her little girl can do better~ +``` -* `MOMMY_LITTLE` is what mommy calls you~ (default: "girl") -* `MOMMY_PRONOUNS` is what mommy uses for themselves~ (default: "her") -* `MOMMY_ROLES` is what mommy's role will be~ (default: "mommy") +```shell +$ command1 | command2 | command 3 | command 4 || ./mommy -1 && ./mommy -0 +[if all commands succeed] +good girl~ +``` -All these options can take a `/`-separated list, and mommy will select the one she feels like using whenever she talks to you~ +## installation +download the [latest release](https://github.com/FWDekker/mommy/releases/latest) for your platform and install as usual~ -For example, if the file `~/.config/mommy/config.sh` looks like +for example, on Debian-like systems (including Ubuntu), run ```shell -MOMMY_LITTLE=boy/pet/baby -MOMMY_PRONOUNS=his/their -MOMMY_ROLES=daddy +sudo apt install ./mommy-0.0.2.deb ``` -then mommy might say any of -* `daddy loves his little baby~ ❤` -* `daddy loves their little pet~ ❤` -* `daddy loves their little boy~ ❤` -## Development -All you need to build your own mommy is `build-essential`, `rpm`, and `squashfs-tools`, and then you just run `build.sh`~ +and then run `mommy [your command]`~ + +## development +all you need to build your own mommy is `build-essential`, `rpm`, and `squashfs-tools`, and then you just run +`build.sh`~ +make sure to update the `version` file first though~ -## Acknowledgements -Mommy was very much inspired by [cargo-mommy](https://github.com/Gankra/cargo-mommy)~ +## acknowledgements +mommy was very much inspired by [cargo-mommy](https://github.com/Gankra/cargo-mommy)~ diff --git a/src/mommy b/src/mommy index f3595f5..9d1d9ec 100755 --- a/src/mommy +++ b/src/mommy @@ -33,35 +33,36 @@ MOMMY_ENCOURAGEMENTS_EXTRA="" ## Functions -# Reads stdin; if `$1` is `0`, the first character is changed to lowercase, otherwise the first character is changed to -# uppercase; and writes to stdout. +# Reads stdin; if `$1` is `0`, the first character is changed to lowercase, if `$1` is `1`, the first character is +# changed to uppercase, otherwise nothing is changed; and writes to stdout. capitalize() { input=$(cat) if [ "$1" -eq "0" ]; then from="[:upper:]" to="[:lower:]" - else + elif [ "$1" -eq "1" ]; then from="[:lower:]" to="[:upper:]" + else + echo "$input" + return 0 fi echo "$(echo "$input" | cut -c 1 | tr "$from" "$to")$(echo "$input" | cut -c 2-)" return 0 } -# Splits stdin by `/`, and writes a random part to stdout. +# Splits `$1` by `/`, and writes a random part to stdout. choose_random() { - list=$(cat) - - count=$(echo "$list/" | grep -o "/" | wc -l) + count=$(echo "$1/" | grep -o "/" | wc -l) idx=$(shuf -i 1-"$count" -n 1) - echo "$list" | cut -d "/" -f "$idx" + echo "$1" | cut -d "/" -f "$idx" return 0 } -# Joins all input arguments using `/` as the delimiter and writes to stdout, removes consecutive `/`s, and removes -# leading and trailing `/`es. Respects the word splitting of the inputs to determine where to place the delimiter. +# Joins all input arguments using `/` as the delimiter, removes consecutive `/`s, removes leading and trailing `/`es, +# and writes to stdout. Respects the word splitting of the inputs to determine where to place the delimiter. join_by_slash() { printf "%s/" "$@" | tr -s "/" | sed -e "1h;2,\$H;\$!d;g" -e "s/^\/*//" -e "s/\/*$//" return 0 @@ -95,13 +96,13 @@ compliments=$(join_by_slash "$MOMMY_COMPLIMENTS" "$MOMMY_COMPLIMENTS_EXTRA") encouragements=$(join_by_slash "$MOMMY_ENCOURAGEMENTS" "$MOMMY_ENCOURAGEMENTS_EXTRA") # Randomize -pet_name=$(echo "$MOMMY_PET_NAME" | choose_random) -pronoun=$(echo "$MOMMY_PRONOUN" | choose_random) -role=$(echo "$MOMMY_ROLE" | choose_random) -suffix=$(echo "$MOMMY_SUFFIX" | choose_random) +pet_name=$(choose_random "$MOMMY_PET_NAME") +pronoun=$(choose_random "$MOMMY_PRONOUN") +role=$(choose_random "$MOMMY_ROLE") +suffix=$(choose_random "$MOMMY_SUFFIX") -compliment=$(echo "$compliments" | choose_random | fill_template_with_globals) -encouragement=$(echo "$encouragements" | choose_random | fill_template_with_globals) +compliment=$(choose_random "$compliments" | fill_template_with_globals) +encouragement=$(choose_random "$encouragements" | fill_template_with_globals) ## Output @@ -116,7 +117,6 @@ elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then local_man_path="$(dirname -- "$0")/mommy.1" if [ -f "$local_man_path" ]; then - echo "" man -l "$local_man_path" | cat return 0 elif [ -f "$global_man_path" ]; then diff --git a/src/mommy.1 b/src/mommy.1 index e311d3c..225ecc9 100644 --- a/src/mommy.1 +++ b/src/mommy.1 @@ -31,7 +31,8 @@ messages~ ❤ .br * \fIMOMMY_SUFFIX\fP is how \fBmommy\fP will end all their messages~ .br -* \fIMOMMY_CAPITALIZE\fP is `0` if \fBmommy\fP should start her sentences in lowercase, and `1` for uppercase~ +* \fIMOMMY_CAPITALIZE\fP is `0` if \fBmommy\fP should start her sentences in lowercase, `1` for uppercase, and anything +else to change nothing~ .br * \fIMOMMY_COMPLIMENTS\fP is the compliment \fBmommy\fP should give you if you did a good job~ .br @@ -86,36 +87,36 @@ and so on~ .PP $ mommy true .br -Good girl~ +good girl~ .PP $ mommy false .br -Mommy believes in you~ +mommy knows her little girl can do better~ .PP $ false || mommy .br -Good girl~ +good girl~ .PP $ true && mommy .br -Mommy believes in you~ +mommy knows her little girl can do better~ .PP $ command1 | command2 | command 3 | command 4 || ./mommy -1 && ./mommy -0 .br [if any command fails] .br -Mommy believes in you~ +mommy knows her little girl can do better~ .PP $ command1 | command2 | command 3 | command 4 || ./mommy -1 && ./mommy -0 .br [if all commands succeed] .br -Good girl~ +good girl~ .SH BUGS From 3e438f60869526d938fec9b3c70b71fcd31c7917 Mon Sep 17 00:00:00 2001 From: "Florine W. Dekker" Date: Sun, 29 Jan 2023 17:44:30 +0100 Subject: [PATCH 4/6] =?UTF-8?q?mommy=20now=20takes=20a=20custom=20config?= =?UTF-8?q?=20file~=20=F0=9F=96=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++-- src/mommy | 40 +++++++++++++++++++++++++++++++++------- src/mommy.1 | 12 ++++++------ 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b55eff8..cc46b22 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ if it fails~ alternatively, mommy will compliment you if you run `mommy -0`, and will encourage you if you run `mommy -1`~ -mommy will carefully read the following variables from `~/.config/mommy/config.sh` to give you the bestest messages~ ❤ +mommy will carefully read the following variables from `~/.config/mommy/config.sh` (override using `mommy -c ./my_file`) +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~ @@ -34,7 +35,7 @@ in custom compliments and encouragements, you can ask mommy to use variables `%% `%%ROLE%%`~ be careful with trailing newlines because mommy doesn't remove those for you~ -for example, if the file `~/.config/mommy/config.sh` looks like +for example, if the config file looks like ```shell script MOMMY_PET_NAME="boy/pet/baby" MOMMY_PRONOUN="his/their" diff --git a/src/mommy b/src/mommy index 9d1d9ec..001e2c1 100755 --- a/src/mommy +++ b/src/mommy @@ -1,8 +1,12 @@ #!/bin/sh ## Defaults +### Options MOMMY_CONFIG_FILE="$HOME/.config/mommy/config.sh" +MOMMY_FORCE_COMPLIMENT="0" +MOMMY_FORCE_ENCOURAGEMENT="0" +### Configuration MOMMY_PET_NAME="girl" MOMMY_PRONOUN="her" MOMMY_ROLE="mommy" @@ -88,6 +92,27 @@ fill_template_with_globals() { } +## Read options +while getopts ":01c:" OPTION; do + case "$OPTION" in + 0) + MOMMY_FORCE_COMPLIMENT="1" + ;; + + 1) + MOMMY_FORCE_ENCOURAGEMENT="1" + ;; + + c) + MOMMY_CONFIG_FILE="$OPTARG" + ;; + + ?) + ;; + esac +done + + ## Load configuration # shellcheck source=/dev/null test -f "$MOMMY_CONFIG_FILE" && . "$MOMMY_CONFIG_FILE" @@ -106,13 +131,7 @@ encouragement=$(choose_random "$encouragements" | fill_template_with_globals) ## Output -if [ "$1" = "-0" ]; then - echo "$compliment" - return 0 -elif [ "$1" = "-1" ]; then - echo "$encouragement" >&2 - return 1 -elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then global_man_path="/usr/share/man/man1/mommy.1" local_man_path="$(dirname -- "$0")/mommy.1" @@ -126,7 +145,14 @@ elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "%%ROLE%% could not find the manual for %%PRONOUN%% little %%PET_NAME%%" | fill_template_with_globals >&2 return 1 fi +elif [ "$MOMMY_FORCE_COMPLIMENT" = "1" ]; then + echo "$compliment" + return 0 +elif [ "$MOMMY_FORCE_ENCOURAGEMENT" = "1" ]; then + echo "$encouragement" >&2 + return 1 else + shift "$((OPTIND -1))" "$@" command_exit_code=$? diff --git a/src/mommy.1 b/src/mommy.1 index 225ecc9..557732d 100644 --- a/src/mommy.1 +++ b/src/mommy.1 @@ -6,11 +6,11 @@ mommy - here to support you~ .SH SYNOPSIS -\fBmommy\fP [\fIcommand\fP] +\fBmommy\fP [\fB\-c\fP \fIconfig\fP] [\fIcommand\fP] .br -\fBmommy\fP \fB-0\fP +\fBmommy\fP [\fB\-c\fP \fIconfig\fP] \fB-0\fP .br -\fBmommy\fP \fB-1\fP +\fBmommy\fP [\fB\-c\fP \fIconfig\fP] \fB-1\fP .SH DESCRIPTION @@ -20,8 +20,8 @@ mommy - here to support you~ alternatively, \fBmommy\fP will compliment you if you set \fI-0\fP, and will encourage you if you set \fI-1\fP~ .PP -\fBmommy\fP will carefully read the following variables from \fI~/.config/mommy/config.sh\fP to give you the bestest -messages~ ❤ +\fBmommy\fP will carefully read the following variables from \fI~/.config/mommy/config.sh\fP (override with +\fIconfig\fP) to give you the bestest messages~ ❤ .br * \fIMOMMY_PET_NAME\fP is what \fBmommy\fP calls you~ .br @@ -51,7 +51,7 @@ in custom compliments and encouragements, you can ask \fBmommy\fP to use variabl be careful with trailing newlines because \fBmommy\fP doesn't remove those for you~ .PP -for example, if the file \fI~/.config/mommy/config.sh\fP looks like +for example, if the \fIconfig\fP looks like .RS .br \fIMOMMY_PET_NAME\fP="boy/pet/baby" From b03e56ae2a85bd882ab50f382d2c626aedab4c8d Mon Sep 17 00:00:00 2001 From: "Florine W. Dekker" Date: Sun, 29 Jan 2023 21:31:19 +0100 Subject: [PATCH 5/6] =?UTF-8?q?mommy=20has=20been=20tested=20now~=20?= =?UTF-8?q?=F0=9F=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .shellspec | 1 + README.md | 79 +++++---- build.sh | 3 +- src/{ => main/resources}/mommy.1 | 25 +-- src/{ => main/sh}/mommy | 53 +++--- src/test/sh/mommy_spec.sh | 268 +++++++++++++++++++++++++++++++ 6 files changed, 339 insertions(+), 90 deletions(-) create mode 100644 .shellspec rename src/{ => main/resources}/mommy.1 (80%) rename src/{ => main/sh}/mommy (84%) create mode 100755 src/test/sh/mommy_spec.sh diff --git a/.shellspec b/.shellspec new file mode 100644 index 0000000..6e764f3 --- /dev/null +++ b/.shellspec @@ -0,0 +1 @@ +--execdir @specfile diff --git a/README.md b/README.md index cc46b22..6bac3ec 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,37 @@ $ mommy npm test mommy knows her little girl can do better~ ``` -## description +## usage put `mommy` before any command you want to run and mommy displays a compliment if it succeeds and an encouraging message if it fails~ -alternatively, mommy will compliment you if you run `mommy -0`, and will encourage you if you run `mommy -1`~ +alternatively, use `mommy -e` to evaluate the string as a command, as in `mommy -e "npm test"`~ -mommy will carefully read the following variables from `~/.config/mommy/config.sh` (override using `mommy -c ./my_file`) +```shell +$ mommy true +good girl~ +``` + +```shell +$ mommy false +mommy knows her little girl can do better~ +``` + +```shell +$ mommy -e "command1 | command2 | command 3 | command 4" +[if any command fails] +mommy knows her little girl can do better~ +``` + +```shell +$ mommy -e "command1 | command2 | command 3 | command 4" +[if all commands succeed] +good girl~ +``` + +## configuration +mommy will carefully read the following variables from `~/.config/mommy/config.sh` (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~ @@ -43,7 +67,7 @@ MOMMY_ROLE="daddy" MOMMY_SUFFIX="~/ :3/" MOMMY_COMPLIMENTS_EXTRA="great job little %%PET_NAME%%/%%ROLE%% is proud of you" MOMMY_ENCOURAGEMENTS_EXTRA="\ -%%ROLE%% is here for you\ +/%%ROLE%% is here for you\ /%%ROLE%% will always love you\ /%%ROLE%% is here if you want a hug" ``` @@ -54,39 +78,6 @@ then mommy might compliment you with any of and so on~ -## examples -```shell -$ mommy true -good girl~ -``` - -```shell -$ mommy false -mommy knows her little girl can do better~ -``` - -```shell -$ false || mommy -good girl~ -``` - -```shell -$ true && mommy -mommy knows her little girl can do better~ -``` - -```shell -$ command1 | command2 | command 3 | command 4 || ./mommy -1 && ./mommy -0 -[if any command fails] -mommy knows her little girl can do better~ -``` - -```shell -$ command1 | command2 | command 3 | command 4 || ./mommy -1 && ./mommy -0 -[if all commands succeed] -good girl~ -``` - ## installation download the [latest release](https://github.com/FWDekker/mommy/releases/latest) for your platform and install as usual~ @@ -98,9 +89,17 @@ sudo apt install ./mommy-0.0.2.deb and then run `mommy [your command]`~ ## development -all you need to build your own mommy is `build-essential`, `rpm`, and `squashfs-tools`, and then you just run -`build.sh`~ -make sure to update the `version` file first though~ +to build your own mommy, just run `./build.sh`, and outputs appear in `dist/`~ + +to install the requirements on a Debian-like machine, run +```shell +sudo gem install fpm +sudo apt install build-essential squashfs-tools rpm +``` + +for a new release, make sure to update `./version` and update the date in `src/main/resources/mommy.1`~ + +to run tests, install [shellspec](https://github.com/shellspec/shellspec) and run `shellspec src/test/sh/mommy_spec.sh`~ ## acknowledgements mommy was very much inspired by [cargo-mommy](https://github.com/Gankra/cargo-mommy)~ diff --git a/build.sh b/build.sh index c6887ca..f98148c 100755 --- a/build.sh +++ b/build.sh @@ -9,7 +9,8 @@ rm -rf build/ rm -rf dist/ # Prepare build -cp -r src/ build/ +cp -r src/main/sh/ build/ +cp -r src/main/resources/ build/ find build/ -type f -exec sed -i "s/%%VERSION_NUMBER%%/$version/g" {} \; # Build packages diff --git a/src/mommy.1 b/src/main/resources/mommy.1 similarity index 80% rename from src/mommy.1 rename to src/main/resources/mommy.1 index 557732d..132d534 100644 --- a/src/mommy.1 +++ b/src/main/resources/mommy.1 @@ -1,4 +1,4 @@ -.TH MOMMY "1" "2023-01-25" "mommy %%VERSION_NUMBER%%" "User Commands" +.TH MOMMY "1" "2023-01-29" "mommy %%VERSION_NUMBER%%" "User Commands" .SH NAME @@ -6,18 +6,15 @@ mommy - here to support you~ .SH SYNOPSIS -\fBmommy\fP [\fB\-c\fP \fIconfig\fP] [\fIcommand\fP] +\fBmommy\fP [\fB\-c\fP \fIconfig\fP] \fIcommand\fP ... .br -\fBmommy\fP [\fB\-c\fP \fIconfig\fP] \fB-0\fP -.br -\fBmommy\fP [\fB\-c\fP \fIconfig\fP] \fB-1\fP +\fBmommy\fP [\fB\-c\fP \fIconfig\fP] \fB-e\fP \fIeval\fP .SH DESCRIPTION \fBmommy\fP displays a compliment when \fIcommand\fP succeeds and an encouraging message when \fIcommand\fP fails~ -.PP -alternatively, \fBmommy\fP will compliment you if you set \fI-0\fP, and will encourage you if you set \fI-1\fP~ +alternatively, instead of running the vararg \fIcommand\fP, \fBmommy\fP evaluates the command in \fIeval\fP .PP \fBmommy\fP will carefully read the following variables from \fI~/.config/mommy/config.sh\fP (override with @@ -95,24 +92,14 @@ $ mommy false mommy knows her little girl can do better~ .PP -$ false || mommy -.br -good girl~ - -.PP -$ true && mommy -.br -mommy knows her little girl can do better~ - -.PP -$ command1 | command2 | command 3 | command 4 || ./mommy -1 && ./mommy -0 +$ mommy "command1 | command2 | command 3 | command 4" .br [if any command fails] .br mommy knows her little girl can do better~ .PP -$ command1 | command2 | command 3 | command 4 || ./mommy -1 && ./mommy -0 +$ mommy "command1 | command2 | command 3 | command 4" .br [if all commands succeed] .br diff --git a/src/mommy b/src/main/sh/mommy similarity index 84% rename from src/mommy rename to src/main/sh/mommy index 001e2c1..4222ad1 100755 --- a/src/mommy +++ b/src/main/sh/mommy @@ -3,8 +3,8 @@ ## Defaults ### Options MOMMY_CONFIG_FILE="$HOME/.config/mommy/config.sh" -MOMMY_FORCE_COMPLIMENT="0" -MOMMY_FORCE_ENCOURAGEMENT="0" +MOMMY_HELP="" +MOMMY_EVAL="" ### Configuration MOMMY_PET_NAME="girl" @@ -14,7 +14,7 @@ MOMMY_SUFFIX="~ ❤️" MOMMY_CAPITALIZE="0" MOMMY_COMPLIMENTS="\ -good %%PET_NAME%%\ +/good %%PET_NAME%%\ /that's a good %%PET_NAME%%\ /%%ROLE%% is so proud of you\ /%%ROLE%% thinks you deserve a special treat for that\ @@ -24,13 +24,13 @@ good %%PET_NAME%%\ " MOMMY_COMPLIMENTS_EXTRA="" MOMMY_ENCOURAGEMENTS="\ -%%ROLE%% knows %%PRONOUN%% little %%PET_NAME%% can do better\ +/%%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 I will be here for you\ +/%%ROLE%% promises whatever happens %%ROLE%% will be here for you\ /%%ROLE%% believes in you because you're my good %%PET_NAME%%\ " MOMMY_ENCOURAGEMENTS_EXTRA="" @@ -93,25 +93,21 @@ fill_template_with_globals() { ## Read options -while getopts ":01c:" OPTION; do - case "$OPTION" in - 0) - MOMMY_FORCE_COMPLIMENT="1" - ;; - - 1) - MOMMY_FORCE_ENCOURAGEMENT="1" - ;; - - c) - MOMMY_CONFIG_FILE="$OPTARG" - ;; +if [ "$1" = "--help" ]; then + MOMMY_HELP="1" +fi - ?) - ;; +while getopts ":hc:e:" OPTION; do + case "$OPTION" in + h) MOMMY_HELP="1" ;; + c) MOMMY_CONFIG_FILE="$OPTARG" ;; + e) MOMMY_EVAL="$OPTARG" ;; + ?) ;; esac done +shift "$((OPTIND -1))" + ## Load configuration # shellcheck source=/dev/null @@ -131,9 +127,9 @@ encouragement=$(choose_random "$encouragements" | fill_template_with_globals) ## Output -if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then +if [ -n "$MOMMY_HELP" ]; then global_man_path="/usr/share/man/man1/mommy.1" - local_man_path="$(dirname -- "$0")/mommy.1" + local_man_path="$(dirname -- "$0")/../resources/mommy.1" if [ -f "$local_man_path" ]; then man -l "$local_man_path" | cat @@ -145,15 +141,12 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "%%ROLE%% could not find the manual for %%PRONOUN%% little %%PET_NAME%%" | fill_template_with_globals >&2 return 1 fi -elif [ "$MOMMY_FORCE_COMPLIMENT" = "1" ]; then - echo "$compliment" - return 0 -elif [ "$MOMMY_FORCE_ENCOURAGEMENT" = "1" ]; then - echo "$encouragement" >&2 - return 1 else - shift "$((OPTIND -1))" - "$@" + if [ -n "$MOMMY_EVAL" ]; then + (eval "$MOMMY_EVAL") + else + ("$@") + fi command_exit_code=$? if [ $command_exit_code -eq 0 ]; then diff --git a/src/test/sh/mommy_spec.sh b/src/test/sh/mommy_spec.sh new file mode 100755 index 0000000..4d04ca6 --- /dev/null +++ b/src/test/sh/mommy_spec.sh @@ -0,0 +1,268 @@ +Describe "mommy" + config="./config" + mommy="../../main/sh/mommy" + + clean_config() { rm -f "$config"; } + After "clean_config" + + Describe "command line options" + Describe "help information" + It "outputs help information using -h" + When run "$mommy" -h + The word 1 of output should equal "MOMMY(1)" + The status should be success + End + + It "outputs help information using --help" + When run "$mommy" --help + The word 1 of output should equal "MOMMY(1)" + The status should be success + End + + It "outputs help information even when -h is not the first option" + When run "$mommy" -c "./a_file" -h + The word 1 of output should equal "MOMMY(1)" + The status should be success + End + End + + Describe "custom configuration file" + It "ignores an invalid path" + When run "$mommy" -c "./does_not_exist" true + The output should not equal "" + The status should be success + End + + It "uses the configuration from the given file" + echo "MOMMY_COMPLIMENTS='apply news';MOMMY_SUFFIX=''" > "$config" + + When run "$mommy" -c "$config" true + The output should equal "apply news" + The status should be success + End + End + + Describe "command" + It "writes a compliment to stdout if the command returns 0 status" + echo "MOMMY_COMPLIMENTS='purpose wall';MOMMY_SUFFIX=''" > "$config" + + When run "$mommy" -c "$config" true + The output should equal "purpose wall" + The status should be success + End + + It "writes an encouragement to stderr if the command returns non-0 status" + echo "MOMMY_ENCOURAGEMENTS='razor woolen';MOMMY_SUFFIX=''" > "$config" + + When run "$mommy" -c "$config" false + The error should equal "razor woolen" + The status should be failure + End + + It "returns the non-0 status of the command" + When run "$mommy" return 4 + The error should not equal "" + The status should equal 4 + End + + It "passes all arguments to the command" + echo "MOMMY_COMPLIMENTS='disagree mean';MOMMY_SUFFIX=''" > "$config" + + When run "$mommy" -c "$config" echo a b c + The line 1 of output should equal "a b c" + The line 2 of output should equal "disagree mean" + The status should be success + End + End + + Describe "eval" + It "writes a compliment to stdout if the evaluated command returns 0 status" + echo "MOMMY_COMPLIMENTS='bold accord';MOMMY_SUFFIX=''" > "$config" + + When run "$mommy" -c "$config" -e "true" + The output should equal "bold accord" + The status should be success + End + + It "writes an encouragement to stderr if the evaluated command returns non-0 status" + echo "MOMMY_ENCOURAGEMENTS='head log';MOMMY_SUFFIX=''" > "$config" + + When run "$mommy" -c "$config" -e "false" + The error should equal "head log" + The status should be failure + End + + It "returns the non-0 status of the evaluated command" + When run "$mommy" -e "return 4" + The error should not equal "" + The status should equal 4 + End + + It "passes all arguments to the command" + echo "MOMMY_COMPLIMENTS='desire bread';MOMMY_SUFFIX=''" > "$config" + + When run "$mommy" -c "$config" -e "echo a b c" + The line 1 of output should equal "a b c" + The line 2 of output should equal "desire bread" + The status should be success + End + + It "considers the command a success if all parts succeed" + echo "MOMMY_COMPLIMENTS='milk literary';MOMMY_SUFFIX=''" > "$config" + + When run "$mommy" -c "$config" -e "echo 'a/b/c' | cut -d '/' -f 1" + The line 2 of output should equal "milk literary" + The status should be success + End + + It "considers the command a success if any part fails" + echo "MOMMY_ENCOURAGEMENTS='bear cupboard';MOMMY_SUFFIX=''" > "$config" + + When run "$mommy" -c "$config" -e "echo 'a/b/c' | cut -d '/' -f 0" + The line 3 of error should equal "bear cupboard" + The status should be failure + End + End + End + + Describe "configuration" + Describe "template variables" + It "inserts the pet name" + echo "MOMMY_COMPLIMENTS='>%%PET_NAME%%<';MOMMY_SUFFIX='';MOMMY_PET_NAME='attempt'" > "$config" + + When run "$mommy" -c "$config" true + The output should equal ">attempt<" + The status should be success + End + + It "inserts the pronoun" + echo "MOMMY_COMPLIMENTS='>%%PRONOUN%%<';MOMMY_SUFFIX='';MOMMY_PRONOUN='respect'" > "$config" + + When run "$mommy" -c "$config" true + The output should equal ">respect<" + The status should be success + End + + It "inserts the role" + echo "MOMMY_COMPLIMENTS='>%%ROLE%%<';MOMMY_SUFFIX='';MOMMY_ROLE='help'" > "$config" + + When run "$mommy" -c "$config" true + The output should equal ">help<" + The status should be success + End + + It "appends the suffix" + echo "MOMMY_COMPLIMENTS='>';MOMMY_SUFFIX='respect'" > "$config" + + When run "$mommy" -c "$config" true + The output should equal ">respect" + The status should be success + End + + It "chooses a random variable value" + # Probability of 1/(26^4)=1/456976 to fail + + pronouns="a/b/c/d/e/f/g/h/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z" + echo "MOMMY_COMPLIMENTS='>%%PRONOUN%%<';MOMMY_SUFFIX='';MOMMY_PRONOUN='$pronouns'" > "$config" + + output1=$("$mommy" -c "$config" true) + output2=$("$mommy" -c "$config" true) + output3=$("$mommy" -c "$config" true) + output4=$("$mommy" -c "$config" true) + output5=$("$mommy" -c "$config" true) + + [ "$output1" != "$output2" ] || [ "$output1" != "$output3" ] \ + || [ "$output1" != "$output4" ] \ + || [ "$output1" != "$output5" ] + is_different="$?" + + When call test "$is_different" -eq 0 + The status should be success + End + End + + Describe "capitalization" + It "changes to the first character to lowercase if configured to 0" + echo "MOMMY_COMPLIMENTS='Alive station';MOMMY_SUFFIX='';MOMMY_CAPITALIZE='0'" > "$config" + + When run "$mommy" -c "$config" true + The output should equal "alive station" + The status should be success + End + + It "changes to the first character to uppercase if configured to 1" + echo "MOMMY_COMPLIMENTS='inquiry speech';MOMMY_SUFFIX='';MOMMY_CAPITALIZE='1'" > "$config" + + When run "$mommy" -c "$config" true + The output should equal "Inquiry speech" + The status should be success + End + + It "uses the template's original capitalization if configured to anything else" + echo "MOMMY_COMPLIMENTS='Belong shore';MOMMY_SUFFIX='';MOMMY_CAPITALIZE='2'" > "$config" + + When run "$mommy" -c "$config" true + The output should equal "Belong shore" + The status should be success + End + End + + Describe "compliments/encouragements" + It "chooses from 'MOMMY_COMPLIMENTS'" + echo "MOMMY_COMPLIMENTS='spill drown';MOMMY_SUFFIX=''" > "$config" + + When run "$mommy" -c "$config" true + The output should equal "spill drown" + The status should be success + End + + It "chooses from 'MOMMY_COMPLIMENTS_EXTRA'" + echo "MOMMY_COMPLIMENTS='';MOMMY_COMPLIMENTS_EXTRA='bill lump';MOMMY_SUFFIX=''" > "$config" + + When run "$mommy" -c "$config" true + The output should equal "bill lump" + The status should be success + End + + It "ignores leading slashes" + # Probability of ~1/30 to pass if code is buggy + + echo "MOMMY_COMPLIMENTS='/////////////////////////////boy only';MOMMY_SUFFIX=''" > "$config" + + When run "$mommy" -c "$config" true + The output should equal "boy only" + The status should be success + End + + It "ignores trailing slashes" + # Probability of ~1/30 to pass if code is buggy + + echo "MOMMY_COMPLIMENTS='';MOMMY_COMPLIMENTS_EXTRA='salt staff/////////////////////////////';MOMMY_SUFFIX=''" > "$config" + + When run "$mommy" -c "$config" true + The output should equal "salt staff" + The status should be success + End + + It "ignores slashes in the middle" + # Probability of ~1/30 to pass if code is buggy + + echo "MOMMY_COMPLIMENTS='end spring///////////////end spring';MOMMY_SUFFIX=''" > "$config" + + When run "$mommy" -c "$config" true + The output should equal "end spring" + The status should be success + End + + It "ignores slashes in between 'MOMMY_COMPLIMENTS' and 'MOMMY_COMPLIMENTS_EXTRA'" + # Probability of ~1/30 to pass if code is buggy + + echo "MOMMY_COMPLIMENTS='attempt cheap///////////////';MOMMY_COMPLIMENTS_EXTRA='///////////////attempt cheap';MOMMY_SUFFIX=''" > "$config" + + When run "$mommy" -c "$config" true + The output should equal "attempt cheap" + The status should be success + End + End + End +End From 9407dcb6c6c1deff7370cef864f4b5b64efc14b3 Mon Sep 17 00:00:00 2001 From: "Florine W. Dekker" Date: Sun, 29 Jan 2023 21:42:01 +0100 Subject: [PATCH 6/6] =?UTF-8?q?mommy=20explains=20how=20to=20create=20an?= =?UTF-8?q?=20alias~=20=E2=9D=A4=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 19 +++++++++++++++++-- version | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6bac3ec..1f02b1c 100644 --- a/README.md +++ b/README.md @@ -78,16 +78,31 @@ then mommy might compliment you with any of and so on~ +### renaming mommy +if you don't want a mommy but for example a daddy, run the following: +```shell +sudo ln -s /usr/bin/mommy /usr/bin/daddy +sudo ln -s /usr/share/man/man1/mommy.1 /usr/share/man/man1/daddy.1 +``` + +if you update mommy, then your daddy will also be updated, but if you uninstall mommy, you should manually uninstall +your daddy by running +```shell +sudo rm /usr/bin/daddy +sudo rm /usr/share/man/man1/daddy.1 +``` + ## installation download the [latest release](https://github.com/FWDekker/mommy/releases/latest) for your platform and install as usual~ for example, on Debian-like systems (including Ubuntu), run ```shell -sudo apt install ./mommy-0.0.2.deb +sudo apt install ./mommy-0.0.3.deb ``` - and then run `mommy [your command]`~ +to uninstall, just do `sudo apt remove mommy`~ + ## development to build your own mommy, just run `./build.sh`, and outputs appear in `dist/`~ diff --git a/version b/version index 4e379d2..bcab45a 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.0.2 +0.0.3