在mac终端设置默认目录 [英] Set the default directory in mac terminal

查看:256
本文介绍了在mac终端设置默认目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只使用终端(mac)git,我只使用git一个目录。是否可以设置默认目录(终端打开时的目录)到我使用git的目录,如果是这样?

解决方案

从Mac OS X Lion 10.7开始,终端支持恢复,默认情况下会自动恢复您退出时打开的终端,恢复其工作目录。所以,你可以打开一个新的终端和cd到你的git目录,然后离开窗口时,你退出。每次重新打开Terminal时,终端将在那里,在同一目录下。如果你使用一些其他shell,你需要调整/ etc / bashrc中的代码到你的shell。我已经在我的回答中发布了代码zsh在在SuperUser上恢复Zsh终端(OS X Lion)。)



您还可以安排Terminal在特定目录中启动shell。您可以自定义或创建一个设置配置文件,以便在启动时发出cd命令:


设置> [配置文件]> Shell>启动>运行命令


启用运行命令 ,然后将命令设置为 cd your_git_directory 。当你用这个配置文件打开一个新的终端,它会去你的git目录。



我建议你复制当前的默认配置文件(如果你从来没有改变过,默认为Basic),使用配置文件列表底部的Action(齿轮)菜单,然后自定义该配置文件。



最后,当您打开Terminal时打开一个使用此配置文件的终端,设置



> bb 终端>首选项>启动> >


到您的自定义个人资料。 (On Lion,Resume会恢复当您退出时打开的窗口,而不是执行启动操作。正如我提到的,当您退出时,您可以将此终端保持打开状态,当您再次打开终端时将恢复,或者,可以在退出时按选项修改键;退出菜单项将更改为退出并放弃Windows,下次打开终端时将执行启动操作。)


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?

解决方案

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:

Terminal > Preferences > Settings > [profile] > Shell > Startup > Run command

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

Terminal > Preferences > Startup > On Startup, open

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.)

这篇关于在mac终端设置默认目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆