dotfiles

regexghost dotfiles and scripts
git clone https://git.regexghost.com/dotfiles.git
Log | Files | Refs | README

setup.sh (1184B)


      1 #!/bin/sh
      2 
      3 file="lists/$2"
      4 
      5 sub="$HOME/.local/bin/sub"
      6 
      7 if [ "$2" = "all" ]; then
      8 	for x in lists/*; do
      9 		"$0" "$1" "$(basename "$x")"
     10 	done
     11 	exit
     12 fi
     13 
     14 exec 3<&0
     15 if [ "$1" = "save" ]; then
     16 	while read -r filepath; do
     17 		repo_path=$(echo "$filepath" | sed "s|~|$2|g")
     18 		real_path=$(echo "$filepath" | sed "s|~|$HOME|g")
     19 		basename=$(basename "$filepath")
     20 		repo_dirname=$(dirname "$repo_path")
     21 		mkdir -p "$repo_dirname"
     22 		echo $filepath
     23 		if grep -q "Start Substitute" "$real_path"; then
     24 			"$sub" save "$basename" "$repo_dirname" "$real_path" <&3
     25 			"$sub" clean "$basename" "$repo_dirname" "$real_path" "$repo_path"
     26 		else
     27 			cp "$real_path" "$repo_path"
     28 		fi
     29 	done < $file
     30 elif [ "$1" = "make" ]; then
     31 	while read -r filepath; do
     32 		repo_path=$(echo "$filepath" | sed "s|~|$2|g")
     33 		real_path=$(echo "$filepath" | sed "s|~|$HOME|g")
     34 		basename=$(basename "$filepath")
     35 		real_dirname=$(dirname "$real_path")
     36 		repo_dirname=$(dirname "$repo_path")
     37 		echo $filepath
     38 		mkdir -p "$real_dirname"
     39 		if grep -q "Start Substitute" "$repo_path"; then
     40 			"$sub" make "$basename" "$repo_dirname" "$repo_path" "$real_path" <&3
     41 		else
     42 			cp "$repo_path" "$real_path"
     43 		fi
     44 	done < $file
     45 fi
     46 exec 3<&-