-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·159 lines (136 loc) · 6.06 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·159 lines (136 loc) · 6.06 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
#!/bin/bash
DOTFILES="$(dirname "$(realpath "$0")")"
if_exists_bak() {
if [[ ! -L "${1}" && -f "${1}" ]]; then
# Backup: In case where dotfile at location already exists
if [[ ! -f "${1}.bak" ]]; then
# Do not overwrite current bak
mv "${1}"{,.bak}
else
# write a new bak suffix if more backups already exist
count=1
while true; do
if [[ ! -f "${1}.${count}.bak" ]]; then
mv "${1}.${count}" "${1}.${count}.bak"
((count++))
break 1
fi
done
fi
return 0
elif [[ -L "${1}" ]]; then
# symlink case
echo "Symlink '${1}' -> '$(readlink -f $1)' already exists"
return 1
else
printf "no file ${1} found\nAdding ${1}...\n"
return 0
fi
}
install_tmux_completion() {
tmux -V > /dev/null 2>&1 || exit 1
curl "https://raw.githubusercontent.com/Bash-it/bash-it/master/completion/available/tmux.completion.bash" |\
sed '1,10 s/^/#/' \
> "${DOTFILES}/tmux.completion.bash"
}
check_decision() {
local _human_readable_message="$1" _command="$2"
echo "Do you want to run \"$_command\" ?"
printf "%s" "$_human_readable_message "
read -rp " (y/n/q)? " y_n_q
msg="option selected"
case "$y_n_q" in
y|Y|Yes|yes ) echo "'${y_n_q}' $msg'"; $_command ;;
n|N|No|no ) echo "'${y_n_q}' $msg, skipping";;
q|Q|Quit|quit ) echo "'${y_n_q}' $msg, quitting"; return;;
* ) echo "invalid";;
esac
}
prompt_to_install_conda() {
os2kernel="$(uname -a | rev | cut -d ' ' -f1 | rev)"
IFS=', ' read -r -a array <<< "$(curl "https://repo.anaconda.com/miniconda/" \
| awk -F'</*td>' '$2{print $2}' \
| xargs -n5 | grep "${os2kernel}" | grep "py310" \
| sed 's/href=\([^>]*\).*/\1/g;s/<a//g')" # Using vanilla sed is safer
if [ "${#array[@]}" -eq 0 ]; then
echo "No conda installer found."
exit 1
fi
# shellcheck disable=SC2145
printf "Found conda installer: %s\n" "${array[@]}"
url_conda_target="https://repo.continuum.io/miniconda/${array[0]}"
curl -Lo "${array[0]}" "${url_conda_target}"
chmod +x "${array[0]}" || sudo !!
bash "${array[0]}" || exit 1
rm "${array[0]}"
}
create_pynvim_conda_env() {
echo
echo "* Checking for conda environment location"
environment_location="$(find / -mindepth 1 -maxdepth 3 -type d -iname "miniconda*" | head -n1)"
if [ -d "$environment_location" ] && $_REINSTALL_CONDA; then
human_readable_message="Do you want to remove ${environment_location} before reinstalling?"
_command="rm -r \"${environment_location}\""
check_decision "$human_readable_message" "$_command" || check_decision "$human_readable_message" "sudo ${_command}"
fi
PYNVIM_ENV_YAML="./vimrc/pynvim-env.yaml"
if [ -d "${environment_location}/$(grep "name:" "${PYNVIM_ENV_YAML}" | awk '{print $2}')" ]; then
conda env create -f "${PYNVIM_ENV_YAML}" -n pynvim
else
echo "* Assuming pynvim conda env already exists..."
environment_location=$(conda env create -f "${PYNVIM_ENV_YAML}" -n pynvim 2>&1 | grep -v "^$" | sed 's/.*exists: //g')
[ -n "$environment_location" ] && echo "* Found $environment_location" || echo "No conda environment location found"
conda env update -f "${PYNVIM_ENV_YAML}" --prune
fi
export CONDA_PYNVIM_ENV_PYTHON_PATH="$environment_location/bin/python3"
}
install_tpm() {
[ -d "${HOME}/.tmux/plugins" ] || mkdir -pv "${HOME}/.tmux/plugins"
git clone "https://github.com/tmux-plugins/tpm" "${HOME}/.tmux/plugins/tpm"
}
install_gruvbox() {
curl -Lo "Gruvbox.itermcolors" "https://raw.githubusercontent.com/runxel/gruvbox-iterm/84ca3c759ab9b9f2a2ede9a32446adb37f3761b6/Gruvbox.itermcolors"
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
# If this is being used as a script (e.g. `$ ./setup.sh`)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
export PATH="$HOME/homebrew/bin:$PATH"
brew bundle && echo '[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"' >> "${HOME}/.bash_profile"
for dotfile in bashrc bash_functions bash_aliases inputrc tmux.conf curlrc gitconfig hushlogin; do
if_exists_bak "$HOME/.${dotfile}" && ln -sv "$DOTFILES/${dotfile}" "$HOME/.${dotfile}"
done
install_tmux_completion
install_gruvbox
if ! (which conda > /dev/null 2>&1); then
prompt_to_install_conda
echo "Please rerun the installation script after running\n. ${HOME}/.bashrc to ensure the base conda env is activated"
rm ./Miniconda*.sh && exit 1
else
echo "* Skipping miniconda installation. A conda installation was found at $(realpath $(which conda))"
fi
if ! (which ollama > /dev/null 2>&1); then
# Install Ollama
curl -fsSL https://ollama.com/install.sh | sh
fi
if [ -d $DOTFILES/vimrc ] && [ ! -d $DOTFILES/.config/nvim ]; then
# Symlink neovim config submodule (at ~/.dotfiles/.gitmodules )
ln -s "$DOTFILES/vimrc" "$HOME/.config/nvim"
fi
create_pynvim_conda_env
# Symlink agent skills to all discovery paths
# Source of truth: ~/.dotfiles/skills/<name>/SKILL.md
# Targets: ~/.config/opencode/skills/, ~/.claude/skills/, ~/.agents/skills/
if [ -d "$DOTFILES/skills" ]; then
for skills_target in "$HOME/.config/opencode/skills" "$HOME/.claude/skills" "$HOME/.agents/skills"; do
mkdir -p "$skills_target"
for skill_dir in "$DOTFILES/skills"/*/; do
skill_name=$(basename "$skill_dir")
if [ ! -L "$skills_target/$skill_name" ]; then
ln -sv "$DOTFILES/skills/$skill_name" "$skills_target/$skill_name"
fi
done
done
echo "* Agent skills symlinked to opencode, claude, and agents discovery paths"
fi
echo "Tip: Go to https://www.nerdfonts.com/font-downloads and download a nerdfont with glyphs for neovim"
fi