Do you use bash aliases to customise your commands?
Of course you do!
But, did you know you can extend aliases to use bash functions and pass arguments?
bash functions enables you to concatenate multiple commands and add as much arguments as you can. Well, just like any function in any programming language.
I came across this when i was looking into condensing git commands. I AM EXTREMELY LAZY, and running git add + git commit + git push every time, really hurts.
So let's make a function that does just that.
We need to make the alias persistent in bash profile.
Open a new bash terminal window and run :
Anywhere in your bashrc file, declare the function as shown below.
Save and exit nano.
Here is what we did, we declared
pushtoremote function, which runs git add . git commit -m
message and git push
$3 are placeholders for the variables passed to the alias upon executing.
branch (example follows).
We need to link the alias to the current session, so we can immediately start using it.
Here is a sample command with
Note : some terminals like
fish do not support
&& so you will have to replace it with
If you make something extra cool with bash functions, please do let me know. :)))
I post snippets every day on twitter, join me there!