# Bash functions to level up your aliases game!



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.

STEP 1 
---
We need to make the alias persistent in bash profile.
Open a new bash terminal window and run : 


![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ls5vq9y65hhjc3aptoji.png)


STEP 2 
---
Anywhere in your bashrc file, declare the function as shown below.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ypoovjhs2fydmdofmjg1.png)

STEP 3 
---

Save and exit nano.
 
Here is what we did, we declared `pushtoremote` function, which runs git add . git commit -m `message` and git push `repository` `branch` **consecutively** 

`$1` `$2` `$3` are placeholders for the variables passed to the alias upon executing. `message` `repository` `branch`  (example follows).  

STEP 4 
---

We need to link the alias to the current session, so we can immediately start using it. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/bovrjvlx2tcgyfcepw8v.png)


STEP 5 
---
 
Here is a sample command with `pushtoremote` alias. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/7181zfhmwwo5cnp38wzq.png)



*Note* : some terminals like `fish` do not support `&&` so you will have to replace it with `and`


If you make something extra cool with bash functions, please do let me know. :)))              

I post snippets every day on twitter, join me there! 

Cheers! 

IYO 
 

   


 



  

