如何让git使用Textmate作为默认编辑器?

7

如果我在命令行中输入mate <filepath>,它会在TextMate中打开正确的文件。

但是当我执行以下操作时:

$ mate -v
open: invalid option -- v
Usage: open [-e] [-t] [-f] [-W] [-R] [-n] [-g] [-h] [-b <bundle identifier>] [-a <application>] [filenames] [--args arguments]

此外,当我执行git commit时,会看到以下内容:
$ git commit
error: cannot run mate: No such file or directory
error: There was a problem with the editor 'mate'.
Please supply the message using either -m or -F option.

我的~/.bashprofile文件中有以下几行内容:

#Set Textmate as my default editor from the command-line
alias mate='open -a TextMate.app'

export EDITOR="/usr/local/bin/mate -w"

~/.bashrc 中只有这一个内容:

alias mate='open -a TextMate.app'

编辑1

我的~/.gitconfig包含以下内容:

[user]
    name = My Name
    email = myemail@address.com
[core]
    editor = mate
[github]
    user = marcamillion
    token = 50e3iuaidsgadjkhwkjegakjhbsdkjb30432 (don't worry, this is fake)

帮帮我!


而且使用 EXPORT "EDITOR="mate",这样会更好吗? - VonC
@VonC 嗯?不太明白你的意思。我应该编辑哪个文件,写些什么或替换些什么? - marcamillion
@VonC 如果你的意思是我尝试将 export EDITOR="mate" 添加到我的 .bashprofile,那么是的,我刚刚尝试了一下,但它没有起作用。我需要完全关闭终端,还是只需关闭该终端会话并重新打开它即可?我在另一个终端会话中运行着 Rails 服务器,所以我不想关闭它。但如果必须这样做,我可以关闭它。 - marcamillion
@marcamillion:打开一个新会话就足够了。 - CharlesB
是的,我是这个意思,但下面的答案可能更准确。 - VonC
2个回答

12

编辑提交日志信息的编辑器将从GIT_EDITOR环境变量、core.editor配置变量、VISUAL环境变量或EDITOR环境变量(按照此顺序)中选择。

假设mate路径正确,则配置这个的简单方法是运行:

git config --global core.editor "/usr/local/bin/mate -w"

当然,前提是你可以运行/usr/local/bin/mate -w。通过本地用户运行/usr/local/bin/mate -w来检查它是否存在。如果没有找到,你可以使用which mate来查找它是否在路径中存在 - 如果不存在,我认为你需要使用别名中的形式(open -a TextMate.app -w)。

编辑:已将评论纳入答案。


嗯...好建议。我尝试运行/usr/local/bin/mate -w,但它返回了一个-bash: /usr/local/bin/mate: No such file or directory的错误。TextMate可能在哪里?我该如何找到它? - marcamillion
1
@marcamillion,这就是你的问题。尝试使用“which mate”命令来查找它是否存在于你的路径中。 - eis
如果不行的话,我认为你需要使用你别名中的“open -a TextMate.app”。 - eis
就是这样!如果您想修改您的答案,我会接受它。 - marcamillion

6
通过将以下内容添加到 ~/.gitconfig 中的核心部分
[core]
    editor = mate

更新: 如果已经存在,那么问题可能是出在 Textmate 上而不是 Git。

Textmate 2:

在偏好设置中有一个终端选项卡和一个安装按钮, 点击安装后,mate 将在 /usr/local/bin/mate 中,并且一切都应该正常工作。

Textmate 1:

你需要创建一个符号链接 http://manual.macromates.com/en/using_textmate_from_terminal.html

我有 Textmate 1(现在我用 Vim :)。

ls -l `which mate`

lrwxr-xr-x  1 jameskyburz  staff  66 Jul  1  2011 /usr/local/bin/mate -> /Applications/TextMate.app/Contents/SharedSup

将/Applications/TextMate.app/Contents/Resources/mate软链接到/usr/local/bin/mate


已经有了。抱歉,在我的问题中忘记包含它了。我马上更新一下。 - marcamillion

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接