-
Notifications
You must be signed in to change notification settings - Fork 1
/
lastvice
executable file
·154 lines (154 loc) · 5.6 KB
/
lastvice
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
#
#### lastvice
#### Author- Shawn Miller
#### Friday 15 February 2018
#
###########################################################
## Global Variables and Information Gathering
###########################################################
#
PROGNAME=$(basename $0)
PROGVERS="1.0.1-08"
PROGDATE="2018-02-16"
#
###########################################
#### Declare Color Variables
###########################################
#
RED="$(tput setaf 1)"
GRN="$(tput setaf 2)"
YLLW="$(tput setaf 3)"
BLU="$(tput setaf 4)"
MAG="$(tput setaf 5)"
CYN="$(tput setaf 6)"
LTRED="$(tput setaf 9)"
LTGRN="$(tput setaf 10)"
LTYLLW="$(tput setaf 11)"
LTBLU="$(tput setaf 12)"
LTMAG="$(tput setaf 13)"
LTCYN="$(tput setaf 14)"
BGBLU="$(tput setab 4)"
BGYLLW="$(tput setab 3)"
BGLYLLW="$(tput setab 11)"
ULINE="$(tput smul)"
NULINE="$(tput rmul)"
SOMODE="$(tput smso)"
NSOMODE="$(tput rmso)"
BOLD="$(tput bold)"
RESET="$(tput sgr0)"
#
###########################################################
## Script Options/Usage
###########################################################
#
usage () {
clear
cat <<EOT
${BOLD}${YLLW}Description-${RESET}${LTCYN}
I started this script shortly after I quit smoking cigarettes and I wanted to keep up with how
many days it had been, everything was 'hard-coded' with my own info. I soon realized that this
could be used for anyone and for any bad habit or vice that had been broken.${BOLD}
Options-${RESET}${LTYLLW}
${ULINE}OPTION Description Long Description ${NULINE}${RESET}${LTCYN}
[help]${GRN} Help${YLLW} Show this output and exit${LTCYN}
[]${GRN} None${YLLW} Will default to MY original hard-coded arguments${LTCYN}
[${YLLW}<yourname>${LTCYN}]${GRN} Your Name${YLLW} Put your name as the ${BOLD}${ULINE}${LTCYN}FIRST${NULINE}${RESET}${YLLW} argument, Can be${LTCYN} Shawn${YLLW} or${LTCYN} "Shawn Miller"${LTCYN}
[${YLLW}<quitdate>${LTCYN}]${GRN} Quit Date${YLLW} Put your quit date as the ${BOLD}${ULINE}${LTCYN}SECOND${NULINE}${RESET}${YLLW} argument, as${BOLD}${LTCYN} YYYY-MM-DD${RESET}${LTYLLW}
${ULINE}Optional${NULINE}-${RESET}${LTYLLW} The following arguments are optional, Default vice is "a cigarette"${LTCYN}
[${YLLW}<yourvice>${LTCYN}]${GRN} Your Vice${YLLW} Optional- Put your Vice/Bad-Habit as the ${BOLD}${ULINE}${LTCYN}THIRD${NULINE}${RESET}${YLLW} argument,
Can be${LTCYN} drinking${YLLW} or${LTCYN} "drinking soda"${YLLW}${LTCYN}
[months]${GRN} Number Months${LTRED} (Option Not Available Yet!)${LTCYN}
[years]${GRN} Number Years${LTRED} (Option Not Available Yet!)${BOLD}${YLLW}
Usage-${RESET}${GRN}
./${PROGNAME}${LTCYN} [OPTION] [${YLLW}<YourName${LTCYN}|${YLLW}"Your Name">${LTCYN}] [YYYY-MM-DD] [${YLLW}<"Your Vice">${LTCYN}] [months|years]${YLLW}
Example-${GRN}
./$PROGNAME "Shawn Miller" 2018-11-19
./$PROGNAME "Shawn Miller" 2018-11-19 "Drinking Dr. Pepper!"${YLLW}
Feedback, Questions, Bugs- ${LTBLU}[email protected]${YLLW}
Github-${LTBLU} https://github.com/SeaPhor${RESET}
EOT
}
#
###########################################
#### Declare Arg Checks
###########################################
#
[[ $@ =~ "help" ]] && { usage; exit 0; }
#[[ $@ =~ "nocolor" ]] &&i NOCOLR=true || NOCOLR=false
[[ ! $2 ]] && quitdate="2018-11-19" || quitdate=$2
[[ ! $1 ]] && quitter="Shawn Miller" || quitter=$1
if [[ "`echo $3`" != "" ]]; then
if [[ $(echo $3) == "months" ]]; then
mywhat="a cigarette!!!"
elif [[ $(echo $3) == "years" ]]; then
mywhat="a cigarette!!!"
else
mywhat=$3
fi
else
mywhat="a cigarette!!!"
fi
[[ $@ =~ "months" ]] && months=true || months=false
[[ $@ =~ "years" ]] && months=true || years=false
#
###########################################
#### Environment Variables and Information Gathering
###########################################
#
declare -i numdays=$(echo $((($(date +%s --date $quitdate)-$(date +%s))/(3600*24))) | sed 's/[^0-9]//g')
if [[ $numdays -ge 180 ]]; then
allrt_clr="${BOLD}${GRN}${SOMODE}${ULINE}"
else
if [[ $numdays -le "179" ]]; then
if [[ $numdays -le "89" ]]; then
allrt_clr="${BOLD}${RED}${ULINE}"
else
allrt_clr="${BOLD}${YLLW}${ULINE}"
fi
fi
fi
#
[[ $months ]] && numonths="$(expr $numdays '/' 30)"
[[ $years ]] && numyears="$(expr $numdays '/' 365)"
#
###########################################
#### Declare Functions
###########################################
#
norm_print () {
echo -e "\n${BOLD}${GRN}${quitter}${RESET}${YLLW} has gone${BOLD}${CYN} =====>>>>> ${allrt_clr}${numdays}${NULINE}${NSOMODE}${RESET}${BOLD}${CYN} <<<<<=====${RESET}${LTYLLW} Days without ${mywhat}\n${RESET}"
}
#
so_print () {
echo -e "\n${SOMODE}${BOLD}${GRN}${quitter}${RESET}${SOMODE}${YLLW} has gone${BOLD}${CYN} =====>>>>> ${allrt_clr}${numdays}${NULINE}${RESET}${SOMODE}${BOLD}${CYN} <<<<<=====${RESET}${SOMODE}${LTYLLW} Days without ${mywhat}\n${NSOMODE}${RESET}"
}
#
declare -i times=10
declare -i count=0
if [[ $numdays -ge 90 ]]; then
until (( times == count )); do
clear
norm_print
sleep .5
clear
so_print
sleep .5
((++count))
done
else
norm_print
fi
#
if $months; then
echo -e "${BOLD}${allrt_clr}${numonths} Months\n${RESET}"
fi
if $years; then
echo -e "${BOLD}${allrt_clr}${numyears} Years\n${RESET}"
fi
toilet -f mono12 -F metal SeaPhor
#
exit 0
#
#### Reference: https://linuxconfig.org/how-to-count-days-since-a-specific-date-until-today-using-bash-shell
#