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 where I use git, and if so how?
相关问题
- softlinks atime and mtime modification
- Get unexpanded argument from bash command line
- Include and Execute EXE in C# Command Line App
- Batch - Set variables in for loop
- Rails gem update not working (version 4.1.1 to 4.2
相关文章
- Emacs/xterm color annoyance on Linux
- Compile and build with single command line Java (L
- How to update command line output?
- make GitX open via Terminal for the repo laying at
- How to execute another python script from your scr
- Python file keyword argument?
- Reset bash history search position
- Interactively merge files tracked with git and unt
If you are using for example ZSH, just add to your config file
.zshrc
this string:or for instance:
Change path with your preference.
It just will return command to ZSH, you won't see it in terminal and it will start with your chosen path.
Try
echo "cd $directory" >> ~/.bash_profile
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).
This will see if you are in your
HOME
directory only on launch, and if so change to your newSTART
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 toSTART
. Which is expected.As of Mac OS X Lion 10.7, Terminal supports Resume and by default will automatically restore terminals you had open when you quit, restoring their working directories. So, you can just open a new terminal and cd to your git directory, then leave the window open when you Quit. Each time you reopen Terminal, the terminal will be there, in the same directory. (This works for bash by default. If you're using some other shell, you'll need to adapt the code in /etc/bashrc to your shell. I've posted code for zsh in my answer to Resume Zsh-Terminal (OS X Lion) on SuperUser.)
You can also arrange for Terminal to start a shell in a particular directory. You can customize or create a "Settings Profile" to issue a "cd" command when it starts:
Enable "Run command" and "Run inside shell", then set the command to
cd your_git_directory
. When you open a new terminal with that profile, it will go to your git directory.I recommend you Duplicate the current default profile (if you've never changed it, the default is "Basic") using the Action ("gear") menu at the bottom of the profiles list, then customize that profile.
Finally, to have it automatically open a terminal with this profile when you open Terminal, set
to your custom profile. (On Lion, Resume will restore windows that were open when you quit, rather than perform the startup action. As I mentioned, you can just leave this terminal open when you Quit and it will be restored when you open Terminal again. Or, you can press the Option modifier key when quitting; the Quit menu item will change to "Quit and Discard Windows" and the next time you open Terminal it will perform the startup action.)