So, I made this shell script that can be called from TexStudio, The scripts calls git to add and commit files with the current date, and then push them to GitHub. I want to improve it's functionality so that I can add a comment and choose which branch I want to commit to. (I based my scripts on this and this comment.)
So far I have made the current macro:
%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/")
}
and a shell script, gitcommitpush.sh
, I added to /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
When I try to execute the macro, TexStudio returns the following error message:
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)
I am unsure why it doesn't work, and could use some help getting the syntax right. Any kind soul here that can help me?
Also, I want to make the macro/script work for all files and directories, so I am trying to find a way to get the macro script to retrieve the path to the main directory, and pass it on to the shell script. Anyone?
+ "\"",
? I think the argument ofsystem
should be a single string.<>
inworkDir
.