0

I'm trying to create a short cut for a mac terminal such that when I write 'jj' the following line of code used in terminal will run:

python 5_7_16.py

My partner can write the program for Linux but he's not able to do it for Mac. He managed to write the path of the code as follows

      FPTH="/Users/kylefoley/PycharmProjects/inference_engine2/inference2/Proofs/5_7_16.py"

When I'm using the pycharm software these are the first two lines of code I use before I can use python 5_7_16.py

cd inference2
cd Proofs

We already have the python file 'jj' saved in the right location and we can almost get it to work but not quite.

Also, software has three modes: output to excel, output to django, output to mysql. For reasons that I don't understand my partner thought we needed to write down in our file what type of mode is active. I don't understand why this is the case because all that information is already stored in the 5_7_16 file. Just in case it helps, here are the first lines of the python code.

excel = True
mysql = False

if not excel and not mysql:
    from inference2.models import Define3, Archives, Input
    from inference2 import views
if mysql:
    import os
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    print BASE_DIR
    sys.path.append(BASE_DIR)
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "inference_engine2.settings")
    import django
    django.setup()
    from inference2 import views
    from inference2.models import Define3, Archives, Input

So here is what he wrote so far, thought again, I don't understand why all this is necessary. I would think that all you would need would be to just tell the mac terminal what code you want to run:

FPTH="/Users/kylefoley/PycharmProjects/inference_engine2/inference2/Proofs/5_7_16.py"

vmysql=$(sed -i ‘’ -E ’s/^mysql = \(.*\)/\1/g’ $FPTH)
vexcel=$(sed —i ‘’ E ’s/^excel = \(.*\)/\1/g’ $FPTH)
echo $vexcel
echo $vmysql
if [ "$vexcel" == "True" ] ; then
echo "Excel"
elif [ "$vmysql" = "True" ] 
then
echo "Mysql"
else
echo "Django"
fi
if [ "$vexcel" = "True" ] ; then
echo "Excel is set”
python $FPTH
elif [ "$vmysql" = "True" ] 
then
echo "Mysql is set”
python $FPTH
else
echo “Django is set”
cd /dUsers/kylefoley/PycharmProjects/inference_engine2
python manage.py runserver
fi
bobsmith76
  • 160
  • 1
  • 9
  • 26
  • 2
    This is a lot of writing for a very simple thing. Go into `~/.bash_rc` and write `alias jj="python ~/inference2/Proofs/5_7_16.py"` – Eli Sadoff Nov 02 '16 at 19:50

1 Answers1

0

You need to add the alias in your .bash_profile file. For details, check: About .bash_profile, .bashrc, and where should alias be written in?

Below are the steps to follow:

# Step 1: Go To home directory
cd 

# Step 2: Edit ".bash_profile" file OR, create if not exists
vi .bash_profile
# In this file add entry at last as:
# alias jj="python ~/inference2/Proofs/5_7_16.py"
#                  ^ OR whatever is the path to file

# Now, close the file

# Step 3: Refresh bash shell environment
source ~/.bash_profile

You are good to do jj now.


From the bash manpage:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

Community
  • 1
  • 1
Moinuddin Quadri
  • 46,825
  • 13
  • 96
  • 126