Skip to content

Instantly share code, notes, and snippets.

@applicato
Forked from madprops/gitcheck.sh
Created September 26, 2018 13:02
Show Gist options
  • Select an option

  • Save applicato/a5260de7f3f59af28ce39fdc3cbca9c0 to your computer and use it in GitHub Desktop.

Select an option

Save applicato/a5260de7f3f59af28ce39fdc3cbca9c0 to your computer and use it in GitHub Desktop.
Bash script to check if any of the git locations in a list have uncommitted changes and show output in a GUI alert box using gxmessage
#!/bin/bash
# Depends on the gxmessage package
# This is a script that will check all git repos in the location array
# Then it will check the output length of git diff
# If there's output in any of them it will show a red warning with their location
# If not it will show an "All good" message in green
# This is useful to keep various git repos in check with a simple command (or keypress if you map it)
# For this to work, it's suggested you disable warnings that can cause git diff output to vary
# For instance I need to do "git config --global core.safecrlf false"
# To avoid line ending warnings
# Some space formatting here on strings is on purpose
# I mapped this to F12 on Openbox, here's how:
#<keybind key="F12">
# <action name="Execute">
# <command>/mnt/c/Users/yo/Documents/stuff/gitcheck.sh</command>$
# </action>
#</keybind>
s=""
modified=0
locations=(
"/mnt/c/Users/yo/Documents/hue"
"/mnt/c/Users/yo/Documents/huebot"
"/mnt/c/Users/yo/Documents/msg"
)
for i in "${locations[@]}"
do
cd "$i"
diff=$(git diff | cat | wc -m)
if (( diff > 0 )); then
s=" $s
$i has changes"
modified=$((modified + 1))
fi
done
if (( modified > 0 )); then
gxmessage -center -bg red -fn "sans 20" "$s"
else
gxmessage -center -bg green -fn "sans 20" "All good!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment