-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink_dotfiles.sh
More file actions
47 lines (38 loc) · 1.65 KB
/
link_dotfiles.sh
File metadata and controls
47 lines (38 loc) · 1.65 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env zsh
set -euo pipefail
echo "「シンボリックリンク」の作成を開始しました"
DOTFILES_DIR="$HOME/dotfiles"
# リンクを作成するファイル一覧(キー:シンボリックリンク先、値:dotfiles内の実ファイル)
LINKS=(
"$DOTFILES_DIR/zsh/.zshrc:$HOME/.zshrc"
"$DOTFILES_DIR/zsh/.zshenv:$HOME/.zshenv"
"$DOTFILES_DIR/git/.gitconfig:$HOME/.gitconfig"
"$DOTFILES_DIR/git/.gitignore:$HOME/.gitignore"
"$DOTFILES_DIR/git/.gitattributes:$HOME/.gitattributes"
"$DOTFILES_DIR/asdf/.tool-versions:$HOME/.tool-versions"
"$DOTFILES_DIR/aws/config:$HOME/.aws/config"
"$DOTFILES_DIR/vscode/settings.json:$HOME/Library/Application Support/Code/User/settings.json"
"$DOTFILES_DIR/android/sdk:$HOME/Library/Android/sdk"
"/opt/homebrew/share/android-commandlinetools/cmdline-tools/latest:$DOTFILES_DIR/android/sdk/cmdline-tools/latest"
)
# すべてのリンクを作成
for link in "${LINKS[@]}"; do
src=$(echo "$link" | cut -d':' -f1)
dest=$(echo "$link" | cut -d':' -f2)
# 親ディレクトリが無ければ作成
mkdir -p "$(dirname "$dest")"
# 既存のファイルやリンクがあればバックアップ
# if [ -e "$dest" ] || [ -L "$dest" ]; then
# echo "$dest をバックアップ: ${dest}.backup"
# mv "$dest" "${dest}.backup"
# fi
# 既存のファイルやリンクを削除(バックアップは取らない)
if [ -e "$dest" ] || [ -L "$dest" ]; then
echo "既存の $dest を削除"
rm -rf "$dest"
fi
# シンボリックリンクを作成
echo "$src → $dest"
ln -s "$src" "$dest"
done
echo "「シンボリックリンク」の作成が完了しました"