需要 TexStudio 宏的帮助来调用 shell 脚本

需要 TexStudio 宏的帮助来调用 shell 脚本

所以,我做了这个脚本可以从 TexStudio 调用,脚本调用 git 添加和提交具有当前日期的文件,然后将它们推送到 GitHub。我想改进它的功能,以便我可以添加评论并选择要提交到哪个分支。(我的脚本基于评论。)

到目前为止我已经制作了当前的宏:

%SCRIPT
dialog = new UniversalInputDialog()
    dialog.setWindowTitle("Git commit and push")
    dialog.add("add comment", "Comment", "comment")
    dialog.add("master", "Branch", "branch")
if (dialog.exec() != null) {
    comment = dialog.get("comment")
    branch = dialog.get("branch")
    workDir = "/home/user/directory/path/"
    system("sh gitcommitpush.sh " + workDir + "\"" + comment+ " \"" + branch + "\"", workingDirectory="/home/user/directory/path/")
}

以及一个 shell 脚本,gitcommitpush.sh我将其添加到/usr/local/bin

#!/bin/sh

comment="$1"
branch="$2"
dir="$3"

#First, I set the path to master directory
cd "$3" 

# Then I add all files in the local repository and stages them for commit:
git add .

# Then I want to check if a comment has been added. If only the generic comment "add comment" is unchanged, I want the script to simply commit with the current date as comment. Otherwise, I commits the changes with current date and the comment passed on from the TexStudio macro.

if [ $comment == "add comment" ]
then
git commit -a -m `date "+%d._%B_%Y_%H:%M:%S_%Z"`
else
git commit -a -m `date "+%d._%B_%Y_%H:%M:%S_%Z_$comment"`
fi

# Last I want to push the changes in your local repository up to the specified branch in the remote repository:

git push origin $branch

当我尝试执行宏时,TexStudio 返回以下错误消息:

The specified stdout redirection is not supported: "> "add comment "master"". Please see the manual for details.

Process started: sh gitcommitpush.sh <path to file

/usr/bin/sh: 0: Can't open gitcommitpush.sh

Process exited with error(s)

我不确定为什么它不起作用,需要一些帮助才能使语法正确。这里有谁能帮助我吗?

另外,我想让宏/脚本适用于所有文件和目录,因此我试图找到一种方法让宏脚本检索主目录的路径,并将其传递给 shell 脚本。有人知道吗?

相关内容