#!/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 $@
function dovt
{
osascript <<EOF
tell application "iTerm2"
create window with default profile
tell current session of current window
delay 1
write text "cd $PWD"
write text "$@"
end tell
end tell
EOF
}
3条答案
按热度按时间iszxjhcz1#
希望对你有帮助。你可以用iTerm2命令代替iTerm。
x3naxklr2#
无耻的插件,但你可以尝试使用这个small program我为自己建立,这将很容易让你做你想做的事情。
它将允许您指定如下配置文件:
那会做你想要的:-)
smtd7mpg3#
我的版本部分基于@ubuntudroid的评论: