commit 1e19d01c564c44cdd046f23e196b390cc89668d9 Author: Ian Andwati Date: Tue Sep 3 23:14:13 2024 +0300 init diff --git a/.stow-local-ignore b/.stow-local-ignore new file mode 100644 index 0000000..cf8670f --- /dev/null +++ b/.stow-local-ignore @@ -0,0 +1,11 @@ +\.gitignore +\.bin + +^/README.* +^/LICENSE.* + +\.git +#LICENSE +README.md + +/scripts diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..87ae70e --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a0a8f23 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# dotfiles +My configuration files diff --git a/scripts/repo_sync.sh b/scripts/repo_sync.sh new file mode 100755 index 0000000..8f6b5bc --- /dev/null +++ b/scripts/repo_sync.sh @@ -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 diff --git a/scripts/sync-dotfiles b/scripts/sync-dotfiles new file mode 100644 index 0000000..3fe3542 --- /dev/null +++ b/scripts/sync-dotfiles @@ -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