Closed VorpalBlade closed 9 months ago
From the manual:
chezmoi sets a number of CHEZMOI* environment variables when running scripts, corresponding to commonly-used template data variables.
That could have been one way (if CHEZMOI_SOURCE_DIR and CHEZMOI_SOURCEFILE had been set), except none of these appear to be set for `modify` scripts.
chezmoi copies modify_
scripts to a file in a temporary directory, sets the executable bit on the file, and then executes them. This is needed even if the modify_
script is not a template as the executable bit is not set in the source directory.
How do I get the original path to this file? Do I simply have to accept that I can't, and make it a
.tmpl
and insert something like:source "{{ .chezmoi.sourceDir }}/{{ .chezmoi.sourceFile}}"
?
Right now, you have to accept that you can't. Note that the .chezmoi.sourceFile
template variable does not exist.
That could have been one way (if CHEZMOI_SOURCE_DIR and CHEZMOI_SOURCEFILE had been set), except none of these appear to be set for `modify` scripts.
That was an oversight. Fixed in #2935.
On Wed, 19 Apr 2023, 00:57 Tom Payne, @.***> wrote:
chezmoi copies modify scripts to a file in a temporary directory, sets the executable bit on the file, and then executes them. This is needed even if the modify script is not a template as the executable bit is not set in the source directory.
How do I get the original path to this file? Do I simply have to accept that I can't, and make it a .tmpl and insert something like: source "{{ .chezmoi.sourceDir }}/{{ .chezmoi.sourceFile}}"?
Right now, you have to accept that you can't. Note that the .chezmoi.sourceFile template variable does not exist.
Yes, it does. And I have used it successfully in modify scripts. It was apparently added in https://github.com/twpayne/chezmoi/issues/1210
That could have been one way (if CHEZMOI_SOURCE_DIR and CHEZMOI_SOURCE_FILE
had been set), except none of these appear to be set for modify_ scripts.
That was an oversight. Fixed in #2935 https://github.com/twpayne/chezmoi/pull/2935.
Good, would be even better if the source file name was also exported this way. :)
— Reply to this email directly, view it on GitHub https://github.com/twpayne/chezmoi/issues/2934#issuecomment-1513887222, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZJM2SENACGU7YB74CXDRTXB4L6TANCNFSM6AAAAAAXDG7JOE . You are receiving this because you authored the thread.Message ID: @.***>
What exactly are you trying to do?
I was trying to be smart and inspect the path to the modify script (in order to detect an associated data file located relative to it). My modify script is actually a config file being executed by a rust program:
The idea was that the rust program would inspect the path to this
modify_
"script" to locate additional data files. However, when chezmoi actually executes this script the path is something like:/tmp/3306499162.Trolltech.conf
.This would make sense if the modify script was templated (
modify_blah.tmpl
) as chezmoi would need to replace things in the file. But that is not the case here, it is NOT a template. How do I get the original path to this file? Do I simply have to accept that I can't, and make it a.tmpl
and insert something like:source "{{ .chezmoi.sourceDir }}/{{ .chezmoi.sourceFile}}"
?Either way, I can't find where this behaviour is documented.
What have you tried so far?
Scratching my head at this (it is late local time...).
Where else have you checked for solutions?
Output of any commands you've tried with
--verbose
flagIrrelevant without the whole setup of my rust program. But if you really want to try it I can setup a test case.
Output of
chezmoi doctor
Additional context
Add any other context about the problem here.