Bash ~ never forget to git commit again π₯

I'm a full-stack developer from South Africa πΏπ¦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa πΏπ¦. I love writing about JavaScript, HTML and CSS.
Darn, that is a good idea! Actually thinking of making a desktop app that does all of this π¦
This article is reminding me of how much I really want to learn bash scripting. Itβs really cool to see that you can do things like this with scripts. Thanks for sharing!
Thank you Alyssa! Bash is amazing, and quite easy actually. Very simple commands.
Give it a try with something like this π₯
Shell is amazing, I use if for a lot of small things, cleaning up download folders and finding junk stuff in my mac etc. π€
Thank you Mohd, that means a lot to me! π₯
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

Are you:
Then this article is for you!
Today we will be making a bash script that we can run at the end of our day.
It will loop through our project directory and tell us the following statistics per project:
Have a look at hacking your morning routine!
It will look like this:

Today we'll be looking at a single bash script.
I'm going through this section by section. At the end I'll link it on GitHub for you to download.
We will start by defining our variables
Change the
DIRto your project folder.
DIR=~/www/
GITBASED=.git
Then we need to loop over each subdirectory in our projects folder.
for dir in $DIR*
do
// Loop here
done
Then inside the loop, we need first to check if it's a directory we are checking:
if [[ -d $dir ]]; then
// Yes I'm a directory
fi
You can see we check the dir based on the -d (directory)
If it's a directory, we can work with it:
We'll cd into the directory and define an empty message.
cd $dir
MSG="";
Then we check if it's a git project. If it's not a git project we change our message.
if [ -d "$GITBASED" ]; then
// Git based!
else
// Not a valid git project
MSG=": Not a valid git project π"
fi
If it is a git project, we will first define a test variable that will execute git status.
TEST=$(git status $dir);
Our variable TEST now contains the return value of git status now we will use some if...else statements to check if it contains certain substrings:
if [[ $TEST == *"nothing to commit"* ]]; then
MSG=": No changes β
"
// Check if git status has unstaged changes
elif [[ $TEST == *"Changes not staged for commit"* ]]; then
MSG=": Unstaged changes π€·ββοΈ"
// Check if git status has uncommitted changes
elif [[ $TEST == *"Untracked files"* ]]; then
MSG=": You forgot to commit some files π‘"
fi
And lastly, we will echo the message prefixed with he project name and change back a directory.
echo ${dir##*/}$MSG
cd ..
That's it!
If we run our bash.sh script, we will get all lines per project folder with the status.
Run it with:
sh bash.sh
No more reasons to forget your commits!
Find the project on my GitHub afterwork.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter