문제

today I wanted to write a function which will deploy my blog page (developed in nanoc) to github pages automatically - here's the script:

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;
}

Example usage: cmit "my example commit!"

I don't really know how register my function in system (OSX) - in .bashrc, .bash_profile or maybe somewhere else? Please help!

도움이 되었습니까?

해결책

Just added it to the bottom of your ~/.bashrc file then you will be able to use cmit like a regular command, you will need to refresh your current shell to pick up the changes so run source ~/.bashrc. If you have the function saved in a file cmit just do cat cmit >> ~/.bashrc to append the function to the end of your ~/.bashrc.

You could try out a test function first:

# add to ~/.bashrc first
function test() {
    echo "Some test foo!"
}

$ source ~/.bashrc

$ test
Some test foo!

다른 팁

You can put it in your .bashrc, it will work as long as you're logged as the owner of this .bashrc file.

If you want it to be available for any user, put the content of your function in a script file, make it executable using chmod then move it in /usr/bin (I'm assuming you have admin rights on that system)

Note: typically you'd give it rwx rx rx rights, which corresponds to a chmod 755 my_script

EDIT:

can you create your own lets say .my_bashrc and somehow tell system to look in that file as well?

Yes you could, just tell your .bashrc to source your file:

source ~/my_files/.my_bashrc

or

. ~/my_files/.my_bashrc
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top