今天我想编写一个函数来自动将我的博客页面(在 nanoc 中开发)部署到 github 页面 - 这是脚本:
function cmit()
{
nanoc compile;
git add .;
git commit -am $1;
git push origin source;
cd output; git add .;
git commit -am $1;
git push origin master;
cd ..;
echo 'new version deployed! now starting nanoc locally..';
nanoc aco;
}
示例用法:cmit "my example commit!"
我真的不知道如何在系统 (OSX) 中注册我的函数 - 在 .bashrc
、.bash_profile
或其他地方?请帮忙!
最佳答案
只需将它添加到您的 ~/.bashrc
文件的底部,然后您就可以像常规命令一样使用 cmit
,您需要刷新当前的shell 获取更改,因此运行 source ~/.bashrc
。如果您将函数保存在文件 cmit
中,只需执行 cat cmit >> ~/.bashrc
将函数附加到 ~/.bashrc 的末尾
。
您可以先尝试一个测试函数:
# add to ~/.bashrc first
function test() {
echo "Some test foo!"
}
$ source ~/.bashrc
$ test
Some test foo!
关于function - 在系统中注册自定义 shell 函数 (OSX),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14193207/