AFAIK you can't use only templates for this. One workaround could be to combine templates with custom actions and a bash script.
Preparation
First, write a script that, when given a file, will replace all occurrences of the string $(date)
with the actual date (in some specified format). For instance, create ~/.local/bin/insert_date_into_template
with the contents:
#!/bin/bash
# produce dd/mm/yyyy date, other formats possible
date=$(date +"%d/%m/%Y")
# see https://stackoverflow.com/questions/407523/escape-a-string-for-a-sed-replace-pattern
escaped_date=$(echo "$date" | sed 's/[\/&]/\\&/g')
sed -i 's/$(date)/'"$escaped_date"'/g' "$*"
and make it executable (chmod u+x ~/.local/bin/insert_date_into_template
). Hopefully, ~/.local/bin/
is already in your $PATH
.
Next, define a new custom action, by going to Edit > Configure custom actions in Thunar, and clicking on the plus sign on the side. Choose an appropriate name (say Insert date into template
) and description, and set the command to insert_date_into_template %F
(or, if that doesn't work, ~/.local/bin/insert_date_into_template %F
).
Operation
Now, if you want to have a new file, pre-filled according to the template, but with $(date)
replaced by the current date, you need to carry out two steps:
Create the new file from the template, as you'd normally do (right-click, Create Document etc.).
Invoke the custom action, by right-clicking on the newly created file and selecting Insert date into template
(or whatever you named the custom action, above).
(Note that obviously the template needs to contain the string $(date)
for this to have any effect. Also obviously don't invoke the custom action on the actual, original templates in ~/Templates
!)
Room for improvement
In principle, the process could be condensed to just one step (rather than two), by writing an appropriate custom action. However, things might then get slightly fiddly, as you'd need to have a way of specifying which template (python, LaTeX, cpp etc.) you want to use. (If zenity
is available in Xubuntu, you might use that, for the selection of the template.)
$(today)
within the example snippet, instead of$(date)
! – aplaice Jan 21 at 0:39