目前使用sublime来作为编辑器,经常需要切换到iTerm2终端来进行文件处理、执行命令。最近升级了iTerm2后发现sublime打不开终端了。在网上找了一圈发现iTerm2的3.0版本的脚本调用方式改了,一直未找到合适的解决方案,实在忍不了了自己动手修改了一下。现在分享一下,方便大家使用。
软件版本:
修复方法
打开sublime_terminal包的根目录,可以看到其中有一个iTerm.sh
文件,这个就是启动iTerm的脚本,启动iTerm失败主要是此脚本的问题。可以直接使用下面脚本替换原文件中的内容:
#!/bin/bash
CD_CMD="cd "\\\"$(pwd)\\\"" && clear"
if echo "$SHELL" | grep -E "/fish$" &> /dev/null; then
CD_CMD="cd "\\\"$(pwd)\\\""; and clear"
fi
VERSION=$(sw_vers -productVersion)
OPEN_IN_TAB=0
while [ "$1" != "" ]; do
PARAM="$1"
VALUE="$2"
case "$PARAM" in
--open-in-tab)
OPEN_IN_TAB=1
;;
esac
shift
done
if (( $(expr $VERSION '<' 10.7) )); then
RUNNING=$(osascript<<END
tell application "System Events"
count(processes whose name is "iTerm2")
end tell
END
)
else
RUNNING=1
fi
if (( ! $RUNNING )); then
osascript<<END
tell application "iTerm"
activate
tell current session of current window
write text "$CD_CMD"
end tell
end tell
END
else
if (( $OPEN_IN_TAB )); then
osascript &>/dev/null <<EOF
tell application "iTerm"
activate
tell current window
select
create tab with default profile
tell current session of current tab
write text "$CD_CMD"
end tell
end tell
end tell
EOF
else
osascript &>/dev/null <<EOF
tell application "iTerm"
create window with default profile
tell current session of current window
write text "$CD_CMD"
end tell
end tell
EOF
fi
fi
也可以新建一个iTerm2_3.sh
的文件,此时需要修改sublime_terminal的配置Preferences > Package Settings > Terminal > Settings – User
:
{
"terminal": "iTerm.sh",
"parameters": ["--open-in-tab"]
}