This is a series of how I automate making small changes in multiple git repos:
- Script (some of) your git commits
- Tend to your garden of git repos
- Function arguments in bash
- Source an adjacent bash script
Let's have a look at the script in my previous post:
#!/usr/bin/env bash
branch=change-renovate-extends-value
service=
worktree="/tmp//"
commit_message="Change renovate extends value to new shared config repo"
(
default_branch=
if ! ; then
fi
)
As mentioned in that post, I tend to write these kind of scripts every now and then. And when I do, I basically want to have the same safeguards for all of them. A framework if you will.
So, this week, after having written two more almost identical scripts containing all of these safeguard boilerplate, I decided to try to abstract some of it away.
Kinda sorta function argument in bash
It turns out, that if I have some function in bash, I can store the name of that function in a variable, and then just invoke it like ($var_with_name_of_function with some args).
This means that I can send the name of a function as an argument to another function and invoke the first one from the second one. Kind of like a wrapper function.
#!/usr/bin/env bash
This will output the following:
Start
I am in the middle
End
Wrap this up
So, that means I can write a run_in_worktree wrapper:
branch=change-renovate-extends-value
commit_message="Change renovate extends value to new shared config repo"