in Uncategorized

How to Set Default Directory in Mac erminal

As a tech person I need to use the terminal a lot. So, after opening the terminal need to browse or open any specific dir if I want to run any command based on dir or services like git. At home I mostly use mac(though as office I use windows long time) and I was looking for how to set any specific directory default in mac’s terminal. After doing some search found some help in stackoverflow. Here is how I have set for mine.

Open your mac’s termnial. Run command nano ~/.bash_profile .

bash_profile. This file is loaded before Terminal loads your shell environment and contains all the startup configuration and preferences for your command line interface.

via this article

Now write the below line in the bash profile file, the first has my fav dir that I want to open at terminal start

export START="/Applications/XAMPP/xamppfiles/htdocs/projects" //this is my fav dir I like to open as default dir for mac
if [[ $PWD == $HOME ]]; then
cd $START
else
cd $HOME
fi

Save the bash profile and exit. Now open your terminal.

Note: I used the tricks from here at stackoverflow and tried to write as my own way.

Write a Comment

Comment