Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·125 lines (105 loc) · 3 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·125 lines (105 loc) · 3 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
#!/usr/bin/env bash
set -euo pipefail
DOTFILES_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
INSTALL_PACKAGES=false
usage() {
cat <<'EOF'
Usage: ./setup.sh [--packages]
Create dotfile links for the current user. Pass --packages to also install
packages for the detected operating system.
EOF
}
while (($#)); do
case "$1" in
--packages)
INSTALL_PACKAGES=true
;;
-h|--help)
usage
exit 0
;;
*)
printf 'Unknown option: %s\n' "$1" >&2
usage >&2
exit 2
;;
esac
shift
done
backup_and_link() {
local source_path="$1"
local target_path="$2"
local backup_path
if [[ -L "$target_path" ]] &&
[[ "$(readlink "$target_path")" == "$source_path" ]]; then
printf 'Already linked: %s\n' "$target_path"
return
fi
if [[ -e "$target_path" || -L "$target_path" ]]; then
backup_path="${target_path}.backup.$(date +%Y%m%d%H%M%S)"
mv -- "$target_path" "$backup_path"
printf 'Backed up: %s -> %s\n' "$target_path" "$backup_path"
fi
ln -s -- "$source_path" "$target_path"
printf 'Linked: %s -> %s\n' "$target_path" "$source_path"
}
install_herdr_copilot_integration() {
local herdr_command
if ! command -v copilot >/dev/null 2>&1; then
printf 'Skipped Herdr Copilot integration: Copilot CLI is not installed.\n'
return
fi
if command -v herdr >/dev/null 2>&1; then
herdr_command="$(command -v herdr)"
elif [[ -x "$HOME/.local/bin/herdr" ]]; then
herdr_command="$HOME/.local/bin/herdr"
else
printf 'Skipped Herdr Copilot integration: Herdr is not installed.\n'
return
fi
if "$herdr_command" integration status |
grep -q '^copilot: current'; then
printf 'Herdr Copilot integration is already installed.\n'
return
fi
"$herdr_command" integration install copilot
}
for path in .zshrc .tmux.conf .gitconfig; do
backup_and_link "$DOTFILES_DIR/$path" "$HOME/$path"
done
mkdir -p "$HOME/.config"
backup_and_link "$DOTFILES_DIR/.tmux" "$HOME/.tmux"
backup_and_link "$DOTFILES_DIR/herdr" "$HOME/.config/herdr"
backup_and_link "$DOTFILES_DIR/nvim" "$HOME/.config/nvim"
if [[ "$INSTALL_PACKAGES" == true ]]; then
case "$(uname -s)" in
Darwin)
"$DOTFILES_DIR/setup/macos.sh"
;;
Linux)
if [[ -r /etc/os-release ]]; then
# shellcheck disable=SC1091
. /etc/os-release
fi
if [[ "${ID:-}" != ubuntu && "${ID_LIKE:-}" != *ubuntu* ]]; then
printf 'Package installation supports Ubuntu only (detected: %s).\n' \
"${ID:-unknown}" >&2
exit 1
fi
"$DOTFILES_DIR/setup/ubuntu.sh"
;;
*)
printf 'Unsupported operating system: %s\n' "$(uname -s)" >&2
exit 1
;;
esac
fi
install_herdr_copilot_integration
if command -v zsh >/dev/null 2>&1; then
zsh_path="$(command -v zsh)"
current_shell="$(readlink -f "${SHELL:-/bin/sh}")"
if [[ "$current_shell" != "$(readlink -f "$zsh_path")" ]]; then
printf 'To use zsh by default, run: chsh -s %q\n' "$zsh_path"
fi
fi
printf 'Dotfiles setup finished.\n'