Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#!/usr/bin/env bash
#########################################################
# calendrier - Tool for managing calendars #
# Author: Someone Someone S #
# Version: 2.0.0 #
# Usage: calendrier [ACTION] [DAY] #
# #
# #
# #
# #
# #
# #
# #
# #
# #
#########################################################
grep -q help <<<$@ && (
echo "=========================================================================================="
echo "calendrier - Tool for managing time in a shell calendar program"
echo "Author: Someone"
echo "Version: 2.0.0"
echo "Usage: calendrier [add, delete, show, urgent, now, gui] [today, tomorrow, yesterday, MM-DD-YYYY]"
echo "==========================================================================================="
)
echo -e "\e[0;32mSetting colors\e[0m"
Color_Off='\e[0m' # Text Reset
# Regular Colors
Black='\e[0;30m' # Black
Red='\e[0;31m' # Red
Green='\e[0;32m' # Green
Yellow='\e[0;33m' # Yellow
Blue='\e[0;34m' # Blue
Purple='\e[0;35m' # Purple
Cyan='\e[0;36m' # Cyan
White='\e[0;37m' # White
if [[ -d ~/.Calendrier ]]
then echo -e "${Green}Found Calendrier profile directory${Color_Off}"
else
mkdir -p ~/.Calendrier
echo -e "${Green}Created Calendrier dir${Color_Off}"
fi
if [ "`echo $@`" = "" ]; then
echo -e "${GREEN}:( Missing arguments${Color_Off}"
fi
case $1 in
add) echo -e ${Green}Adding event...${Color_Off}
echo -e ${Green}Assuming date to be $2 in YYYY-MM-DD${Color_Off}
case $2 in
today) set dateis=`date +%Y-%m-%d`
echo Date is $dateis in YYYY-MM-DD >> ~/.Calendrier/log
read -p "Is this an event, a meeting, appointment, or class? " option
if [ $option == event ]; then
echo -e "${Green}Ah, so it's an event!${Color_Off}"
echo -ne "${Green}What event are you going to? ${Color_Off}"
read whatevent
echo -ne "${Green}What time? ${Color_Off}"
read thetimelol
echo -e "${Green}Cool :), this event will be recorded${Color_Off}"
echo "$dateis at $thetimelol: $whatevent" >> ~/.Calendrier/class
fi
if [ $option == meeting ]; then
echo -e "${Green}Ah, so it's a meeting!${Color_Off}"
echo -ne "${Green}If it is a meeting, who is it with (seperate names with commas)? ${Color_Off}"
read whoisitwith
echo -ne "${Green}OK, what time is it at? ${Color_Off}"
read whattime
echo -ne "${Green}Where? ${Color_Off}"
read where
echo -e "${Green}Perfect! Now that you're done, I will register this in the Calendrier local database ${Color_Off}"
echo "$dateis at $whattime: Meeting with $whoisitwith at $where" >> ~/.Calendrier/meeting
fi
if [ $option == class ]; then
echo -e "${Green}Ah, so it's a class!${Color_Off}"
echo -ne "${Green}OK, what time is it at? ${Color_Off}"
read whattime2
echo -ne "${Green}What class is it (e.g. Science, Mathematics, History)? ${Color_Off}"
read whatclass
echo -ne "${Green}Where? ${Color_Off}"
read where2
echo -e "${Green}Perfect! Now that you're done, I will register this in the Calendrier local database ${Color_Off}"
echo "$dateis at $whattime2:$whatclass at $where2" >> ~/.Calendrier/class
fi
;;
tomorrow) set dateis=`date --date="tomorrow" +'%Y-%m-%d'`
echo Date is $dateis in YYYY-MM-DD >> ~/.Calendrier/log
read -p "Is this an event, a meeting, appointment, or class? " option
if [ $option == event ]; then
echo -e "${Green}Ah, so it's an event!${Color_Off}"
echo -ne "${Green}What event are you going to? ${Color_Off}"
read whatevent
echo -ne "${Green}What time? ${Color_Off}"
read thetimelol
echo -e "${Green}Cool :), this event will be recorded${Color_Off}"
echo "$dateis at $thetimelol: $whatevent" >> ~/.Calendrier/class
fi
if [ $option == meeting ]; then
echo -e "${Green}Ah, so it's a meeting!${Color_Off}"
echo -ne "${Green}If it is a meeting, who is it with (seperate names with commas)? ${Color_Off}"
read whoisitwith
echo -ne "${Green}OK, what time is it at? ${Color_Off}"
read whattime
echo -ne "${Green}Where? ${Color_Off}"
read where
echo -e "${Green}Perfect! Now that you're done, I will register this in the Calendrier local database ${Color_Off}"
echo "$dateis at $whattime: Meeting with $whoisitwith at $where" >> ~/.Calendrier/meeting
fi
if [ $option == class ]; then
echo -e "${Green}Ah, so it's a class!${Color_Off}"
echo -ne "${Green}OK, what time is it at? ${Color_Off}"
read whattime2
echo -ne "${Green}What class is it (e.g. Science, Mathematics, History)? ${Color_Off}"
read whatclass
echo -ne "${Green}Where? ${Color_Off}"
read where2
echo -e "${Green}Perfect! Now that you're done, I will register this in the Calendrier local database ${Color_Off}"
echo "$dateis at $whattime2:$whatclass at $where2" >> ~/.Calendrier/class
fi
;;
esac
if [ "$2" != "today" ] && [ "$2" != "tomorrow" ]; then
if date --date="$2" 2> /dev/null > /dev/null
then set dateis="$2"
echo Date is $dateis in YYYY-MM-DD >> ~/.Calendrier/log
read -p "Is this an event, a meeting, appointment, or class? " option
if [ $option == event ]; then
dateis=$2
echo -e "${Green}Ah, so it's an event!${Color_Off}"
echo -ne "${Green}What event are you going to? ${Color_Off}"
read whatevent
echo -ne "${Green}What time? ${Color_Off}"
read thetimelol
echo -e "${Green}Cool :), this event will be recorded${Color_Off}"
echo "$dateis at $thetimelol: $whatevent" >> ~/.Calendrier/class
fi
if [ $option == meeting ]; then
dateis=$2
echo -e "${Green}Ah, so it's a meeting!${Color_Off}"
echo -ne "${Green}If it is a meeting, who is it with (seperate names with commas)? ${Color_Off}"
read whoisitwith
echo -ne "${Green}OK, what time is it at? ${Color_Off}"
read whattime
echo -ne "${Green}Where? ${Color_Off}"
read where
echo -e "${Green}Perfect! Now that you're done, I will register this in the Calendrier local database ${Color_Off}"
echo "$dateis at $whattime: Meeting with $whoisitwith at $where" >> ~/.Calendrier/meeting
fi
if [ $option == class ]; then
dateis=$2
echo -e "${Green}Ah, so it's a class!${Color_Off}"
echo -ne "${Green}OK, what time is it at? ${Color_Off}"
read whattime2
echo -ne "${Green}What class is it (e.g. Science, Mathematics, History)? ${Color_Off}"
read whatclass
echo -ne "${Green}Where? ${Color_Off}"
read where2
echo -e "${Green}Perfect! Now that you're done, I will register this in the Calendrier local database ${Color_Off}"
echo "$dateis at $whattime2:$whatclass at $where2" >> ~/.Calendrier/class
fi
else
echo -e "${Green}Don't be silly, `whoami`. That's not a date. PS: It should be formatted YYYY-MM-DD or YY-MM-DD${Color_Off}"
exit
fi
fi
gui)
;;
esac
Are there any tips (besides the ifs mess )? Any bugs?
Please don't be mean. This is my first try. Also, I am still working on it. It is NOT complete yet.
Please don't be mean. This is my first try. Also, I am still working on it. It is NOT complete yet.
Nobody is, and I should know, I asked weirder stuff and they still let me in as long as you adhere to the rules, you're okay...
So, where is the problem? You did supply the script, but...where do you reach the "bump in the road"?
Welcome to the forum!!
Thor
Edit - personally, I'd consider PERL as a next step, since all systems have that installed by default anyway, or at least have it ready to install in the respecitve repo
Last edited by ButterflyMelissa; 07-06-2014 at 03:03 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.