在 Mac OS Finder 中打开终端
有没有类似于“在此处打开命令窗口”Windows Powertoy for Mac OS 的东西? 我通过谷歌搜索找到了几个插件,但想看看哪些最适合开发人员。
Is there something similar to the "Open Command Window Here" Windows Powertoy for Mac OS? I've found a couple plugins through a google search but wanted to see what works best for developers out there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
从 Mac OS X Lion 10.7 开始,终端完全包含此功能作为服务。 与大多数服务一样,这些服务默认处于禁用状态,因此您需要启用它才能使其显示在“服务”菜单中。
启用文件夹中的新终端。 还有文件夹中的新终端选项卡,它将在最前面的终端窗口中创建一个选项卡(如果有,否则它将创建一个新窗口)。 这些服务适用于所有应用程序,而不仅仅是 Finder,它们对文件夹以及文本中选择的绝对路径名进行操作。
您甚至可以为它们分配命令键。
服务出现在每个应用程序菜单的“服务”子菜单中以及上下文菜单中(按住 Control 键单击或右键单击文件夹或路径名)。
当您在 Finder 中选择文件夹时,文件夹中的新终端服务将变为活动状态。 您不能简单地打开文件夹并“就地”运行服务。 返回父文件夹,选择相关文件夹,然后通过“服务”菜单或上下文菜单激活服务。
此外,如果您将文件夹(或路径名)拖到终端应用程序图标上,Lion Terminal 将打开一个新的终端窗口,您还可以拖动到现有窗口的选项卡栏来创建新选项卡。
最后,如果将文件夹或路径名拖到选项卡上(在选项卡栏中)并且前台进程是 shell,它将自动执行“cd”命令。 (拖动到选项卡内的终端视图中只会插入路径名,就像在旧版本的终端中一样。)
您还可以从命令行或 shell 脚本执行此操作:
这相当于拖动文件夹的命令行/pathname 到终端应用程序图标上。
与此相关的是,Lion Terminal 还提供了用于查找手册页的新服务:在终端中打开手册页在新的终端窗口中显示选定的手册页主题,以及在终端中搜索手册页 对所选文本执行“apropos”。 前者还可以理解手册页引用(“open(2)”)、手册页命令行参数(“2 open”)和手册页 URL(“x-man-page://2/open”)。
As of Mac OS X Lion 10.7, Terminal includes exactly this functionality as a Service. As with most Services, these are disabled by default, so you'll need to enable this to make it appear in the Services menu.
Enable New Terminal at Folder. There's also New Terminal Tab at Folder, which will create a tab in the frontmost Terminal window (if any, else it will create a new window). These Services work in all applications, not just Finder, and they operate on folders as well as absolute pathnames selected in text.
You can even assign command keys to them.
Services appear in the Services submenu of each application menu, and within the contextual menu (Control-Click or Right-Click on a folder or pathname).
The New Terminal at Folder service will become active when you select a folder in Finder. You cannot simply have the folder open and run the service "in place". Go back to the parent folder, select the relevant folder, then activate the service via the Services menu or context menu.
In addition, Lion Terminal will open a new terminal window if you drag a folder (or pathname) onto the Terminal application icon, and you can also drag to the tab bar of an existing window to create a new tab.
Finally, if you drag a folder or pathname onto a tab (in the tab bar) and the foreground process is the shell, it will automatically execute a "cd" command. (Dragging into the terminal view within the tab merely inserts the pathname on its own, as in older versions of Terminal.)
You can also do this from the command line or a shell script:
This is the command-line equivalent of dragging a folder/pathname onto the Terminal application icon.
On a related note, Lion Terminal also has new Services for looking up man pages: Open man page in Terminal displays the selected man page topic in a new terminal window, and Search man Pages in Terminal performs "apropos" on the selected text. The former also understands man page references ("open(2)"), man page command line arguments ("2 open") and man page URLs ("x-man-page://2/open").
这是:
https://github.com/jbtule/cdto#cd-to
这是一个拖入 Finder 工具栏的小应用程序,图标非常适合。 它适用于终端、xterm(在 X11 下)、iterm。
This:
https://github.com/jbtule/cdto#cd-to
It's a small app that you drag into the Finder toolbar, the icon fits in very nicely. It works with Terminal, xterm (under X11), iterm.
我发现一个不可或缺的替代应用程序是 DTerm,它实际上打开了一个迷你终端在您的应用程序中。 另外,它几乎可以与所有工具兼容 - Finder、XCode、PhotoShop 等。
An application that I've found indispensible as an alternative is DTerm, which actually opens a mini terminal right in your application. Plus it works with just about everything out there - Finder, XCode, PhotoShop, etc.
澄清(感谢@vgm64):如果您已经在终端中,这可以让您快速切换到最上面的Finder窗口,而无需离开终端。 这样,您就可以避免使用鼠标。
我已将以下内容添加到我的
.bash_profile
中,以便我可以随时在终端中输入cdff
。这是来自此 macosxhints.com 终端提示。
Clarification (thanks @vgm64): if you're already in Terminal, this lets you quickly change to the topmost Finder window without leaving Terminal. This way, you can avoid using the mouse.
I've added the following to my
.bash_profile
so I can typecdff
in Terminal at any time.This is from this macosxhints.com Terminal hint.
查看在此处打开终端。 它可能与“在此处打开命令窗口”最相似。 我使用了
>cdto
,这非常相似,但这似乎在处理空格方面更好一些......但并不完美。它非常好的功能是“在应用程序启动时检测按键事件并使用它们来修改脚本的行为”,允许脚本在通过按住 ⌘ 键调用时最前面的终端窗口。 巧妙的技巧。
另请注意 PCheese 的回答; 它对于重度终端用户来说可能更有用!
Check out Open Terminal Here. It may be the most similar to "Open Command Window Here." I used
>cdto
and this is very similar but this seems to be a little better at dealing with Spaces... but not perfect.What it has that is very nice is the ability to "detect key-down events at the start of the application and used them to modify the behavior of the script" allowing the script to open a new tab in the front most terminal window when invoked by holding down ⌘ key. Neat trick.
Also note PCheese's answer; it is probably more useful for heavy terminal users!
vgm64 和 d0k 发布了非常漂亮且纤薄的在此处打开终端的更新版本。 这一改变是由詹姆斯·大卫·洛做出的。 他在他的网站上发布了新版本。 只需下载 OpenTerminalHere.zip,解压,将包移动到 Library/Scripts 文件夹,然后将其从那里拖动到 Finder 工具栏。
它的特别之处在于,如果 Terminal.app 窗口已打开,它总是打开一个新选项卡。 很有用! 我还注意到,应用程序按钮的样式比 redacted 发布的 cdto 更适合 Snow Leopard Finder.app 样式。
There is an updated version of the very nice and slim Open Terminal Here posted by vgm64 and d0k. The change was made by james david low. He published the new version on his site. Just download OpenTerminalHere.zip, extract it, move the bundle to your Library/Scripts folder and drag it from there to your Finder toolbar.
What is special about it is that it always opens a new tab if a Terminal.app window is already open. Very useful! I also noted that the style of the button of the application better fits the Snow Leopard Finder.app style than cdto posted by redacted did.
另外,您可以使用 command-C 从取景器中复制项目,跳到终端(例如使用 Spotlight 或 QuickSilver)输入“cd ”,然后简单地使用 command-v 粘贴
Also, you can copy an item from the finder using command-C, jump into the Terminal (e.g. using Spotlight or QuickSilver) type 'cd ' and simply paste with command-v
我为 Finder 工具栏创建了一个包含 3 个应用程序的捆绑包。
其他两个应用程序执行以下操作:
有关详细信息,请参阅此处:
http://nslog.de/posts/71
I created a bundle with 3 apps for the finder toolbar.
The other two apps do:
For more information see here:
http://nslog.de/posts/71
如果您安装 Big Cat 脚本 (http://www.ranchero.com/bigcat/)可以添加您自己的上下文菜单(右键单击)项目。 我不认为它带有 Open Terminal Here applescript,但我使用这个脚本(我不记得是我自己编写的,还是从其他人的示例中提取的):
类似的脚本也可以让您获得完整的路径右键单击文件,我发现这更有用。
If you install Big Cat Scripts (http://www.ranchero.com/bigcat/) you can add your own contextual menu (right click) items. I don't think it comes with an Open Terminal Here applescript but I use this script (which I don't honestly remember if I wrote myself, or lifted from someone else's example):
Similar scripts can also get you the complete path to a file on right-click, which is even more useful, I find.
这比您要求的要多一点,但我向那些希望 Finder 有更多功能的人推荐 Cocotech 的路径查找器。 它包括一个工具栏按钮,用于打开当前目录的终端窗口,或者在每个 Finder 窗口底部有一个带有终端命令行的可伸缩窗格。 还有许多我现在离不开的其他功能。 非常成熟、稳定的软件。
http://cocoatech.com/
It's a bit more than you're asking for, but I recommend Cocoatech's Path Finder for anyone who wishes the Finder had a bit more juice. It includes a toolbar button to open a Terminal window for the current directory, or a retractable pane with a Terminal command line at the bottom of each Finder window. Plus many other features that I now can't live without. Very mature, stable software.
http://cocoatech.com/
好吧,我意识到这有点晚了……也许在写这篇文章时这个替代方案不可用?
不管怎样,我发现通过 Fink 安装 pos 包(在这种情况下是先决条件,也许对于那些使用 MacPorts 的人来说有类似的东西?)是最简单的解决方案。 您将获得两个命令:
是的,在编写 cdf 之前您必须切换到终端窗口,但我认为与单击 Finder 工具栏中的按钮相比,这相当便宜。 它也适用于 iTerm,您无需下载单独的 Finder 工具栏按钮即可打开 iTerm 窗口。 这与 PCheese 提出的方法相同,但您不必弄乱您的 .bash_profile。
Ok, I realize that this is a bit late... maybe this alternative wasn't available at the moment of writing the post?
Anyway, I've found installing the pos package via Fink (a prerequisite in this case, maybe there is something similar for those who uses MacPorts?) to be the easiest solution. You get two commands:
Yes, you have to switch to the Terminal window before writing cdf, but I suppose that's quite cheap comparing to clicking a button in the Finder toolbar. And it works with iTerm as well, you don't have to download a separate Finder toolbar button that opens an iTerm window. This is the same approach as proposed by PCheese, but you don't have to clutter your .bash_profile.
如果像我一样您关闭了 Finder 工具栏,则此服务会向每个文件夹的上下文菜单添加一个项目: http://blog.leenarts.net/2009/09/03/open-service-here/
这还允许您打开在 Finder 树视图中看到的任何文件夹。
If like me you turn off the Finder toolbar, this Service adds an item to every folder's contextual menu: http://blog.leenarts.net/2009/09/03/open-service-here/
This also allows you to open any folder you see in Finder tree view.
我主要使用这个功能:
您还可以为脚本分配一个快捷方式,如下所示。
重用现有选项卡或创建新窗口(终端):
重用现有选项卡或创建新选项卡(终端):
始终创建新选项卡(iTerm 2):
与 10.7 中添加的服务相比,前两个脚本有两个优点:
I mostly use this function:
You could also assign a shortcut to a script like the ones below.
Reuse an existing tab or create a new window (Terminal):
Reuse an existing tab or create a new tab (Terminal):
Always create a new tab (iTerm 2):
The first two scripts have two advantages compared to the services added in 10.7:
OSX 10.6 上的 AppleScript 存在错误。 (打开 2 个终端窗口)。
我通过在激活后添加关闭命令来修复此问题。 这将关闭第一个终端窗口。
There is a bug in the AppleScript on OSX 10.6. (2 terminal windows open).
I fixed this by adding the close command after activate. This close the first Terminal window.