BashScripts.org
http://bashscripts.org/forum/

baps - (B)(A)sh (P)honebook (S)cript
http://bashscripts.org/forum/viewtopic.php?f=7&t=138
Page 1 of 1

Author:  crouse [ Tue Oct 25, 2005 12:05 am ]
Post subject:  baps - (B)(A)sh (P)honebook (S)cript

QUITE a few changes :D :D :D

Code:
#!/bin/bash
#
##########################
# USA Linux Users Group  #
# http://www.usalug.org  #
# http://bashscripts.org #
##########################

#######################################################
#     baps - (B)(A)sh (P)honebook (S)cript                #
#######################################################
#
#
#    FILE: baps
# VERSION: See variable below
#    DATE: See variable below
#
#  AUTHOR: Crouse - Please visit bashscripts.org and usalug.org
#
#
########################################################

######################
# Start of Variables #
######################
#
#
#########################################################
                                                       ##
baps_version="0.1.1"                                   ##
revision_date="Modified October 25, 2005"              ##
author="Created by: Dave Crouse"                       ##
                                                       ##
#########################################################
#
#
######################
# End of Variables   #
######################

mkdir -p ~/.baps; touch ~/.baps/phone.data;
touch ~/.baps/temp.data
cat /dev/null > ~/.baps/temp.data


headerfile ()
{
clear; echo "
(B)(A)sh (P)honebook (S)cript
                baps - Version $baps_version ";
echo "*****************************************************";
echo "   The results returned for a search of: $searchforthis" ;
echo "     ______________________________________";
sort -d ~/.baps/temp.data | nl -ba ;
echo "     ______________________________________";
echo "";
echo "*****************************************************";
}

mainmenu ()
{
menu="     s)earch a)dd  r)emove  e)xit"
while true; do

headerfile;
echo -e "$menu"
echo "";
read -p "Please choose one of the options above : " option

case $option in
      s)   searchrecords; ;;
      a)   addrecord; ;;
      r)   removerecord; ;;   
      e) exit; ;;


       # help)   helpfile ; ;;
       list)  listallrecords; ;;
      alias)  echo "alias baps='sh $PWD/baps.sh'" >> ~/.bashrc; ;;
      clear) rm ~/.baps/temp.data; ;;           
      erase) erasephonebook ;;     
      *)   echo "Sorry, that isn't an option, try again. "; sleep 2;  ;;
   esac
done;
}

addrecord ()
{
clear; echo "
(B)(A)sh (P)hone (S)cript
                baps - Version $baps_version ";
read -p "ADDING RECORD: Enter Name " name;
read -p "ADDING RECORD: Enter Phone Number " number;
entry="$name $number"
echo $entry >> ~/.baps/phone.data
echo "Record Added: $entry"; sleep 1;

}

searchrecords ()
{
cat /dev/null > ~/.baps/temp.data
  read -p "Search for : " searchforthis
     if [[ $searchforthis != "" ]]
      then
   grep -i "$searchforthis" ~/.baps/phone.data > ~/.baps/temp.data
   headerfile
      else
        echo ""
   echo "Sorry, you must enter something to search for!"
   read -p "Hit any key to continue. " temp
     fi
}

erasephonebook ()
{
read -p "$USER are you sure you want to erase the entire phone directory ? y/n: " reallycontinue
if [ "$reallycontinue" = "y" ]
   then
   rm ~/.baps/phone.data; echo "!! Erasing Entire Directory !!" ; sleep 1;
   rm ~/.baps/temp.data;
fi
}

removerecord ()
{
touch ~/.baps/temp2.data; cat /dev/null > ~/.baps/temp2.data;
sort -d ~/.baps/phone.data > ~/.baps/temp2.data
mv ~/.baps/temp2.data  ~/.baps/phone.data
clear; echo "
(B)(A)sh (P)honebook (S)cript
                baps - Version $baps_version ";
echo "************ Removing Record **************************";
echo "     ______________________________________";
echo " Line Number   | Record";
nl -ba ~/.baps/phone.data
echo "     ______________________________________";
echo " ";
echo "************ Removing Record **************************";
     read -p "Enter the line number of the record you would like to delete : " removeline;
     if [[ $removeline != "" ]]
     then
         cat /dev/null > ~/.baps/temp2.data;
         cat ~/.baps/phone.data | sed ''$removeline'd' > ~/.baps/temp2.data;
         mv ~/.baps/temp2.data ~/.baps/phone.data
    echo "Record Removed!" ; sleep 1;
     fi
}

listallrecords ()
{
clear; echo "
(B)(A)sh (P)honebook (S)cript
                baps - Version $baps_version ";
echo "*********** Listing all entries **********************";
sort -d ~/.baps/phone.data | nl -ba ;
echo "*********** Listing all entries **********************";
read -p "Hit ENTER to continue : " anykey
}

###########################
# Program run starts here #
###########################
mainmenu
exit

Author:  crouse [ Thu Dec 08, 2005 12:54 am ]
Post subject: 

http://steve-parker.org/sh/eg/addressbook/

Haven't looked at the code of his yet though......

Author:  crudball [ Tue Mar 07, 2006 12:49 pm ]
Post subject: 

Couldn;t you stick this code
Code:
mkdir -p ~/.baps; touch ~/.baps/phone.data;
touch ~/.baps/temp.data
cat /dev/null > ~/.baps/temp.data

in an if bit so as then you wouldn't keep running those commands?
Code:
if [[ -d ~./baps ]]
then
echo "baps dir exists"
else
echo "it doesn't exist, will now create the dir and neccesary files. " ;
mkdir -p ~/.baps; touch ~/.baps/phone.data;
touch ~/.baps/temp.data ;
cat /dev/null > ~/.baps/temp.data
fi

Author:  crouse [ Mon Jun 19, 2006 12:52 pm ]
Post subject: 

crudball wrote:
Couldn;t you stick this code
Code:
mkdir -p ~/.baps; touch ~/.baps/phone.data;
touch ~/.baps/temp.data
cat /dev/null > ~/.baps/temp.data

in an if bit so as then you wouldn't keep running those commands?
Code:
if [[ -d ~./baps ]]
then
echo "baps dir exists"
else
echo "it doesn't exist, will now create the dir and neccesary files. " ;
mkdir -p ~/.baps; touch ~/.baps/phone.data;
touch ~/.baps/temp.data ;
cat /dev/null > ~/.baps/temp.data
fi



if you do a man mkdir you will see that the -p option does that already.....

-p, --parents
no error if existing, make parent directories as needed


so in essence your code is checking it TWICE ..... no need.... my code checks for existing directories, if not.....creates them....

Author:  coastie [ Fri Jul 21, 2006 9:18 am ]
Post subject: 

Looks good man....maybe i'll have to put your number in here :P you'll never be safe now that i have it...hehehehe

Author:  crouse [ Fri Sep 08, 2006 3:36 pm ]
Post subject: 

Code:
#!/bin/bash
#
##########################
# USA Linux Users Group  #
# http://www.usalug.org  #
# http://bashscripts.org #
##########################

#######################################################
#     baps - (B)(A)sh (P)honebook (S)cript            #
#######################################################
#                                                     #
#                                                     #
#    FILE: baps                                       #
# VERSION: See variable below                         #
#    DATE: See variable below                         #
# LICENSE: GPL                                        #
#  AUTHOR: Crouse - Please visit bashscripts.org      #
#                   and usalug.org                    #
#                                                     #
#                                                     #
#######################################################

######################
# Start of Variables #
######################
#
#
#########################################################
                                                       ##
baps_version="0.2"                                     ##
revision_date="Modified Sept 9th, 2006"                ##
author="Created by: Dave Crouse"                       ##
                                                       ##
#########################################################
#
#
######################
# End of Variables   #
######################

mkdir -p ~/.baps; touch ~/.baps/phone.data;
touch ~/.baps/temp.data;
cat /dev/null > ~/.baps/temp.data;


headerfile ()
{
clear;
echo "*****************************************************";
echo "*         (B)(A)sh (P)honebook (S)cript             *";
echo "*****************************************************";
echo " ";
echo "   The results returned for a search of: $searchforthis" ;
echo "     ______________________________________";
echo " ";
sort -d ~/.baps/temp.data | nl -ba ;
echo "     ______________________________________";
echo "";
}

mainmenu ()
{
menu="     s)earch a)dd  r)emove  e)xit"
while true; do

headerfile;
echo -e "$menu"
echo "";
read -p "Please choose one of the options above : " option

case $option in
      s)   searchrecords; ;;
      a)   addrecord; ;;
      r)   removerecord; ;;   
      e) exit; ;;


       # help)   helpfile ; ;;
       print) sort -d ~/.baps/phone.data | nl -ba | lpr ; ;;
       list)  listallrecords; ;;
      alias)  echo "alias phonebook='sh $PWD/baps.sh'" >> ~/.bashrc; ;;
      clear) rm ~/.baps/temp.data; ;;           
      erase) erasephonebook ;;     
      *)   echo "Sorry, that isn't an option, try again. "; sleep 2;  ;;
   esac
done;
}

addrecord ()
{
clear;
echo "*****************************************************";
echo "*         (B)(A)sh (P)honebook (S)cript             *";
echo "*****************************************************";
read -p "ADDING RECORD: Enter Name " name;
read -p "ADDING RECORD: Enter Phone Number " number;
entry="$name $number"
echo $entry >> ~/.baps/phone.data
echo "Record Added: $entry"; sleep 1;

}

searchrecords ()
{
cat /dev/null > ~/.baps/temp.data
  read -p "Search for : " searchforthis
     if [[ $searchforthis != "" ]]
      then
   grep -i "$searchforthis" ~/.baps/phone.data > ~/.baps/temp.data
   headerfile
      else
        echo ""
   echo "Sorry, you must enter something to search for!"
   read -p "Hit any key to continue. " temp
     fi
}

erasephonebook ()
{
read -p "$USER are you sure you want to erase the entire phone directory ? y/n: " reallycontinue
if [ "$reallycontinue" = "y" ]
   then
   cp ~/.baps/phone.data ~/.baps/phone.data~~
   rm ~/.baps/phone.data; echo "!! Erasing Entire Directory !!" ; sleep 1;
   rm ~/.baps/temp.data;
fi
}

removerecord ()
{
touch ~/.baps/temp2.data; cat /dev/null > ~/.baps/temp2.data;
sort -d ~/.baps/phone.data > ~/.baps/temp2.data
mv ~/.baps/temp2.data  ~/.baps/phone.data
clear;
echo "*****************************************************";
echo "*         (B)(A)sh (P)honebook (S)cript             *";
echo "*****************************************************";
echo "    ~~~~~~~~ Removing Record ~~~~~~~~";
echo " ";
echo "     ______________________________________";
echo " Line Number   | Record";
nl -ba ~/.baps/phone.data
echo "     ______________________________________";
echo " ";
echo "    ~~~~~~~~ Removing Record ~~~~~~~~";
     read -p "Enter the line number of the record you would like to delete : " removeline;
     if [[ $removeline != "" ]]
     then
         cat /dev/null > ~/.baps/temp2.data;
         cat ~/.baps/phone.data | sed ''$removeline'd' > ~/.baps/temp2.data;
         mv ~/.baps/temp2.data ~/.baps/phone.data
    echo "Record Removed!" ; sleep 1;
     fi
}

listallrecords ()
{
clear; sort -d ~/.baps/phone.data | nl -ba | less ;
}

###########################
# Program run starts here #
###########################
mainmenu
exit 0

Author:  coastie [ Fri Sep 08, 2006 10:10 pm ]
Post subject: 

you should do this one like you did bbips :idea:

baps name

searches all the names you have in it. :idea:

Author:  coastie [ Sat Sep 09, 2006 1:59 pm ]
Post subject: 

I just started using it again. Works good crouse ;) still think you should make it like bbips :idea:

Author:  crouse [ Sat Sep 09, 2006 3:19 pm ]
Post subject: 

coastie wrote:
I just started using it again. Works good crouse ;) still think you should make it like bbips :idea:


you mean menu driven ?

Author:  coastie [ Sat Sep 09, 2006 4:35 pm ]
Post subject: 

no, doing what you did with bbips, in that it's installed in /usr/bin. You could also add some stuff for addresses, and email addy's. My dad has been looking for an easy to use address book, this definately fits the bill. As soon as I can get Linux installed for him ;) I think that even he could use this without screwing it up ;)

Author:  crouse [ Sat Sep 09, 2006 7:48 pm ]
Post subject: 

nothing to "make" coastie :)

Just rename it to whatever you want..... and put it in /usr/bin or /usr/local/bin and it should work for everyone...... however, everyone will have their own directories with their own phone book....

Author:  coastie [ Sat Sep 09, 2006 7:55 pm ]
Post subject: 

nice, thanks ;)

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com