Thursday, February 26, 2009

~/.bashrc won't load in OSX terminal

While I was in my /etc/bashrc tonight setting up macports I thought of something that has always bugged me but I never really cared enough to figure out.

Why doesn't by personal bash config file (~/.bashrc) not load when I launch a terminal?

I still don't know the answer to that question, but I at least figured out a really simple hack tonight.

inside of /etc/bashrc you simply need to add the line(I added it at the end)
~/.bashrc

This will load all your personal aliased and settings right bash loads and performs the system-wide aliases and config options. If this solves all your problems, then you can go about your day and I was glad to help ^.^ But this could actually be improved upon if people care to follow along.

Depending on the contents of your ~/.bashrc file, you may need to use this line instead
. ~/.bashrc

that is, <dot><space>~/.bashrc. this executes all the commands within ~/.bashrc within the current shell process. This does not make a difference for most commands. The only only I know of is cd (change directory) which. Scripts which call the system command cd must be executed with <dot><space> in order for that change to be reflected in the shell executing the script after execution ends.

So there you go, now you can make all terminals you launch cd into your code root directory when you launch the terminal. I don't but I don't judge you ^.^

Labels: , ,

Ports!

It's been a couple months since I last formatted my computer, and I hadn't reinstalled macports until tonight. I was procrastinating because I remembered it being a pain to set up the first time. Turns out I was just a noob back then ^.^

went to the macports site and got the latest version to install. then just clicked through the install w/o any changes. It was kindof an accident. I do it a lot because I fail to see the 'customize' button in OSX installer before I click through to the next page(It's all alone in the bottom left of the window; who looks at the bottom left of windows?!). Luckily I knew that macports wants to install everything in /opt/local/bin.

All that was left was to change PATH variable to let my execute macports' apps from any directory. Another key step was to add macports' man pages to my MANPATH variable. I think that this was the part that I found confusing when I first installed macports, because I wasn't aware that MANPATH existed. None-the-less I was confused when I couldn't read man pages for the apps I ported.

yadda yadda yadda.... open my bashrc file to add these paths:
sudo vim /etc/bashrc

If you don't use vim for text-editing, I highly recommend it. To learn more you can just execute the command in the terminal:
vimtutor

The tutorial is a text file and you learn how to edit in vim it as you read it. Pretty clever, but not what we came to do.. back to bashrc.

Add the following lines to your bashrc file:
PATH="/opt/local/bin/:/opt/local/sbin/:$PATH"
MANPATH="/opt/local/man/:$MANPATH"

Save and exit your text editor(:wq in vim), and tada! All bash terminals you launch from now on will let you launch your macports apps.

To load the changes into your current terminal session type (note the space between the period and slash)
. /etc/bashrc

Thats all there is to it ^.^

Labels: , ,