是否有类似于“在这里打开命令窗口”的Mac OS Windows Powertoy ?我通过谷歌搜索找到了几个插件,但想看看哪些最适合开发人员。
当前回答
这样的:
https://github.com/jbtule/cdto#cd-to
这是一个小的应用程序,你可以拖到Finder工具栏中,图标非常合适。它使用Terminal, xterm(在X11下),term。
其他回答
我主要使用这个函数:
cf() {
cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')"
}
你也可以像下面这样为脚本指定一个快捷方式。
重用一个现有的选项卡或创建一个新窗口(终端):
tell application "Finder" to set p to POSIX path of (insertion location as alias)
tell application "Terminal"
if (exists window 1) and not busy of window 1 then
do script "cd " & quoted form of p in window 1
else
do script "cd " & quoted form of p
end if
activate
end tell
重用一个现有的标签或创建一个新的标签(终端):
tell application "Finder" to set p to POSIX path of (insertion location as alias)
tell application "Terminal"
if not (exists window 1) then reopen
activate
if busy of window 1 then
tell application "System Events" to keystroke "t" using command down
end if
do script "cd " & quoted form of p in window 1
end tell
总是创建一个新标签(iTerm 2):
tell application "Finder" to set p to POSIX path of (insertion location as alias)
tell application "iTerm"
if exists current terminal then
current terminal
else
make new terminal
end if
tell (launch session "Default") of result to write text "cd " & quoted form of p
activate
end tell
与10.7中添加的服务相比,前两个脚本有两个优势:
它们使用标题栏上的文件夹,而不是要求您首先选择一个文件夹。 如果最前面的选项卡不忙,比如运行命令、显示手册页或运行emacs,他们就会重用该选项卡。
这比你要求的要多一点,但我推荐Cocoatech的Path Finder给那些希望Finder有更多果汁的人。它包括一个工具栏按钮,用于打开当前目录的终端窗口,或者在每个Finder窗口的底部有一个带有终端命令行的可伸缩窗格。还有许多我现在生活中不可或缺的功能。非常成熟、稳定的软件。 http://cocoatech.com/
好吧,我意识到有点晚了…也许在我写这篇文章的时候,这个选择还不存在?
不管怎样,我发现通过Fink安装pos包是最简单的解决方案(在这种情况下是先决条件,也许使用MacPorts的人也有类似的方法?)你会得到两个命令:
posd -给出最前端Finder窗口的当前目录(您可以为其创建一个别名cdf=cd posd) fdc -将最前面的Finder窗口的当前目录切换到终端pwd。这与“open .”略有不同,后者总是打开一个新的finder窗口。
是的,在写cdf之前你必须切换到终端窗口,但我认为这比在Finder工具栏中单击一个按钮要便宜得多。它也适用于iTerm,你不需要下载一个单独的Finder工具栏按钮来打开一个iTerm窗口。这与PCheese提出的方法相同,但是您不必使.bash_profile变得混乱。
如果你像我一样关闭了Finder工具栏,这个服务会在每个文件夹的上下文菜单中添加一个条目:http://blog.leenarts.net/2009/09/03/open-service-here/
这还允许您打开在Finder树视图中看到的任何文件夹。
澄清(感谢@vgm64):如果你已经在终端中,这可以让你在不离开终端的情况下快速切换到最上面的Finder窗口。这样,就可以避免使用鼠标。
我已经在我的.bash_profile中添加了以下内容,这样我就可以在任何时候在终端中键入cdff。
function ff { osascript -e 'tell application "Finder"'\
-e "if (${1-1} <= (count Finder windows)) then"\
-e "get POSIX path of (target of window ${1-1} as alias)"\
-e 'else' -e 'get POSIX path of (desktop as alias)'\
-e 'end if' -e 'end tell'; };\
function cdff { cd "`ff $@`"; };
这是macosxhints.com的终端提示。
推荐文章
- 警告用户/local/mysql/data目录不属于mysql用户
- 崇高的文本从命令行
- 在Mac OS X上使用鼠标聚焦(加上自动提升)
- 我在哪里可以找到Mac OS X Lion的“make”程序?
- 当我没有Mac的时候,在Mac/Safari上测试web应用程序
- 在Mac上安装MySQL后,使用ALTER USER语句重置MySQL root密码
- my.cnf文件在macOS上的位置
- 如何从Mac OS X上卸载MySQL ?
- Git bash错误:无法fork子进程:没有可用的终端(-1)
- 使用grep删除空行
- 查找当前可执行文件的路径,不包含/proc/self/exe
- Git在终端提交时打开VIM,但无法返回终端
- 在Mac上安装R -警告消息:设置LC_CTYPE失败,使用“C”
- 为什么cURL返回错误“(23)Failed writing body”?
- 节点和错误:EMFILE,打开的文件太多