是否有类似于“在这里打开命令窗口”的Mac OS Windows Powertoy ?我通过谷歌搜索找到了几个插件,但想看看哪些最适合开发人员。
当前回答
如果你安装了Big Cat Scripts (http://www.ranchero.com/bigcat/),你可以添加自己的上下文菜单(右键单击)项。我不认为它带有一个Open Terminal Here applescript,但我使用这个脚本(我不记得是我自己写的,还是从别人的例子中引用的):
on main(filelist)
tell application "Finder"
try
activate
set frontWin to folder of front window as string
set frontWinPath to (get POSIX path of frontWin)
tell application "Terminal"
activate
do script with command "cd \"" & frontWinPath & "\""
end tell
on error error_message
beep
display dialog error_message buttons ¬
{"OK"} default button 1
end try
end tell
end main
类似的脚本还可以通过右键单击获得文件的完整路径,我发现这更有用。
其他回答
好吧,我意识到有点晚了…也许在我写这篇文章的时候,这个选择还不存在?
不管怎样,我发现通过Fink安装pos包是最简单的解决方案(在这种情况下是先决条件,也许使用MacPorts的人也有类似的方法?)你会得到两个命令:
posd -给出最前端Finder窗口的当前目录(您可以为其创建一个别名cdf=cd posd) fdc -将最前面的Finder窗口的当前目录切换到终端pwd。这与“open .”略有不同,后者总是打开一个新的finder窗口。
是的,在写cdf之前你必须切换到终端窗口,但我认为这比在Finder工具栏中单击一个按钮要便宜得多。它也适用于iTerm,你不需要下载一个单独的Finder工具栏按钮来打开一个iTerm窗口。这与PCheese提出的方法相同,但是您不必使.bash_profile变得混乱。
如果你安装了Big Cat Scripts (http://www.ranchero.com/bigcat/),你可以添加自己的上下文菜单(右键单击)项。我不认为它带有一个Open Terminal Here applescript,但我使用这个脚本(我不记得是我自己写的,还是从别人的例子中引用的):
on main(filelist)
tell application "Finder"
try
activate
set frontWin to folder of front window as string
set frontWinPath to (get POSIX path of frontWin)
tell application "Terminal"
activate
do script with command "cd \"" & frontWinPath & "\""
end tell
on error error_message
beep
display dialog error_message buttons ¬
{"OK"} default button 1
end try
end tell
end main
类似的脚本还可以通过右键单击获得文件的完整路径,我发现这更有用。
vgm64和d0k发布了一个非常漂亮和苗条的开放终端的更新版本。这个改变是由詹姆斯·大卫·洛做出的。他在自己的网站上发布了新版本。只需下载OpenTerminalHere.zip,解压它,将包移动到你的Library/Scripts文件夹,并将它从那里拖到你的Finder工具栏。
它的特别之处在于,如果是终端,它总是打开一个新标签。应用程序窗口已经打开。非常有用!我还注意到,应用程序按钮的风格更适合雪豹Finder。应用程序的风格比cdto发布的编校做。
此外,您可以使用command-C从查找器中复制一个项目,跳转到终端(例如使用Spotlight或QuickSilver)键入'cd '并简单地使用command-v粘贴
我主要使用这个函数:
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,他们就会重用该选项卡。
推荐文章
- 如何强制从另一个SSH会话分离屏幕?
- 如何从终端机发送电子邮件?
- 在Mac OS X上哪里安装Android SDK ?
- Mac/OS X上的/var/lib/docker在哪里
- Xcode构建失败“架构x86_64未定义的符号”
- 在OSX 10.11中安装Scrapy时,“OSError: [Errno 1]操作不允许”(El Capitan)(系统完整性保护)
- 如何在Mac OS X 10.6中使硬件发出哔哔声
- 从Cocoa应用程序执行一个终端命令
- Android Studio无法找到有效的Jvm(与MAC OS相关)
- NSRange从Swift Range?
- 如何在交互式Python中查看整个命令历史?
- 在OSX中永久设置PATH环境变量
- 如何停止mysqld
- Git显示“警告:永久添加到已知主机列表”
- 如何从远程SSH会话发送数据到本地剪贴板