Closed rehhouari closed 8 months ago
Under chezmoi cd
you can use:
chezmoi git add run_once_example.sh
or
git add run_once_example.sh
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
Sorry to be clear, I'm looking for the equivilant of chezmoi edit --apply
for scripts
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.
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
andgit.autoPush
enabled thenchezmoi 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
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?
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
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
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
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:
chezmoi edit
uses names in the target directory (e.g. chezmoi edit ~/.bashrc
) not source directory names (e.g. private_dot_bashrc.tmpl
) for usability.chezmoi edit ~/my-script.sh
) as well, even though ~/my-script.sh
never exists.If you have suggestions for a better way to handle these, I'm very happy to hear them!
- 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 😁
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
flagOutput of
chezmoi doctor
Additional context
Thanks for the amazing tool!