-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·107 lines (88 loc) · 3.12 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·107 lines (88 loc) · 3.12 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
#!/usr/bin/env bash
set -euo pipefail
DOTFILES_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
BACKUP_ROOT="$DOTFILES_DIR/_backups/$(date +%Y%m%d-%H%M%S)"
BACKUP_CREATED=0
APPLY_MACOS_DEFAULTS=0
usage () {
printf 'Usage: %s [--macos-defaults]\n' "${0##*/}"
}
for argument in "$@"; do
case "$argument" in
--macos-defaults) APPLY_MACOS_DEFAULTS=1 ;;
-h|--help)
usage
exit 0
;;
*)
printf 'Unknown option: %s\n' "$argument" >&2
usage >&2
exit 2
;;
esac
done
backup_target () {
local target="$1"
local relative backup
relative="${target#"$HOME"/}"
backup="$BACKUP_ROOT/$relative"
mkdir -p "$(dirname -- "$backup")"
mv -- "$target" "$backup"
BACKUP_CREATED=1
printf 'Backed up %s -> %s\n' "$target" "$backup"
}
link_item () {
local source="$1"
local target="$2"
if [[ ! -e "$source" ]] && [[ ! -L "$source" ]]; then
printf 'Missing source: %s\n' "$source" >&2
return 1
fi
if [[ -L "$target" ]] && [[ "$(readlink "$target")" == "$source" ]]; then
return 0
fi
if [[ -e "$target" ]] || [[ -L "$target" ]]; then
backup_target "$target"
fi
mkdir -p "$(dirname -- "$target")"
ln -s "$source" "$target"
printf 'Linked %s -> %s\n' "$target" "$source"
}
apply_macos_defaults () {
[[ "${OSTYPE:-}" == darwin* ]] || return 0
defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false
defaults write com.microsoft.VSCodeInsiders ApplePressAndHoldEnabled -bool false
defaults write com.visualstudio.code.oss ApplePressAndHoldEnabled -bool false
defaults write -g ApplePressAndHoldEnabled -bool false
defaults write -g InitialKeyRepeat -int 15
defaults write -g KeyRepeat -int 1
}
link_item "$DOTFILES_DIR/bash_profile" "$HOME/.bash_profile"
link_item "$DOTFILES_DIR/bashrc" "$HOME/.bashrc"
link_item "$DOTFILES_DIR/gitconfig" "$HOME/.gitconfig"
link_item "$DOTFILES_DIR/vimrc" "$HOME/.vimrc"
link_item "$DOTFILES_DIR/zprofile" "$HOME/.zprofile"
link_item "$DOTFILES_DIR/zshrc" "$HOME/.zshrc"
link_item "$DOTFILES_DIR/config/alacritty" "$HOME/.config/alacritty"
link_item "$DOTFILES_DIR/config/gitignore_global" "$HOME/.config/gitignore_global"
link_item "$DOTFILES_DIR/config/htop" "$HOME/.config/htop"
link_item "$DOTFILES_DIR/config/nvim" "$HOME/.config/nvim"
link_item "$DOTFILES_DIR/config/sheldon" "$HOME/.config/sheldon"
link_item "$DOTFILES_DIR/config/starship.toml" "$HOME/.config/starship.toml"
link_item "$DOTFILES_DIR/config/zed/settings.json" "$HOME/.config/zed/settings.json"
link_item "$DOTFILES_DIR/python" "$HOME/.config/dotfiles/python"
legacy_lesscolors="$HOME/.config/lesscolors.sh"
if [[ -L "$legacy_lesscolors" ]] &&
[[ "$(readlink "$legacy_lesscolors")" == "$DOTFILES_DIR/config/lesscolors.sh" ]]; then
rm -- "$legacy_lesscolors"
printf 'Removed stale link %s\n' "$legacy_lesscolors"
fi
link_item "$DOTFILES_DIR/bin/colorless" "$HOME/bin/colorless"
link_item "$DOTFILES_DIR/bin/python" "$HOME/bin/python"
link_item "$DOTFILES_DIR/bin/python3" "$HOME/bin/python3"
if (( APPLY_MACOS_DEFAULTS )); then
apply_macos_defaults
fi
if (( BACKUP_CREATED )); then
printf 'Backups saved under %s\n' "$BACKUP_ROOT"
fi