Monday, October 13, 2008

BASH script for easier programming

How many of you are tired of going through with terminal cd-ing until finding the file you want to compile ?, typing in all those commands for gcc or g++ or even simpler things like python or java and wish that there was some kinda program that would just let you pick the damn file and compile without you having to strain yourself well now there is and also with a cool little gui i might add, so here it this will let you pick your file and then pick what kind of file it is, ie .c .cpp .py etc .... and then just run just like that it is a very simple script nothing fancy, but it just might save you those extra key strokes you always hated to begin with.

just to mention the script can be easily adapted to any other programming language that i didnt add.

README FIRST

should copy this file and put it in a folder, it'd be best to be in your home directory just for easy access if you wanted it to run from terminal, remember to give this file executable permissions and watch it go, always choose to run in terminal when double clicking on it.

Next update of this script will be done sometime in the next couple of weeks. I will be posting the list of new updates soon as well.

any bug reports should be done here thank you.


#!/bin/sh

#
# Simple script to compile and run anytype of file.
#
# Rapsodia49 rapsodia49@gmail.com 2008
#
# 100% opensource
#

filevar="./var"
filevar2="./var2"


if [ -e $filevar ];
then
rm var
fi

if [ -e $filevar2 ];
then
rm var2
fi


SelectFile=$(zenity --file-selection --title "Select a File");echo $SelectFile



if [ -z $SelectFile ];
then
zenity --info --text "No File selected"

else

zenity --info --text "\"$SelectFile\" selected"


ans=$(zenity --list --text "Select the type of file" --radiolist --column "Pick" --column "Type" TRUE C FALSE Shell FALSE "C++" FALSE "Java" FALSE python FALSE Ruby); echo $ans

case $ans in
"C") echo "Compiling and running C File ";
gcc $SelectFile -o var;
./var;
rm var;;

"C++") echo "Compiling and running C++ File ";
g++ $SelectFile -o var2;
./var2;
rm var2;;

"Java") echo "Compiling and running Java File ";
java $SelectFile;;

"python") "Compiling and running Python File ";
python $SelectFile;;

"Shell") "Compiling and running Shell File ";
./$SelectFile;;
"Ruby") "Compiling and running Ruby File ";
ruby $SelectFile;;
esac
fi

No comments: