I'm following the conventional commits standard and I want to make a shell function to do a squash and merge and commit changes with a parsed message, improving my coding speed and my commits consistency.
My problem is to parse the arguments and then use the result in the commit message.
My actual code:
function git_merge_squash() { git merge --squash "$1" shift msg= echo $'\n'"$*" | tr . \\n | tr - ' ' # echo $msg git commit -m $msg } alias gmrs=git_merge_squash
Usage example:
$ gmrs f/my_branch Features.- Signup.-- Save hashed password asynchronously.-- Retrieve token.- Login.-- Retrieve token.- Logout.-- Destroy token
Expected result:
git merge --squash f/my_branch git commit -m " Features Signup Save hashed password asynchronously Retrieve token Login Retrieve token Logout Destroy token"
As you can guess, in my actual code my commented echo
prints exactly the message that I want. But git commit -m
command takes $msg
as a string. I tried multiple other options, like simulating a file input with the -F
flag, but I couldn't work it out.
How can I achieve my goal? Thank you in advance.