Shell脚本:打开2个终端,并自动关闭第一个终端

时间:2013-05-23 10:11:26

标签: shell

我想知道如何修改以下Shell脚本以实现我想要的目标。

该脚本用于MacVim。为了解释它的用途,假设你在gVim中打开一个.tex文件。如果在gVim中运行脚本,则会打开一个新的终端窗口,LaTeXmk(一个自动编译.tex文件的程序)开始运行并编译在gVim中打开的.tex文件。

在此过程中,将打开两个终端窗口。一个用于启动窗口(仅限$ prompt),另一个用于显示LaTeXmk正在运行。由于LaTeXmk运行后不需要第一个窗口,我想在调用脚本后自动关闭它。

有谁能告诉我如何修改脚本以自动关闭第一个终端窗口?

#!/bin/sh 
# 
# Open a new Mac OS X terminal window with the command given 
# as argument. 
# 
# - If there are no arguments, the new terminal window will 
#   be opened in the current directory, i.e. as if the command 
#   would be "cd `pwd`". 
# - If the first argument is a directory, the new terminal will 
#   "cd" into that directory before executing the remaining 
#   arguments as command. 
# - If there are arguments and the first one is not a directory, 
#   the new window will be opened in the current directory and 
#   then the arguments will be executed as command. 
# - The optional, leading "-x" flag will cause the new terminal 
#   to be closed immediately after the executed command finishes. 
# 
# Written by Marc Liyanage <http://www.entropy.ch> 
# 
# Version 1.0 
# 

if [ "x-x" = x"$1" ]; then 
     EXIT="; exit"; shift; 
fi 

if [[ -d "$1" ]]; then 
     WD=`cd "$1"; pwd`; shift; 
else 
     WD="'`pwd`'"; 
fi 

COMMAND="cd $WD; $@" 
echo "$COMMAND $EXIT" 

osascript 2>/dev/null <<EOF 
     tell application "Terminal" 
         activate 
         do script with command "$COMMAND $EXIT" 
     end tell 
EOF 

我在

找到了脚本

http://vim.1045645.n5.nabble.com/latexmk-from-macvim-tt1212353.html

并在帖子中问了一个类似的问题,但到目前为止还没有给出答复。我发现该脚本非常有用,并认为它也可能适用于其他LaTeX用户。

1 个答案:

答案 0 :(得分:2)

该选项不在shell中 - 它位于终端首选项中。打开首选项 - &gt;设置 - &gt;壳牌 - &gt; shell退出时:将其设置为关闭窗口。