macos 如何从终端调用文本编辑器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9421717/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I invoke a text editor from the terminal?
提问by Ceetang
In the Windows command prompt, I can type notepad helloworld.cpp
which will then create a .cppfile with the name helloworldand open up Notepad for me.
在 Windows 命令提示符下,我可以输入notepad helloworld.cpp
它,然后将创建一个名为helloworld的.cpp文件,并为我打开记事本。
Is there a similar function for Mac Terminal, preferably with Textmate or Textedit?
Mac Terminal 有没有类似的功能,最好用 Textmate 或 Textedit?
I'm running Mac OS X Lion 10.7, with Xcode developers tool.
我正在使用 Xcode 开发人员工具运行 Mac OS X Lion 10.7。
采纳答案by pyCthon
There are plenty of ways. Try:
有很多方法。尝试:
vi <filename you want to save or open.cpp>
,pico
,Open /Applications/TextEdit.app <filename>
.
vi <filename you want to save or open.cpp>
,pico
,Open /Applications/TextEdit.app <filename>
.
回答by Vito Gentile
open -e <filename>
The option -e
is used to open the file <filename>
with TextEdit.
该选项-e
用于<filename>
使用 TextEdit打开文件。
回答by ejboy
回答by Roy Miloh
About some of the previous suggestions here - you can use open
command combined with a
flag to open a file with specific application:
关于这里之前的一些建议 - 您可以使用open
命令与a
标志结合使用特定应用程序打开文件:
open -a [appname] [filename]
open -a [appname] [filename]
but if [filename]
doesn't exist it displays an error the file doesn't exists
or something like that, and doesn't create the required file, as you have requested.
但如果[filename]
不存在,它会显示错误the file doesn't exists
或类似的内容,并且不会按照您的要求创建所需的文件。
Write the following to your ~/.bashrc
file (if that file doesn't exists, you can create it by writing touch ~/.bashrc
inside the terminal):
将以下内容写入您的~/.bashrc
文件(如果该文件不存在,您可以通过touch ~/.bashrc
在终端内写入来创建它):
open2()
{
touch
open -a
}
And use it like this:
并像这样使用它:
open2 [appname] [filename]
open2 [appname] [filename]
Note that appname
is an application in your installed application folder (/Applications
).
请注意,这appname
是您安装的应用程序文件夹 ( /Applications
) 中的一个应用程序。
The command touch
creates you the required file (don't worry, if the file exists it won't remove / reset the current file, only redefine the modification time to the current time).
该命令touch
会为您创建所需的文件(别担心,如果文件存在,它不会删除/重置当前文件,只会将修改时间重新定义为当前时间)。
回答by Roy Miloh
If your using text mate you can set it up to work with terminal
如果您使用文本伙伴,您可以将其设置为与终端一起使用
ln -s /Applications/TextMate.app/Contents/Resources/mate ~/bin/mate
Taken from
取自
http://manual.macromates.com/en/using_textmate_from_terminal.html
http://manual.macromates.com/en/using_textmate_from_terminal.html
Once you've got mate into your path you can type the following into the terminal
一旦你进入你的路径,你可以在终端中输入以下内容
mate helloworld.cpp
if you want text mate to display all files in a folder as a project drawer
如果您希望 text mate 将文件夹中的所有文件显示为项目抽屉
mate .
回答by linus
The problem with:
问题在于:
open -e
or
或者
open -a TextEdit
is that you have no control on the TextEdit.app modes: Plain Text or RichText.
是您无法控制 TextEdit.app 模式:纯文本或富文本。
E.g. if you try to open an HTML file, TextEdit will open it in the Rich Text mode, not in the Plain Text mode, as expected. Then switching to the Plain Text mode will not show the HTML tags.
I could not find a Terminal command to activate the Open option:
例如,如果您尝试打开一个 HTML 文件,TextEdit 将按预期以富文本模式而不是纯文本模式打开它。然后切换到纯文本模式将不会显示 HTML 标签。
我找不到激活打开选项的终端命令:
Ignore rich text commands
or the Preference setting:
或首选项设置:
Display HTML files as HTML code instead of formatted text
As far as I can see, even an osascript won't solve the case.
据我所知,即使是 osascript 也无法解决此案。
This is unfortunate since TextEdit.app is the only text editor that is present for sure. Not all Mac users have installed BBedit, TextMate, or any other third party editor and even less users have defined a "default editor".
这很不幸,因为 TextEdit.app 是唯一肯定存在的文本编辑器。并非所有 Mac 用户都安装了 BBedit、TextMate 或任何其他第三方编辑器,甚至更少的用户定义了“默认编辑器”。
回答by Searge
Go to Preferences (?+,) & install shell support.
转到首选项 (?+,) 并安装 shell 支持。
Then you could open any files from terminal with:
然后你可以从终端打开任何文件:
open file.txt
or
或者
mate file.txt
回答by Marc
The answer to the question, for me, was:
对我来说,这个问题的答案是:
leafpad
leafpad