I sometimes use characters such as ! and $ in commit messages, they need to be manually escaped, but not if you use single quotes like this git commit -m 'My $message here!'
. I tried to write a function to make gc
and all text following as the message, but no luck in making it use single quotes. Everything I've tried, it still seems to use double-quotes in the end, making the $message
part hidden, and !
won't work either.
I've tried this:
gc() {
git commit -m ''$*''
}
Also this:
gc() {
message="$*"
git commit -m ''$message''
}
Tried other things too that didn't work, when checking git log
words starting with $
are not shown in the message. It works with single quotes, but it's using double anyway.
I want to run gc My $message here
all text after gc
should be the message, I can't force it to use single quotes, it ends up double. It would output My here
only.
Is there a way to write this function so it would work the way I want? Not sure if this is possible, thanks!
If there is you're smarter than Bard, ChatGPT, Claude, and Bing AI, because I asked them all too, for several hours had no luck.
gc
function. I'm 99% sure the issue is that you are running something likegc Fixed $var
. If you are, the expansion of$var
(and!
) to potentially nothing happens before your func is executed.gc 'I just fixed $var, yay!'
without messing with shell expansion options.