twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
13.36k stars 493 forks source link

Unable to make a script that runs on change of a differrent file. #2944

Closed NikitaMGrimm closed 1 year ago

NikitaMGrimm commented 1 year ago

What exactly are you trying to do?

I am trying to make a script run on change of the hyprland config file.

This is the current script:

!/bin/bash

{{- $HYPRLAND_CONFIG := joinPath .chezmoi.sourceDir "/dot_config/hypr/hyprland.conf.tmpl" -}}
# hyprland config hash: {{ include $HYPRLAND_CONFIG | sha256sum }}

hyprctl reload

The name of the script is run_onchange_before_reload-hyprland.sh.tmpl and it is currently in my .chezmoiscripts directory which is located at ~/.local/share/chezmoi/home/.chezmoiscripts

If I do chezmoi diff after I change the hyprland config, I can see that the hash value changes correctly. Without the template, the commands in the script also seem to run fine if I start it manually.

But if I do chezmoi apply, then I get this error: fork/exec /tmp/XXXXXXXXX.reload-hyprland.sh: no such file or directory

What have you tried so far?

I tried to move the script to the root of chezmoi. I tried to only apply the script changes chezmoi apply --include scripts I tried to change the script to a before script.

Where else have you checked for solutions?

Output of any commands you've tried with --verbose flag

$ chezmoi --verbose apply
diff --git a/.chezmoiscripts/reload-hyprland.sh b/.chezmoiscripts/reload-hyprland.sh
new file mode 100755
index 0000000000000000000000000000000000000000..57bfcc8066398f86c80d70d42ff6f523a3158516
--- /dev/null
+++ b/.chezmoiscripts/reload-hyprland.sh
@@ -0,0 +1,3 @@
+#!/bin/bash# hyprland config hash: f40bd8cd3ae9ed71db3f678db49a5ab6ca78c29b80b47e8f59677575444e5efa
+
+hyprctl reload
chezmoi: fork/exec /tmp/1582096928.reload-hyprland.sh: no such file or directory

Output of chezmoi doctor

```console $ chezmoi doctor ``` ``` RESULT CHECK MESSAGE warning version v2.33.1, built at 2023-04-08T07:27:16Z warning latest-version v2.33.3 ok os-arch linux/amd64 (Arch Linux) ok uname Linux vito 6.2.12-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 20 Apr 2023 16:11:55 +0000 x86_64 GNU/Linux ok go-version go1.20.3 (gc) ok executable /usr/bin/chezmoi ok config-file ~/.config/chezmoi/chezmoi.yaml, last modified 2023-04-22T01:42:46+02:00 ok source-dir ~/.local/share/chezmoi is a git working tree (clean) ok suspicious-entries no suspicious entries ok working-tree ~/.local/share/chezmoi is a git working tree (clean) ok dest-dir ~ is a directory ok umask 022 ok cd-command found /bin/zsh ok cd-args /bin/zsh info diff-command not set ok edit-command found ~/.local/share/bob/nvim-bin/nvim ok edit-args nvim ok git-command found /usr/bin/git, version 2.40.0 ok merge-command found ~/.local/share/bob/nvim-bin/nvim ok shell-command found /bin/zsh ok shell-args /bin/zsh ok age-command found /usr/bin/age, version 1.1.1 ok gpg-command found /usr/bin/gpg, version 2.2.41 info pinentry-command not set info 1password-command op not found in $PATH info bitwarden-command bw not found in $PATH info dashlane-command dcli not found in $PATH info gopass-command gopass not found in $PATH info keepassxc-command keepassxc-cli not found in $PATH info keepassxc-db not set info keeper-command keeper not found in $PATH info lastpass-command lpass not found in $PATH info pass-command pass not found in $PATH info passhole-command ph not found in $PATH info rbw-command rbw not found in $PATH info vault-command vault not found in $PATH info secret-command not set ```

Additional context

twpayne commented 1 year ago

In the verbose output, you can see that the #! line is not correct:

#!/bin/bash# hyprland config hash: f40bd8cd3ae9ed71db3f678db49a5ab6ca78c29b80b47e8f59677575444e5efa

You need a newline after #!/bin/bash. The {{- on line 3 of your script removes all the previous whitespace. Use {{ instead.

NikitaMGrimm commented 1 year ago

Thank you very much :) Have a great day.