Last active
December 3, 2018 19:01
-
-
Save madprops/a94a977e32ba7602f4cdef46e67bf8a8 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) | |
# Edit: Added timeouts for gxmessage. These can be changed. | |
# 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" | |
"/mnt/c/Users/yo/Documents/doctor" | |
"/mnt/c/Users/yo/Documents/www/paste" | |
) | |
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 -timeout 10 -center -bg red -fn "sans 20" "$s" | |
else | |
gxmessage -timeout 3 -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