From ec47895eb6e1b024302ffc894aba76175e5720ed Mon Sep 17 00:00:00 2001 From: Daniel Kapla Date: Sun, 7 Jan 2018 15:58:37 +0100 Subject: [PATCH] add: cleanup script, break: makeindex, changed: pdflatex command (no script) --- package.json | 4 ++++ scripts/cleanup.sh | 21 +++++++++++++++++++ scripts/pdflatex.sh | 23 --------------------- src/commands.ts | 50 +++++++++++++++++++++++++++------------------ src/extension.ts | 5 +++++ 5 files changed, 60 insertions(+), 43 deletions(-) create mode 100755 scripts/cleanup.sh delete mode 100755 scripts/pdflatex.sh diff --git a/package.json b/package.json index e30291f..fe14272 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,10 @@ "command": "latex.makeindex", "title": "makeindex", "category": "LaTeX" + }, { + "command": "latex.cleanup", + "title": "Cleanup directory (delete compile helper files)", + "category": "LaTeX" } ], "languages": [ diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh new file mode 100755 index 0000000..f5ad27d --- /dev/null +++ b/scripts/cleanup.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +cleanupDir=${1%/} # remove trailing / if necessary + +echo $cleanupDir + +if [ -d $cleanupDir ]; then # check if cleanupDir is a directory + cd $cleanupDir; +else + echo "Couldn't find directory to clean up" +fi +for file in $cleanupDir/*.*; do + if [ -f $file ]; then + for ending in "log" "ilg" "out" "toc" "aux" "synctex.gz" "idx" "ind"; do + if [[ $file == *.$ending ]]; then + rm "$file" + echo -e "\033[93m rm $file \033[0m" + fi + done + fi +done diff --git a/scripts/pdflatex.sh b/scripts/pdflatex.sh deleted file mode 100755 index 4870896..0000000 --- a/scripts/pdflatex.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -FILEDIRNAME=${1%/*} -FILE=${1##*/} -echo "fileDirname : $FILEDIRNAME" -echo "file : $FILE" - -if [ ${FILE: -4} == ".tex" ]; then - cd "$FILEDIRNAME" - pdflatex -synctex=1 -interaction=nonstopmode -output-directory="$FILEDIRNAME" "$FILE" > ~/.vscode/.pdflatex_log - if [ $? == 0 ]; then # check success status (return value) of the last command (pdflatex) - echo -e "\033[32mCreated \"${FILE%.*}.pdf\" successfully.\033[0m"; - # lsof -- "${FILE%.*}.pdf" > /dev/null; # check if .pdf file if allready opened - # if [ $? != 0 ]; then - # ( nohup evince "${FILE%.*}.pdf" > /dev/null; exit; ) # open the created .pdf - # fi - else - cat ~/.vscode/.pdflatex_log - echo -e "\033[31mERROR: Compiling \"${FILE}\" failed.\033[0m"; - fi -else - echo "$FILE is not a *.tex file." -fi diff --git a/src/commands.ts b/src/commands.ts index 54e4dfe..27c5a1a 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1,5 +1,7 @@ import * as vscode from 'vscode'; import * as child_process from 'child_process'; +import documentclass_symbols from '../dictionary/documentclass_symbols'; +import { window } from 'vscode'; export default { // pdflatex -synctex=1 -interaction=nonstopmode -output-directory="$FILEDIRNAME" "$FILE" > ~/.vscode/.pdflatex_log @@ -9,9 +11,10 @@ export default { var fileDir: string = document.fileName.substring(0, document.fileName.lastIndexOf('/')); document.save(); // save the document before compile - child_process.exec("pdflatex -synctex=1 -interaction=nonstopmode -output-directory=" + fileDir + " " + document.fileName, + child_process.exec( + "pdflatex -synctex=1 -interaction=nonstopmode -output-directory=" + fileDir + " " + document.fileName, { cwd: fileDir }, // set the working directory - (error, stdout, stderr) => { + (error: Error, stdout: string, stderr: string) => { if (error) { vscode.window.showErrorMessage("pdflatex Failed: " + error.message + ", " + stdout); } else { @@ -20,29 +23,36 @@ export default { } ); }, - - // latex_pdflatex: function latex_pdflatex(textEditor: vscode.TextEditor, textEditorEdit: vscode.TextEditorEdit): void { - // textEditor.document.save(); - // child_process.exec( - // "echo $(" + this.extensionPath + "/scripts/pdflatex.sh \"" + textEditor.document.fileName + "\")", - // (error: Error, stdout: string, stderr: string) => { - // if (error) { - // vscode.window.showErrorMessage("pdflatex Failed: " + error.message + ", " + stdout); - // } else { - // vscode.window.setStatusBarMessage("Created File: " + textEditor.document.fileName.replace('.tex', '.pdf'), 5000); - // } - // } - // ); - // }, latex_makeindex: function latex_makeindex(textEditor: vscode.TextEditor, textEditorEdit: vscode.TextEditorEdit): void { - textEditor.document.save(); + var document: vscode.TextDocument = textEditor.document; + var fileDir: string = document.fileName.substring(0, document.fileName.lastIndexOf('/')); + + textEditor.document.save(); // save the document before makeindex child_process.exec( - "echo $(" + this.extensionPath + "/scripts/makeindex.sh \"" + textEditor.document.fileName + "\")", + "makeindex " + document.fileName.substring(0, document.fileName.lastIndexOf('.')) + ".idx", + { cwd: fileDir }, // set the working directory (error: Error, stdout: string, stderr: string) => { if (error) { - vscode.window.showErrorMessage("makeindex Failed: " + error.message + ", " + stdout); + vscode.window.showErrorMessage("makeindex Failed: " + error.stack + ", " + stdout); } else { - vscode.window.setStatusBarMessage("Index Created: " + textEditor.document.fileName.replace('.tex', '.idx'), 5000); + vscode.window.setStatusBarMessage("Index Created:", 5000); + } + } + ); + }, + latex_cleanup: function latex_cleanup(textEditor: vscode.TextEditor, textEditorEdit: vscode.TextEditorEdit): void { + var document: vscode.TextDocument = textEditor.document; + var fileDir: string = document.fileName.substring(0, document.fileName.lastIndexOf('/')); + + child_process.execFile( + "./scripts/cleanup.sh", + [ fileDir ], + { cwd: this.extensionPath }, // set the working directory + (error: Error, stdout: string, stderr: string) => { + if (error) { + vscode.window.showErrorMessage("cleanup Failed: " + error.message + ", " + stdout); + } else { + vscode.window.showInformationMessage(stdout); } } ); diff --git a/src/extension.ts b/src/extension.ts index c1a79b6..ce128c1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -20,6 +20,11 @@ export function activate(context: vscode.ExtensionContext) { Commands.latex_makeindex, { extensionPath: context.extensionPath } )); + context.subscriptions.push(vscode.commands.registerTextEditorCommand( + 'latex.cleanup', + Commands.latex_cleanup, + { extensionPath: context.extensionPath } + )); // Register the Completion Item Provider context.subscriptions.push(vscode.languages.registerCompletionItemProvider(