Simple bash commands to help with forking repo’s and pushing commits.
In this article, I will show you how we can create custom shell commands for automating forking assignments and pushing commits. These commands will help us focus on other productive things by saving our time. This is a very easy setup and will provide further insight into creating your own commands from highly useful to just for fun ones.
1. Open your bash profile
Open Terminal or Linux Shell, and enter the following commands in your terminal:
$ cd ~
$ ls -a
The commands navigate to the root directory, and the second prints out all of the files saved there.
2. Creating custom command file
To create a new file, enter the following command in your terminal:
$ touch ~/.flatIron_bash_commands.sh
Then open this new file up in your preferred text editor, and add the following code inside this newly created file:
#!/bin/bash# git clone, cd into project, npm install, and open in Vscodefunction flatIron {
reponame=${1##*/}
reponame=${reponame%.git}
git clone "$1" "$reponame"
cd "$reponame"
npm install
code .
}
function lazyGit() {
git add .
git commit -m "Completed"
git push origin master
}
You can customize the function names to your preference, and change what text editor the file opens into(currently it’s Vscode). Also you can edit the commit comment(currently it’s set to “Completed”).
After saving the file, we need to make sure that it works, and test it. So return back to terminal and enter the following commands in your terminal:
$ source ~/.flatIron_bash_commands.sh
$ flatIron git@github.com:niraj23/phase-1-array-find-method-lab.git// Make sure to replace the ssh link with your own
// (optional) - Test the git commit function
// While in the assignment directory run:$ lazyGit
Make sure to replace the ssh link with your own. It should run the function and the file should have opened in you preferred text editor.
3. Adding our command to the rc
files:
Now lets enter the following following commands in your terminal:
$ cd ~
$ ls -a
$ code .
// Or open with whatever text editor you're using
Now based on the shell we are using, we will modify either ~/.bashrc
or ~/.zshrc
file. So in your text editor find either of those two files, and paste the following code anywhere in the file and save it.
source ~/.flatIron_bash_commands.sh
Now close terminal and reopen it and you should be able to use the commands everywhere even when we exit and start a new terminal.
4. Zsh Permission Denied Mac
If you get this error at any stage, theres an easy way to fix it.
Give Terminal full access to the disk.
To fix this, go to System Preferences > Security & Privacy > Privacy panel, then add Terminal to the list of apps that are able to control your computer.