Repository navigation
Expand file tree
/
Copy pathsetup
More file actions
executable file
·180 lines (160 loc) · 5.98 KB
/
Copy pathsetup
File metadata and controls
executable file
·180 lines (160 loc) · 5.98 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
set -euo pipefail
info() { echo -e " \033[38;5;252m $*\033[0m"; }
success() { echo -e " \033[32m\033[1m $*\033[0m"; }
warn() { echo -e " \033[38;5;137m $*\033[0m"; }
link() {
mkdir -p "$(dirname "$2")"
if [ -L "$2" ]; then
ln -sfn "$1" "$2"
elif [ -e "$2" ]; then
warn "Skipping $2, real file exists (move it aside to link)."
else
ln -s "$1" "$2"
success "Linked $1 to $2"
fi
}
info "Setting caarlos0/dotfiles up"
host="$(hostname -s)"
info "Setting up for $host"
# bins
link "$PWD"/bin ~/.bin
if which tmux &>/dev/null; then
link "$PWD"/tmux/tmux.conf ~/.config/tmux/tmux.conf
tmux source ~/.config/tmux/tmux.conf 2>/dev/null || true
fi
# shell
link "$PWD"/fish/functions ~/.config/fish/functions
link "$PWD"/fish/config.fish ~/.config/fish/config.fish
# ssh
for f in "$PWD"/ssh/*; do
link "$f" ~/.ssh/"$(basename "$f")"
done
if [[ $OSTYPE == 'darwin'* ]] && [ -f ~/.ssh/id_ed25519 ]; then
ssh-add --apple-use-keychain ~/.ssh/id_ed25519 &>/dev/null ||
warn "Could not add SSH key to keychain, skipping"
fi
# terms
link "$PWD"/ghostty/config ~/.config/ghostty/config
link "$PWD"/rio ~/.config/rio
# neovim
if which nvim &>/dev/null; then
link "$PWD"/nvim ~/.config/nvim
fi
# copilot
if which copilot &>/dev/null; then
info "Setting up Copilot CLI"
mkdir -p -m 700 ~/.local/state/copilot-coordinator
copilot_config=$(copilot config --list)
cfg() {
if grep -Fxq -- "$1=$2" <<<"$copilot_config"; then
return
fi
copilot config "$@" >/dev/null
success "Set Copilot $1"
}
while read -r key value || [ -n "$key" ]; do
case "$key" in
"" | \#*) continue ;;
esac
if [ -z "$value" ]; then
warn "Missing value for Copilot setting $key in copilot/config" >&2
exit 1
fi
cfg "$key" "$value"
done <"$PWD"/copilot/config
cfg sandbox.userPolicy.filesystem.readwritePaths "$PWD"
success "Copilot configuration is up to date"
info "Checking Copilot plugin marketplace"
copilot_marketplaces=$(copilot plugin marketplace list)
if ! grep -Fwq andyfeller/plugins <<<"$copilot_marketplaces"; then
info "Installing the infographic Copilot plugin"
copilot plugin marketplace add andyfeller/plugins >/dev/null
copilot plugin install infographic@andyfeller >/dev/null
cfg sandbox.userPolicy.filesystem.readonlyPaths ~/.copilot/installed-plugins/andyfeller/infographic
success "Installed the infographic Copilot plugin"
fi
info "Updating Copilot plugins"
copilot plugin update --all >/dev/null
success "Updated Copilot plugins"
info "Linking Copilot agents and skills"
mkdir -p ~/.copilot/{agents,skills}/
for agent in "$PWD"/agents/*; do
[ -f "$agent" ] || continue
link "$agent" ~/.copilot/agents/"$(basename "$agent")"
done
for skill in "$PWD"/skills/*; do
[ -d "$skill" ] || continue
link "$skill" ~/.copilot/skills/"$(basename "$skill")"
done
if which gh &>/dev/null; then
info "Installing shared Copilot skills"
gh skill install github/gh-stack --agent github-copilot --all --scope user --force >/dev/null 2>&1
gh skill install ayghri/i-have-adhd i-have-adhd --agent github-copilot --scope user --force >/dev/null 2>&1
success "Installed shared Copilot skills"
else
warn "GitHub CLI not found, skipping shared Copilot skills" >&2
fi
info "Generating Copilot Fish completions"
mkdir -p ~/.config/fish/completions/
copilot completion fish >~/.config/fish/completions/copilot.fish
success "Copilot CLI setup complete"
else
warn "Copilot CLI not found, skipping Copilot setup" >&2
fi
# other apps
link "$PWD"/.editorconfig ~/.editorconfig
link "$PWD"/hammerspoon/init.lua ~/.hammerspoon/init.lua
if [ -f "$PWD"/hammerspoon/apps."$host".lua ]; then
link "$PWD"/hammerspoon/apps."$host".lua ~/.hammerspoon/apps.lua
else
warn "No hammerspoon/apps.$host.lua, skipping app hotkeys."
fi
link "$PWD"/git/config ~/.config/git/config
link "$PWD"/git/gitignore ~/.config/git/ignore
link "$PWD"/gh/config.yml ~/.config/gh/config.yml
# Remove only links to this checkout's retired extensions.
for name in gh-wait-push gh-wait-review; do
ext="$HOME/.local/share/gh/extensions/$name"
if [ -L "$ext" ] && [ "$(readlink "$ext")" = "$PWD/gh/extensions/$name" ]; then
rm "$ext"
success "Removed retired extension $name"
fi
done
for ext in "$PWD"/gh/extensions/*; do
[ -x "$ext/$(basename "$ext")" ] || continue
link "$ext" ~/.local/share/gh/extensions/"$(basename "$ext")"
done
link "$PWD"/gh-dash/config.yml ~/.config/gh-dash/config.yml
link "$PWD"/fd/ignore ~/.config/fd/ignore
link "$PWD"/direnv ~/.config/direnv
link "$PWD"/prowl ~/.config/prowl
link "$PWD"/copilot/copilot-instructions.md ~/.copilot/copilot-instructions.md
link "$PWD"/copilot/lsp-config.json ~/.copilot/lsp-config.json
link "$PWD"/copilot/mcp-config.json ~/.copilot/mcp-config.json
if [[ $OSTYPE == 'darwin'* ]]; then
if [ -f "$PWD"/Brewfile."$host" ]; then
brew cleanup --scrub --prune 0
info "Installing packages from Brewfile.$host - may ask for your password"
# Keep brew's "Installing X" lines (they explain any password prompt), but
# drop already-installed entries and mas' Spotlight indexing noise. awk
# always exits 0, so pipefail still reports brew's own failures.
brew bundle --file="$PWD"/Brewfile."$host" 2>&1 |
awk 'NF && !/^Using / && !/indexed in Spotlight|Indexing now|MAS_NO_AUTO_INDEX/'
else
warn "No Brewfile.$host, skipping brew bundle."
fi
fi
# Rust components are managed by rustup so they match the active toolchain.
rustup component add rust-analyzer rust-src rustfmt clippy &>/dev/null ||
warn "Could not add rust components (is rustup set up?)"
# Fish setup
if ! grep -q fish /etc/shells; then
info "Adding $(which fish) to /etc/shells - will ask sudo password"
which fish | sudo -p "Password for %u (needed to write to /etc/shells): " tee -a /etc/shells
fi
if ! finger "$USER" | grep -q 'Shell: .*fish'; then
info "Setting $(which fish) as the default shell - will ask user password"
chsh -s "$(which fish)"
fi
success "All done!"