Mac Qt Creator通过open Terminal Here打开Iterm2的新窗口或者标签页

打开Qt Creator - Preferences - Environment - System - Terminal ,后年直接设置为自己想要使用的脚本即可。

 这里提供两个脚本,一个是直接打开Iterm2的新窗口,一个是打开Iterm2的新标签页。

#! /bin/bash

# ugly escaping: for apple script \ and " need to be escaped, whereas %q takes care of all bash escaping
declare -a args
mydir=`pwd`
mydir=$(printf '%q' "$mydir")
mydir="${mydir//\\/\\\\}"
args[0]="cd ${mydir//\"/\\\"};"
for a in "$@" ; do
    x=$(printf '%q ' "$a")
    x="${x//\\/\\\\}"
    args[${#args[@]}]="${x//\"/\\\"}"
done
mArgs=${args[@]:0}

osascript <<EOF
set cdScript to "$mArgs"
tell application "iTerm2"
    set newWindow to (create window with default profile)
    tell newWindow
        select
        set _session to current session
        tell _session
            write text cdScript
        end tell
    end tell
end tell

第二个是打开新标签页:

#! /bin/bash

# ugly escaping: for apple script \ and " need to be escaped, whereas %q takes care of all bash escaping
declare -a args
mydir=`pwd`
mydir=$(printf '%q' "$mydir")
mydir="${mydir//\\/\\\\}"
args[0]="cd ${mydir//\"/\\\"};"
for a in "$@" ; do
    x=$(printf '%q ' "$a")
    x="${x//\\/\\\\}"
    args[${#args[@]}]="${x//\"/\\\"}"
done
mArgs=${args[@]:0}

osascript <<EOF
set cdScript to "$mArgs"
tell application "iTerm2"
    tell current window to set tb to create tab with default profile
    tell current session of current window to write text cdScript
end tell

注意⚠️:

一定要给脚本文件加上可执行权限,不然不会生效的!

sudo chmod +x newtab.sh

在此感谢

bash - new tab in iTerm2 - Stack Overflowhttps://stackoverflow.com/questions/38692346/new-tab-in-iterm2

macos - How to change terminal in Qt Creator? - Stack Overflowhttps://stackoverflow.com/questions/44573054/how-to-change-terminal-in-qt-creatormacos - open new tab in iTerm and execute command there - Ask Different (stackexchange.com)https://apple.stackexchange.com/questions/110778/open-new-tab-in-iterm-and-execute-command-there

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值