-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus.old
More file actions
executable file
·64 lines (49 loc) · 1.89 KB
/
status.old
File metadata and controls
executable file
·64 lines (49 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# Path to the file containing repository paths
REPOS_FILE="$STATUS_REPO_LIST"
yellow="\e[93m"
_0="\e[0m"
separator="********************************************************************************"
checkmark="✅"
cross="❌"
ahead_behind="🔄"
main() {
if [[ ! -f "$REPOS_FILE" ]]; then echo "$REPOS_FILE not found. Create one."; exit 1; fi
# clear -x
echo -e "Fetching..."
while IFS='=' read -r key value; do
# skip lines which begin with '#'
[[ "$key" =~ ^# ]] && continue
# Skip empty lines or lines that don't contain '='
[ -z "$key" ] || [ -z "$value" ] && continue
# Remove leading and trailing whitespace from key and value
key=$(echo "$key" | xargs)
value=$(echo "$value" | xargs)
if [[ ! -d "${HOME}${value}" ]]; then echo "${HOME}${value} does not exists"; continue; fi
check_git_status "${HOME}${value}" "$key" "$1"
done < "$REPOS_FILE"
}
# Function to check if the output is empty and perform 'git status' accordingly
function check_git_status() {
local repo_dir="$1"
local repo_name="$2"
local verbose="$3"
# Fetch the latest updates from the remote
git -C "$repo_dir" fetch > /dev/null 2>&1
local status_output=$(git -C "$repo_dir" status -s)
local ahead_behind_output=$(git -C "$repo_dir" status -sb | grep -E 'ahead|behind')
if [[ -z "$status_output" && -z "$ahead_behind_output" ]]; then
# Repo is clean and up to date
printf "%-12s: %s\n" "$repo_name" "$checkmark"
else
# Repo is either ahead/behind or has uncommitted changes
printf "%-12s: %s\n" "$repo_name" "$cross"
if [[ -n "$ahead_behind_output" ]]; then
printf " %-10s: %s\n" "Outdated" "$ahead_behind"
fi
if [[ $verbose == '-v' ]]; then
git -C "$repo_dir" status -s
fi
fi
}
main "$1"