摘要
我正在尝试编写脚本以通过VS Code在iTerm2中自动启动开发服务器。
当我打开VS Code项目时,我希望bash脚本能够:
问题
我知道如何打开iTerm2,但是我不知道如何制作我编写的bash脚本,然后在iTerm2中运行#2和#3的命令,因为我需要从VS Code终端运行bash脚本,然后打开iTerm2。
答案 0 :(得分:0)
希望它可以帮助您。您可以使用命令iTerm2代替iTerm。
#!/bin/bash
#
# Open new iTerm window from the command line
#
# Usage:
# iterm Opens the current directory in a new iTerm window
# iterm [PATH] Open PATH in a new iTerm window
# iterm [CMD] Open a new iTerm window and execute CMD
# iterm [PATH] [CMD] ... You can prob'ly guess
#
# Example:
# iterm ~/Code/HelloWorld ./setup.sh
#
# References:
# iTerm AppleScript Examples:
# https://gitlab.com/gnachman/iterm2/wikis/Applescript
#
# Credit:
# Inspired by tab.bash by @bobthecow
# link: https://gist.github.com/bobthecow/757788
#
# OSX only
[ `uname -s` != "Darwin" ] && return
function iterm () {
local cmd=""
local wd="$PWD"
local args="$@"
if [ -d "$1" ]; then
wd="$1"
args="${@:2}"
fi
if [ -n "$args" ]; then
# echo $args
cmd="; $args"
fi
osascript &>/dev/null <<EOF
tell application "iTerm"
activate
set term to (make new terminal)
tell term
launch session "Default Session"
tell the last session
delay 1
write text "cd $wd$cmd"
end
end
end tell
EOF
}
iterm $@
答案 1 :(得分:0)
无耻的插头,但是您可以尝试使用我为自己打造的small program,它可以轻松地让您做您想做的事情。
它将允许您指定这样的配置文件:
{
"tabs": [
{
"commands": ["cd /to/other/folder", "cd /to/project && npm start"]
}
]
}
那会做你想要的:-)