From 7b47fb47255946c0dd8eed1a360965e70fbbad47 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Mon, 24 Jun 2024 19:40:42 +0200 Subject: [PATCH] Add script to get git status for all projects --- .bin/projects-status | 71 ++++++++++++++++++++++++++++++++++++++++++++ .config/yadm/encrypt | 1 + 2 files changed, 72 insertions(+) create mode 100755 .bin/projects-status diff --git a/.bin/projects-status b/.bin/projects-status new file mode 100755 index 0000000..f4267d9 --- /dev/null +++ b/.bin/projects-status @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +print_in_color() { + local color="$1" + shift + if [[ -z ${NO_COLOR+x} ]]; then + printf "$color%b\e[0m\n" "$*" + else + printf "%b\n" "$*" + fi +} +red() { print_in_color "\e[31m" "$*"; } +green() { print_in_color "\e[32m" "$*"; } + +projectsrc="$HOME/.config/projectsrc" + +_print_project_status () { + project="$1" + cd "$HOME/$project" || return + + branch=$(git branch --show-current) + if [ -z "$branch" ]; then + return + fi + + remote="origin" + remotes=$(git remote) + if ! echo "$remotes" | grep -q "^$remote$"; then + remote=$(echo "$remotes" | head -n 1) + fi + + + ahead=$(git rev-list --count "$remote/$branch"..HEAD) + if [ "$ahead" -eq 0 ]; then + ahead=$(green "$ahead") + else + ahead=$(red "$ahead") + project=$(red "$project") + fi + + dirty=$(git status --porcelain | wc -l) + if [ "$dirty" -eq 0 ]; then + dirty=$(green "$dirty") + else + dirty=$(red "$dirty") + project=$(red "$project") + fi + + printf "%s\t%s\t%s\t%s\n" \ + "$project" \ + "$branch" \ + "$ahead" \ + "$dirty" +} + +_print_projects_status () { + while read -r next_project + do + if [ -z "$next_project" ]; then + continue + fi + + if [ ! -d "$HOME/$next_project" ]; then + continue + fi + + _print_project_status "$next_project" + done < "$projectsrc" +} + +_print_projects_status | column -t -s$'\t' --table-columns 'Project,Branch,Ahead,Dirty Files' diff --git a/.config/yadm/encrypt b/.config/yadm/encrypt index 6f05e20..3e45726 100644 --- a/.config/yadm/encrypt +++ b/.config/yadm/encrypt @@ -1,5 +1,6 @@ .bin/host-backup-portalo .config/env.d/99-secrets +.config/projectsrc .config/rclone/rclone.conf .local/share/atuin/key .ssh/config