Skip to content

Instantly share code, notes, and snippets.

@eduard-un
Created January 10, 2025 07:53
Show Gist options
  • Save eduard-un/b506f4cb9701004215c6564e108aee3d to your computer and use it in GitHub Desktop.
Save eduard-un/b506f4cb9701004215c6564e108aee3d to your computer and use it in GitHub Desktop.
Bash Script for listing the working branches
#!/bin/bash
# Function to print folder and branch with colors
print_folder_branch() {
local dir="$1"
# Define colors
FOLDER_COLOR="\033[1;34m" # Blue and bold
BRANCH_COLOR="\033[1;32m" # Green
RESET_COLOR="\033[0m" # Reset to default color
# Check if .git is a directory or a file
if [ -d "$dir/.git" ]; then
# If .git is a directory, get the branch directly
local branch=$(git -C "$dir" rev-parse --abbrev-ref HEAD 2>/dev/null)
elif [ -f "$dir/.git" ]; then
# If .git is a file, resolve the path and get the branch
git_dir=$(cat "$dir/.git" | sed 's/gitdir: //')
# Resolve the relative path to an absolute path
git_dir=$(cd "$dir" && cd "$(dirname "$git_dir")" && pwd)/$(basename "$git_dir")
local branch=$(git --git-dir="$git_dir" rev-parse --abbrev-ref HEAD 2>/dev/null)
else
echo -e "${FOLDER_COLOR}${dir}${RESET_COLOR}: ${BRANCH_COLOR}Not a Git repository${RESET_COLOR}"
return
fi
# Print the folder name in blue and the branch in green
echo -e "${FOLDER_COLOR}${dir}${RESET_COLOR} is on ${BRANCH_COLOR}${branch}${RESET_COLOR}"
}
# List of specific directories to check (relative to current location)
directories=(
"."
"ai-app"
"cloud"
"common"
"core"
"epanel"
"includes/builder-5"
"includes/builder"
)
# Process the specified directories
for dir in "${directories[@]}"; do
print_folder_branch "$dir"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment