Showing posts with label shell script. Show all posts
Showing posts with label shell script. Show all posts

Friday, July 27, 2012

cenv: create your own environments

     Everytime I start coding for GTG, I have to start terminal, nautilus and a browser(in case of bugs ;) ). For a lazy person like me, this is a very boring task. Hence i just came up with an easy solution : environment creator which takes a set of your tasks and turns them into a linux command.
     With all the tasks done in just one go, I can consider it to be a productivity enhancing tool (though it's primary purpose was to help lazy bums like me :P ). All sorts of work environments can be created with this tool. You can have one called "work" which like mine, starts terminal with vim/gedit, nautilus and browser. You can keep one for home which could maybe contain nautilus with your songs folder opened up, a music player, a todo list manager if you have one etc.
     Another added advantage for this tool, is that you can create macros for yourself. Say you have a habit of backing up your files to your external device regularly, you can just create an environment called "backup" with all the copy commands. Heck, you can even add one environment inside another environment because these all are actually turned into linux commands only!
     Right now I have features like "new", "remove" , "rename", "edit" etc. but further more features will come up in a week of 2. The very basic version is ready and I plan to launch the version 0.1 by next Saturday.
     Here is the link to the homepage of the launchpad project: https://launchpad.net/cenv
     I'll let others contribute to the code after the launch of version 0.1
  

Tuesday, February 7, 2012

TT (newer version of timetable)

  Last year I had created a shell script which showed me my academic timetable for the day. I was a newbie in shell scripting at that time and hence the script was not so good. Hence, here is tt or I should say timetable2.0 ?
  This time I have stored my timetable in a timetable.txt file so that whenever I need to modify the timetable, I don't need to modify the script. Also, the code is much shorter this time with not so many if statements. Here is the new code:

#!/bin/bash
days=( Monday Tuesday Wednesday Thursday Friday )

if [ "$#" == 0 ]
then
  echo -e "\nToday's Timetable:"
  set `date +%u`
else
  echo -e "\n"${days[$1-1]}"'s timetable:"
fi
  sed -n $1p < timetable.txt
  echo -e "\n\n"


  Still to be added: Feature to change the timetable. But that's all for now. The new modification will come when I feel the mood of it :)

  

Wednesday, August 17, 2011

timetable.sh for lazy people like me

   It is always very difficult for me to remember the time-table, especially for the first few weeks of semester. The condition was worse this semester, so I HAD to find a solution for this.I know, taking a photograph of the timetable would do it but I thought of doing something new (yeah!!)
 
   Since, the start of this semester, I had started using Linux and so I thought of making a shell script to help me.Well, fortunately I stuck to this idea and hence after about an hour of Googling, I was able to learn enough of shell scripting to help me here.Well, to save u from even one hour of googling, I am sharing the skeleton of the program:

#! /bin/bash

if [ "$#" == "0" ]
then
 
   set `date +%u`
if [ "$1" -eq "1" ]
then
   echo -e "Monday's timetable\n"

else if [ "$1" -eq "2" ]
then
   echo -e "\nTuesday\n"
else if [ "$1" -eq "3" ]
then
   echo -e "\n Wednesday\n"
  
else if [ "$1" -eq "4" ]
then
   echo -e "\n Thursday\n"
  
else if [ "$1" -eq "5" ]
then
   echo -e "\nFriday\n"
 fi
 fi
 fi
 fi
 fi
  
else

if [ "$1" == "1" ]
then
      same thing again


fi

fi


So, why did I use $# here?
  $# tells me the no of arguments passed. So if we passed a day number as an argument, then show that day's timetable, otherwise find the day of the week and then display the timetable.

why echo -e?
   Normally, echo doesnot support escape sequences so we need to add -e for them.

and date +%u gives u  the day of the week

We use the set command to give the value to the variable $1. $1 and all are special variables used in Shell script.

U can use == or -eq for checking the comparison. And it is visible that u need to end each if statement using fi!!

Anyways, now I have a shell script to tell me the timetable whenever I need it. Now all I need to do is make it autorun everyday in the morning and also turn it into a linux command. Will do that, and let u know :)

Enjoy this code till then. Yes, u are also welcome to tell me how to do the above!