This commit is contained in:
2024-09-03 23:14:13 +03:00
commit 1e19d01c56
5 changed files with 119 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
#!/bin/bash
GITHUB_USERNAME="andwati"
DESTINATION_FOLDER=~/GitHub
clone_repositories() {
local parent_dir=$1
local url=$2
# Extract the repository name from the URL
local repo_name=$(basename "${url%.git}")
# Clone the repository into the specified folder
git clone "$url" "$parent_dir/$repo_name"
# Move into the cloned repository folder
cd "$parent_dir/$repo_name" || exit
# If there are submodules, initialize and update them
if [ -f ".gitmodules" ]; then
git submodule init
git submodule update
fi
# Recursively clone submodules if any
if [ -f ".gitmodules" ]; then
git submodule foreach --recursive "$0" "$parent_dir/$repo_name"
fi
# Move back to the parent folder
cd "$parent_dir" || exit
}
repositories=$(curl -s "https://api.github.com/users/$GITHUB_USERNAME/repos?per_page=100" | grep -o 'git@[^"]*')
mkdir -p $DESTINATION_FOLDER
cd "$DESTINATION_FOLDER" || exit
for repository in $repositories; do
clone_repositories "$DESTINATION_FOLDER" "$repository"
done
+40
View File
@@ -0,0 +1,40 @@
#!/bin/sh
# Sync dotfiles repo and ensure that dotfiles are tangled correctly afterward
GREEN='\033[1;32m'
BLUE='\033[1;34m'
RED='\033[1;30m'
NC='\033[0m'
# Navigate to the directory of this script (generally ~/.dotfiles/.bin)
cd $(dirname $(readlink -f $0))
cd ..
echo -e "${BLUE}Stashing existing changes...${NC}"
stash_result=$(git stash push -m "sync-dotfiles: Before syncing dotfiles")
needs_pop=1
if [ "$stash_result" = "No local changes to save" ]; then
needs_pop=0
fi
echo -e "${BLUE}Pulling updates from dotfiles repo...${NC}"
echo
git pull origin main
echo
if [[ $needs_pop -eq 1 ]]; then
echo -e "${BLUE}Popping stashed changes...${NC}"
echo
git stash pop
fi
unmerged_files=$(git diff --name-only --diff-filter=U)
if [[ ! -z $unmerged_files ]]; then
echo -e "${RED}The following files have merge conflicts after popping the stash:${NC}"
echo
printf %"s\n" $unmerged_files # Ensure newlines are printed
else
# Run stow to ensure all new dotfiles are linked
stow .
fi