commit 8e8b5345f6d0ff28392902a403d365ec4912611e
parent b5290b7bb99bd44f62a561eaf2d498cf25175bf3
Author: Vetle Haflan <vetle@haflan.dev>
Date: Sun, 29 Dec 2019 01:19:47 +0100
Make a simple mode for gits.sh
This mode can be useful for instance in tmux status bar, or dwm status,
for giving a quick overview of the number of repos that aren't synced.
Diffstat:
M | gits.sh | | | 30 | ++++++++++++++++++++++-------- |
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/gits.sh b/gits.sh
@@ -4,6 +4,7 @@
# "Install" with `sudo ln -s $PWD/gits.sh /usr/bin/gits`
__root_dir="$(realpath $1)"
+__simple=$([ "$2" == "-s" ] && echo 1)
__repos=()
findrepos(){
@@ -19,23 +20,32 @@ findrepos(){
done
}
+inform(){
+ [ -z "$__simple" ] || return
+ printf "$1\n"
+}
+
__nrepos_total=0
__nrepos_uptodate=0
checkrepo(){
repo="$1"
cd "$__root_dir/$repo"
branch=("$(git symbolic-ref --short -q HEAD)")
- echo "Checking $repo ($branch)"
+ let __nrepos_total+=1
+ # If not in quiet mode:
+ inform "Checking $repo ($branch)"
if [ -n "$(git status | grep 'Changes not staged')" ]; then
- printf "\e[1;31m> Uncommited changes\e[0m\n"
+ inform "\e[1;31m> Uncommited changes\e[0m"
elif [ -n "$(git status | grep 'branch is ahead')" ]; then
- printf "\e[1;31m> Unpushed commits\e[0m\n"
+ inform "\e[1;31m> Unpushed commits\e[0m"
elif [ -n "$(git status | grep 'Untracked files')" ]; then
- printf "\e[1;33m> Untracked files\e[0m\n"
- else
+ inform "\e[1;33m> Untracked files\e[0m"
+ elif [ -n "$(git status | grep 'up-to-date')" ]; then
let __nrepos_uptodate+=1
+ inform "\e[1;32m> Up-to-date\e[0m"
+ else
+ inform "\e[1;31m> Unrecognized git status. Check manually!\e[0m"
fi
- let __nrepos_total+=1
}
findrepos $__root_dir
@@ -43,5 +53,9 @@ for r in ${__repos[@]}; do
checkrepo $r
done
-echo "-----"
-printf "\e[1;36m$__nrepos_uptodate / $__nrepos_total repos up-to-date\e[0m\n"
+if [ -z "$__simple" ]; then
+ echo "-----"
+ printf "\e[1;36m$__nrepos_uptodate / $__nrepos_total repos up-to-date\e[0m\n"
+else
+ printf "$__nrepos_uptodate / $__nrepos_total repos up-to-date\n"
+fi