2

I have some .bash_profile settings that restore my last working directory every time I log in to my shell. However, I also use a program that opens a terminal window in the current directory open in Finder, and it does this by sending an event to Terminal using SBApplication.

Is there a way I can detect which way the Terminal was opened in my .bash_profile? Right now the bash settings override the cd to app.

# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin"
export PATH

# My settings
trap 'printf %s "$PWD" > ~/.storepwd' EXIT

cd "$(<~/.storepwd)"
  • Please edit your question adding the settings you've added to your .bash_profile that are relevant to this question. – user3439894 Feb 10 '16 at 14:43
  • Please add an answer instead of editing a solution into your question. You might add it to the accepted answer or the user jherran can do it – klanomath Feb 11 '16 at 17:59
  • BTW "PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin" ... export PATH" will probably break your PATH – klanomath Feb 11 '16 at 18:03
  • @klanomath thanks, new to this site. Yes, I quickly edited out some stuff in my path that I didn't think was relevant to the question and forgot to leave the :${PATH} at the end :P – cdamayor Feb 11 '16 at 18:09
0

You can display BASH variables on your .bash_profile. Then compare the output when you manually open the terminal with output when cd to app opens the terminal.

I meant append at the beginning of your .bash_profile the bash variables listed on the website:

echo $BASH
echo $BASHOPTS
echo $BASHPID
...
echo $TMPDIR
echo $UID

Then open manually the terminal and save the output. Open the terminal from cd to and save the output.

Compare the files.


The proper variable for the above example is DIRSTACK.

Here are the new settings for those passing through:

# My settings
if [ $DIRSTACK = "~" ]; then
    trap 'printf %s "$PWD" > ~/.storepwd' EXIT
    cd "$(<~/.storepwd)"
fi
  • 1
    Could you elaborate a bit on this, maybe include a working example too? – user3439894 Feb 9 '16 at 14:16
  • BASHOPTS isn't set in the standard bash on OSX. – nohillside Feb 10 '16 at 14:18
  • Thanks @jherran! The variable I was looking for is $DIRSTACK. – cdamayor Feb 11 '16 at 17:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .