-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymlink.sh
executable file
·32 lines (29 loc) · 1.23 KB
/
symlink.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash
# Credit to https://github.com/alrra/dotfiles/blob/main/src/os/create_symbolic_links.sh
# Finds all dotfiles in this folder (except .DS_Store and .macos)
declare -a FILES=$(find . -maxdepth 1 -type f -name ".*" -not -name .DS_Store -not -name .git -not -name .gitconfig -not -name .gitmodules -not -name .macos | sed 's|//|/|g' | sed 's|./.|.|')
# Add the .vim_runtime folder
FILES="$FILES .vim_runtime"
for file in ${FILES[@]}; do
source="$(pwd)/$file"
target="$HOME/$(printf "%s" "$file" | sed "s/.*\/\(.*\)/\1/g")"
if [ -e "$target" ]; then
if [ "$(readlink "$target")" != "$source" ]; then
echo "File already exists: $target"
echo "Do you want to overwrite it? (y/N)"
read -r response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
rm -rf "$target"
ln -sf $source $target
printf "\e[0;32m[✔]\e[0m $target → $source\n"
else
printf "\e[0;31m[✖]\e[0m $target → $source\n"
fi
else
printf "\e[0;32m[✔]\e[0m $target → $source\n"
fi
else
ln -sf $source $target
printf "\e[0;32m[✔]\e[0m $target → $source\n"
fi
done