twpayne / chezmoi

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

Cannot auto commit/push scripts #3640

Closed rehhouari closed 8 months ago

rehhouari commented 8 months ago

What exactly are you trying to do?

chezmoi cd nano run_once_example.sh # add stuff to it chezmoi edit run_once_micro_plugins.sh # not managed chezmoi add run_once_example.sh # can't add chezmoi file to chezmoi

no way to push it to repository automatically

What have you tried so far?

I tried editing a file to trigger the auto commit, but that is not a solution Tried manually runnig git commit and git push, again this makes auto commit pointless

Where else have you checked for solutions?

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

$ chezmoi --verbose $COMMAND

Output of chezmoi doctor

```console $ chezmoi doctor RESULT CHECK MESSAGE warning version v2.47.1, built at 2024-03-03T07:35:20Z ok latest-version v2.47.1 ok os-arch linux/amd64 (Arch Linux) ok uname Linux arch 6.7.9-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 08 Mar 2024 01:59:01 +0000 x86_64 GNU/Linux ok go-version go1.22.0 (gc) ok executable /usr/bin/chezmoi ok config-file ~/.config/chezmoi/chezmoi.toml, last modified 2024-03-10T05:09:16+01: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 /usr/bin/bash ok cd-args /usr/bin/bash info diff-command not set ok edit-command found /usr/bin/micro ok edit-args /usr/bin/micro ok git-command found /usr/bin/git, version 2.44.0 warning merge-command vimdiff not found in $PATH ok shell-command found /usr/bin/bash ok shell-args /usr/bin/bash info age-command age not found in $PATH ok gpg-command found /usr/bin/gpg, version 2.4.4 info pinentry-command not set info 1password-command op not found in $PATH info bitwarden-command bw not found in $PATH info bitwarden-secrets-command bws not found in $PATH info dashlane-command dcli not found in $PATH info doppler-command doppler 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 vlt-command vlt not found in $PATH info secret-command not set ```

Additional context

Thanks for the amazing tool!

ErrrorMaxx commented 8 months ago

Under chezmoi cd you can use: chezmoi git add run_once_example.sh or git add run_once_example.sh

rehhouari commented 8 months ago

My issue is that after editing the file, do i need to manually use git commit/push? or is there another way to push scripts i'm not aware of

rehhouari commented 8 months ago

Sorry to be clear, I'm looking for the equivilant of chezmoi edit --apply for scripts

twpayne commented 8 months ago

My issue is that after editing the file, do i need to manually use git commit/push? or is there another way to push scripts i'm not aware of

What do you mean by "push"? Do you mean have chezmoi create a git commit containing your changes and push it to your dotfiles repo?

Sorry to be clear, I'm looking for the equivilant of chezmoi edit --apply for scripts

chezmoi edit --apply applies the file, i.e. updates the target file in your home directory (and will also re-run the script if you're editing a script), whenever you save a file. If you have git.autoCommit and git.autoPush enabled then chezmoi edit will also create and push a commit to your dotfiles repo.

Please could you give an exact sequence commands that demonstrates what you want to achieve.

rehhouari commented 8 months ago

What do you mean by "push"? Do you mean have chezmoi create a git commit containing your changes and push it to your dotfiles repo?

Yes exactly! same way it's done for other config files

If you have git.autoCommit and git.autoPush enabled then chezmoi edit will also create and push a commit to your dotfiles repo.

I do and I'm wondering if I can do the same for scripts as well, meaning push them automatically when that setting is present, after i edit them

twpayne commented 8 months ago

I do and I'm wondering if I can do the same for scripts as well, meaning push them automatically when that setting is present, after i edit them

chezmoi should already be doing this. Can you give a way to reproduce a case where it does not?

twpayne commented 8 months ago

Note that when you run chezmoi edit on the script you have to give the script's name without attributes (i.e. without run_, once_, .tmpl, etc.). The easiest way to determine the target path is with the chezmoi target-path command, for example:

$ chezmoi target-path ~/.local/share/chezmoi/run_once_my-script.sh
/home/user/my-script.sh
rehhouari commented 8 months ago

Thanks, I can now edit the file using chezmoi edit --apply ~/my-script.sh and it will auto commit

That however feel unintutive because I created the file inside the chezmoi folder, and the file ~/my-script.sh doesn't exit. I assume it will be created when initializing chezmoi on a second machine? in that case we select a different path, preferably with the script keeping the same name to give it tab completion when editing (ie: chezmoi edit --applyrun_[tab]) and also, to avoid having multiple files inside the home folder.

Was I supposed to create the script another way? I intend to use this to do one time setup on new installations, like installing plugins for micro for example that i always use, and other stuff

Thanks again and sorry

rehhouari commented 8 months ago

I think I figured it out thank you:

cd ~
mkdir .scripts
chezmoi add .scripts
chezmoi cd
nano dot_scripts/run_once_my-script.sh # create it
chezmoi edit --apply ~/.scripts/my-script.sh # edit and update
twpayne commented 8 months ago

That however feel unintutive because I created the file inside the chezmoi folder, and the file ~/my-script.sh doesn't exit.

I agree that it's not initially intuitive, but I'm not sure how else to do it. Assuming you've read about chezmoi's concepts the current approach exists because:

If you have suggestions for a better way to handle these, I'm very happy to hear them!

rehhouari commented 8 months ago
  • even though ~/my-script.sh never exists.

oh i see, so there is no need for a .scripts folder then, I thought chezmoi would create ~/my-script.sh when initialized on a new machine so I thought a directory would help declutter it when there are many scripts.

If you have suggestions for a better way to handle these, I'm very happy to hear them!

Only thing I can come up with is to make scripts handled entirely through commands:

chezmoi script add --once --before my-script # creates {chezmoi_dir}/chezmoi_scripts/run_once_my-script.sh
chezmoi script edit --apply my-script # opens editor
chezmoi script (get-)attributes my-script
# once,before
chezmoi script set-attributes once,before
chezmoi script list 
# content of {chezmoi_dir}/chezmoi_scripts, to avoid storing scripts in db
# my-script (once,before)
chezmoi script delete my-script

and of course checks would be in place for the autoCommit option 😁