Set the default directory in mac terminal

后端 未结 6 1924
天命终不由人
天命终不由人 2020-12-23 09:00

I only use terminal (mac) for git, and I only use git for one directory. Is it possible to set the default directory (the directory when terminal is opened) to the directory

6条回答
  •  没有蜡笔的小新
    2020-12-23 09:31

    I like to have 'New windows open with: Same Working Directory'. All answers I've found for this question (many SO's) will break that setting by always going to the new home directory. Below is what I use at the top of my .profile (or .bashrc, etc).

    export START="/Users/michael/my/starting/directory"
    if [[ $PWD == $HOME ]]; then
        cd $START
    fi
    

    This will see if you are in your HOME directory only on launch, and if so change to your new START directory. That way new windows won't automatically run this command.

    The only caveat is if you're in your actual HOME directory and open a new window, it will take you to START. Which is expected.

提交回复
热议问题