-
Hello, I would like to name my output file with the current timestamp. I have attempted a few approaches, but I couldn't get them to work. Are there any effective methods to achieve this? // settings.json
{
//...
"latex-workshop.latex.tools": [
//...
{
"name": "rename",
"command": "mv",
"args": [
"%OUTDIR%/doc.pdf",
"%OUTDIR%/$(date +%Y_%m_%d).pdf"
],
"env": {}
}
],
"latex-workshop.latex.recipes": [
{
"name": "pdflatex",
"tools": [
"pdflatex",
"makeglossaries",
"biber",
"pdflatex",
"pdflatex",
"rename"
]
}
]
} |
Beta Was this translation helpful? Give feedback.
Answered by
jlelong
Dec 24, 2023
Replies: 2 comments
-
Unfortunately, there is no way to insert shell commands into |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
JOOmsH
-
Thanks for the hint. // settings.json
{
//...
"latex-workshop.latex.tools": [
//...
{
"name": "rename",
"command": "./rename.sh",
"args": [
"%OUTDIR%/thesis.pdf",
"thesis"
],
"env": {}
}
]
//..
} #!/bin/bash
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <file_path> <new_file_name>"
exit 1
fi
file_path=$1
new_file_name=$2
if [ ! -f "$file_path" ]; then
echo "Error: The specified file does not exist."
exit 1
fi
extension="${file_path##*.}"
timestamp=$(date +"%Y%m%d%H%M")
new_file_name_with_timestamp="${timestamp}_${new_file_name}"
new_file_path="$(dirname "$file_path")/$new_file_name_with_timestamp.$extension"
mv "$file_path" "$new_file_path" 2>/dev/null
if [ $? -eq 0 ]; then
echo "File successfully renamed to $new_file_path."
else
echo "Error: File rename failed."
fi
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately, there is no way to insert shell commands into
args
as the command is not passed to a shell. The only solution I can think of is to write a dedicated script and to add it tolatex-workshop.latex.tools
.