-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.zsh
More file actions
executable file
·134 lines (114 loc) · 3.77 KB
/
init.zsh
File metadata and controls
executable file
·134 lines (114 loc) · 3.77 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
#!/usr/bin/env zsh
# Exit immediately if a command fails and treat unset vars as error
set -euo pipefail
# Immediately invoked anonymous function used to contain variables and functions scope
function {
local __options
local __dotfiles_scripts_dir="$(realpath "$(dirname "$ZSH_ARGZERO")")"
local __dotfiles_dir="$(dirname "$__dotfiles_scripts_dir")"
# Defaults
local __brew=false
local __configure_os_settings=false
local __install_mise_dev_tools=false
local __install_zsh_theme_plugins=false
local __install_vm=false
local __manage_betterdisplay=false
local __profile="work" # work or personal; work = safest
local __symlink_dotfiles=false
local __noop=false
# Load important environment variables
source "$__dotfiles_dir/.zshenv"
# Load functions
source "$__dotfiles_scripts_dir/functions.zsh"
# Default to persisted profile (fall back to 'work')
__profile="$(_v_profile_read)"
# Parse parameters and or display help and exit
zmodload zsh/zutil
zparseopts -D -E -F -A __options - \
b -brew \
d -display \
h -help \
l -link \
m -mise \
o -os \
p: -profile: \
v -vm \
z -zsh ||
(_v_log_error "ERROR" "Invalid options provided\n" && _v_print_help && exit 1)
if [[ $#__options -eq 0 ]]; then
_v_log_warn "WARN" "No options provided\n"
_v_print_help
__noop=true
fi
for opt arg in "${(kv@)__options}"; do
case "$opt" in
-b|--brew)
__brew=true
;;
-d|--display)
__manage_betterdisplay=true
;;
-h|--help)
_v_print_help
exit 0
;;
-l|--link)
__symlink_dotfiles=true
;;
-m|--mise)
__install_mise_dev_tools=true
;;
-o|--os)
__configure_os_settings=true
;;
-p|--profile)
if _v_profile_is_valid "$arg"; then
__profile="$arg"
else
_v_log_error "ERROR" "Valid profile name is required for the \`$opt\` option. Use 'work' or 'personal'. Received: '$arg'"
_v_print_help
exit 1
fi
;;
-v|--vm)
__install_vm=true
;;
-z|--zsh)
__install_zsh_theme_plugins=true
;;
esac
done
echo "\n"
local __profile_color=$([[ "$__profile" == "work" ]] && echo green || echo yellow)
_v_log_info "PRFL" "Profile: $(_v_color_fg $__profile_color "$__profile")"
# Make selected profile available to all scripts and future runs
export DOT_PROFILE="$__profile"
if ! _v_profile_write "$__profile"; then
_v_log_error "ERROR" "Failed to persist selected profile '$__profile'"
exit 1
fi
# Homebrew and Homebrew packages installation
source "$__dotfiles_scripts_dir/brew.zsh"
# Symlink dotfiles
source "$__dotfiles_scripts_dir/symlink.zsh"
# Install Zsh theme + plugins
source "$__dotfiles_scripts_dir/zsh.zsh"
# Install mise dev tools
source "$__dotfiles_scripts_dir/mise.zsh"
# Install VM and containerization tools
source "$__dotfiles_scripts_dir/vm.zsh"
# Configure OS settings
source "$__dotfiles_scripts_dir/os.zsh"
# Manage BetterDisplay settings
source "$__dotfiles_scripts_dir/betterdisplay.zsh"
# Exit if no options were provided
if $__noop; then
echo "\n"
_v_log_warn "WARN" "Nothing to do. Bye "
exit 0
fi
# Finish
echo "\n"
_v_log_ok "DONE" "Bootstrap complete"
_v_reload
} "$@"