You don't set this association in your
.bash_profile. Your shell does not know which OS X application to open a file with – it's the Launch Services that take care of this.
The easiest way to globally change file type associations to certain applications is to install RCDefaultApp and just set everything through System Preferences.
In theory, you could also modify the
~/Library/Preferences/com.apple.LaunchServices.plist file for custom associations, but I wouldn't recommend going there.
I want to associate all .txt files to TextMate so that when I shall open the file from the shell it would automatically launch TextMate and opens my file
Go to a text file, right click it and select Open With…. Here, choose TextMate, and then click Change All….
Now, whenever you're in the shell, you can type:
And this will open TextMate with your text file.1 The same applies to any other association you might set through either RCDefaultApp or the Get Info… dialog in Finder. The magic behind this is that
open wil defer the call to the Launch Services, which then decide on the application to use.2
1: Actually, for TextMate, the following is enough:
2: You can also manually choose an app, e.g.
open -a Xcode foo.txt. Read
man open for more.