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

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

问题描述

我只对 git 使用终端 (mac),并且我只对一个目录使用 git.是否可以将默认目录(打开终端时的目录)设置为我使用git的目录,如果可以,如何设置?

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?

推荐答案

从 Mac OS X Lion 10.7 开始,终端支持恢复,默认情况下会自动恢复您退出时打开的终端,恢复其工作目录.因此,您只需打开一个新终端并 cd 到您的 git 目录,然后在退出时让窗口保持打开状态.每次重新打开终端时,终端都会在同一目录中.(默认情况下,这适用于 bash.如果您使用其他一些 shell,则需要将/etc/bashrc 中的代码调整到您的 shell.我已经在对 在超级用户上恢复 Zsh-Terminal (OS X Lion).)

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

您还可以安排终端在特定目录中启动 shell.您可以自定义或创建设置配置文件"以在启动时发出cd"命令:

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:

终端 > 首选项 > 设置 > [配置文件] > Shell > 启动 > 运行命令

启用Run command"和Run inside shell",然后将命令设置为cd your_git_directory.当您使用该配置文件打开一个新终端时,它将转到您的 git 目录.

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

终端 > 首选项 > 启动 > 在启动时打开

到您的自定义配置文件.(在 Lion 上,Resume 将恢复您退出时打开的窗口,而不是执行启动操作.正如我提到的,您可以在退出时保持此终端打开,再次打开终端时它将恢复.或者,您退出时可以按 Option 修饰键;退出菜单项将变为退出并放弃 Windows",下次打开终端时它将执行启动操作.)

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天全站免登陆