This commit is contained in:
2024-09-03 23:14:13 +03:00
commit 1e19d01c56
5 changed files with 119 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
\.gitignore
\.bin
^/README.*
^/LICENSE.*
\.git
#LICENSE
README.md
/scripts
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 Ian Andwati
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+2
View File
@@ -0,0 +1,2 @@
# dotfiles
My configuration files
+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