Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I added a counter for the amount of mistakes the user made #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions src/bash.command-not-found
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@


print_message () {

local messages
local message

messages=(
"u takin to me ?"
"Boooo!"
"Don't you know anything?"
"RTFM!"
Expand Down Expand Up @@ -74,13 +77,38 @@ print_message () {

# Seed RANDOM with an integer of some length
RANDOM=$(od -vAn -N4 -tu < /dev/urandom)


if test -f "/etc/mistakes_counter.txt"; then
declare -i i=`cat /etc/mistakes_counter.txt`
rm "/etc/mistakes_counter.txt"
let "i++"
touch "/etc/mistakes_counter.txt"
echo $i >> "/etc/mistakes_counter.txt"

else
touch "/etc/mistakes_counter.txt"
declare -i i=1
echo $i >> "/etc/mistakes_counter.txt"

fi


# Print a randomly selected message, but only about half the time to annoy the user a
# Medium Mode
# Prints a randomly selected message, but only about half the time to annoy the user a
# little bit less.
if [[ $((${RANDOM} % 2)) -lt 1 ]]; then

if [[ $((${RANDOM} % 2)) -lt 1 ]]; then
message=${messages[${RANDOM} % ${#messages[@]}]}
printf "\\n %s\\n\\n" "$(tput bold)$(tput setaf 1)${message}$(tput sgr0)" >&2
fi
printf "\\n %s\\n\\n" "$(tput bold)$(tput setaf 1)${message}" >&2
printf "\\n %s\\n\\n" "$(tput bold)$(tput setaf 1)Mistakes counter: ${i}$(tput sgr0)"
fi

#Agressive Mode(Always displays an insult)
#message=${messages[${RANDOM} % ${#messages[@]}]}
#printf "\\n %s\\n\\n" "$(tput bold)$(tput setaf 1)${message}$(tput sgr0)" >&2
#printf "\\n %s\\n\\n" "$(tput bold)$(tput setaf 1)Mistakes counter: ${i}$(tput sgr0)"

}

function_exists () {
Expand Down