I want to use a bash function in a git alias. So I added this to my .bashrc
:
fn() {
echo \"Hello, world!\"
}
export -f fn
If you want to be 100% certain that exported functions will be honored, ensure that the shell being called is bash, not /bin/sh
(which will not honor them if it's implemented by ash or dash).
fn() { echo "hello, world"; }
export -f fn
git config --global alias.fn $'!bash -c \'fn "$@"\' _'
git fn
...properly emits:
hello, world
The relevant entry in .gitconfig
:
[alias]
fn = !bash -c 'fn \"$@\"'