-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·92 lines (84 loc) · 2.71 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·92 lines (84 loc) · 2.71 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
base_dir=$(cd "$(dirname "$0")" && pwd)
backup_dir="$base_dir/.backups.local"
backup_prefix="$backup_dir/$(date '+%Y%m%d%H%M%S')"
is_darwin=false
[[ $OSTYPE == darwin* ]] && is_darwin=true
link_file() {
local src=$1 dst=$2
local use_sudo=${3:-false}
local -a command_prefix=()
[[ $use_sudo == true ]] && command_prefix=(sudo)
local backup_dst=false delete_dst=false link_dst=true
if [[ -e $dst ]]; then
current_link=$(readlink "$dst")
if [[ "$current_link" != "$src" ]]; then
while true; do
printf "File already exists: %s. What do you want?\n" "$dst"
printf "[r]eplace; [b]ack up; [s]kip: "
read -r op
case $op in
r )
delete_dst=true
link_dst=true
break;;
b )
backup_dst=true
delete_dst=true
link_dst=true
break;;
s )
link_dst=false
break;;
* )
echo "Unrecognized option: $op";;
esac
done
else
echo "$dst is already linked to $src"
link_dst=false
fi
fi
if [[ "$backup_dst" == "true" ]]; then
mkdir -p "$backup_dir"
local backup_file
backup_file="$backup_prefix$(basename "$dst")"
"${command_prefix[@]}" mv "$dst" "$backup_file"
echo "$dst was backed up to $backup_file"
fi
if [[ "$delete_dst" == "true" ]]; then
"${command_prefix[@]}" rm -rf "$dst"
fi
if [[ "$link_dst" == "true" ]]; then
"${command_prefix[@]}" ln -s "$src" "$dst"
echo "$dst linked to $src"
return 0
fi
return 1
}
if [[ "$base_dir" != "$HOME/dotfiles" ]]; then
link_file "$base_dir" ~/dotfiles
fi
link_file "$base_dir/zsh/zshrc" ~/.zshrc
link_file "$base_dir/zsh/zshenv" ~/.zshenv
link_file "$base_dir/vim/vimrc" ~/.vimrc
if [[ $is_darwin == true ]]; then
link_file "$base_dir/hammerspoon" ~/.hammerspoon
"$base_dir/macos/copy_default_key_binding.sh"
fi
mkdir -p ~/.claude
for f in "$base_dir"/claude/*; do
link_file "$f" ~/.claude/"$(basename "$f")"
done
mkdir -p ~/.codex
for f in "$base_dir"/codex/*; do
[[ $(basename "$f") == config.toml ]] && continue
link_file "$f" ~/.codex/"$(basename "$f")"
done
sudo mkdir -p /etc/codex
link_file "$base_dir/codex/config.toml" /etc/codex/config.toml true
mkdir -p ~/.config
xdg_configs=(nvim tmux git lsd wezterm ghostty yazi)
for name in "${xdg_configs[@]}"; do
link_file "$base_dir/$name" ~/.config/"$name"
done