Created
January 10, 2025 07:53
-
-
Save eduard-un/b506f4cb9701004215c6564e108aee3d to your computer and use it in GitHub Desktop.
Bash Script for listing the working branches
This file contains hidden or 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 | |
# 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