فهرست منبع

Sat Jul 13 11:33:51 AM BST 2024

Gabriel Capella 4 ماه پیش
والد
کامیت
2d810194e2
1فایلهای تغییر یافته به همراه22 افزوده شده و 14 حذف شده
  1. 22 14
      start

+ 22 - 14
start

@@ -1,13 +1,15 @@
 #!/bin/bash
 
-dot_dir=$HOME/.dofiles
+checkout_dir=$HOME/.dofiles
+script_dir=$checkout_dir/dotfiles
+dots_dir=$checkout_dir/dotfiles/dots
 repo="https://git.capella.pro/capella/dotfiles.git"
 
 set -ex
 trap popd EXIT
 
-mkdir -pv $dot_dir
-pushd $dot_dir
+mkdir -pv $checkout_dir
+pushd $checkout_dir
 
 
 sub_help(){
@@ -21,25 +23,31 @@ sub_help(){
 }
 
 sub_sync(){
-    if [[ ! -d $dot_dir/dotfiles/.git ]]; then
+    if [[ ! -d $checkout_dir/dotfiles/.git ]]; then
         git clone $repo
         pushd dotfiles
         git submodule init
-        git submodule update
         popd
     fi
-    mkdir -p dotfiles/dots
-    cd dotfiles/dots
-    git pull
+
+    cd $script_dir
+    git pull origin master
+    git checkout master
+    git submodule update
+
     if [ ! -z "$1" ]; then
         real_path=$(realpath $1)
         to_copy=${real_path#*$HOME}
-        cp -R $real_path $(pwd)$to_copy
-        rm -rf $real_path
+        cp -R $real_path $dots_dir/$to_copy
+        mv -rf $real_path
         echo "${to_copy/\//}" >> ../to_sync
     fi
-    cd ..
-    git add .
+
+    while read p; do
+        file="$dots_dir/$p"
+        git add $file
+    done < $script_dir/to_sync
+
     if git commit -am "$(date)"; then
         git remote add origin $repo || true
         git push -u origin master
@@ -48,8 +56,8 @@ sub_sync(){
     while read p; do
         destination="$HOME/$p"
         rm -rf $destination
-        ln -s "$dot_dir/dotfiles/dots/$p" $(dirname $destination)
-    done <to_sync
+        ln -s "$dots_dir/$p" $destination
+    done < $script_dir/to_sync
 }