ghsync (1417B)
1 #!/bin/bash 2 3 # Array mit den Namen der Repositories im Home-Verzeichnis 4 repos=("school" "writing" "obsidian" "sync" "dotfiles") 5 6 # Funktion zum Synchronisieren eines einzelnen Repositories 7 sync_repo() { 8 local repo_path="$1" 9 local commit_message="$2" 10 11 echo "Synchronizing repository: $repo_path" 12 13 # Wechsle ins Repository-Verzeichnis 14 cd "$repo_path" || { echo "Failed to access $repo_path"; return 1; } 15 16 # Pull vom Remote-Repository 17 git pull 18 19 # Alle Änderungen hinzufügen 20 git add -A 21 22 # Änderungen committen 23 git commit -m "$commit_message" 24 25 # Änderungen pushen 26 git push 27 28 # Zurück ins ursprüngliche Verzeichnis 29 cd - > /dev/null 30 } 31 32 # Standard-Commit-Nachricht 33 commit_message="exec" 34 35 # Wenn ein Argument übergeben wurde, verwende es als Commit-Nachricht 36 if [ "$#" -eq 1 ]; then 37 commit_message=$1 38 fi 39 40 # Wenn das Skript im Home-Verzeichnis (~) ausgeführt wird 41 if [ "$PWD" == "$HOME" ]; then 42 # Durchlaufe alle Repositories im Array 43 for repo in "${repos[@]}"; do 44 repo_path="$HOME/$repo" 45 if [ -d "$repo_path/.git" ]; then 46 sync_repo "$repo_path" "$commit_message" 47 else 48 echo "Directory $repo_path is not a git repository." 49 fi 50 done 51 else 52 # Wenn das Skript nicht im Home-Verzeichnis ausgeführt wird, synchronisiere nur das aktuelle Verzeichnis 53 sync_repo "$PWD" "$commit_message" 54 fi 55