26 lines
968 B
Bash
Executable File
26 lines
968 B
Bash
Executable File
#!/bin/bash
|
|
|
|
list-git-folder() {
|
|
if [[ -z "$1" ]]; then
|
|
echo '$1/path is empty.'
|
|
exit
|
|
fi
|
|
|
|
# Define column widths
|
|
local path_width=35
|
|
local url_width=50
|
|
local branch_width=8
|
|
|
|
# Print table header
|
|
printf "| %-${path_width}s | %-${url_width}s | %-${branch_width}s |\n" "PATH" "URL" "BRANCH"
|
|
echo "|$(printf '%*s' $((path_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((url_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((branch_width + 2)) '' | tr ' ' '-')|"
|
|
|
|
local git_folders=$(ls-git-folder "$1")
|
|
for git_folder in $git_folders; do
|
|
local url=$(git config --file .gitmodules --get "submodule.$git_folder.url")
|
|
url=${url#git@github.com:}
|
|
url=${url%.git}
|
|
local branch=$(git -C "$git_folder" branch --show-current 2>/dev/null || echo "detached")
|
|
printf "| %-${path_width}s | %-${url_width}s | %-${branch_width}s |\n" "$git_folder" "$url" "${branch:-detached}"
|
|
done
|
|
} |