-
Notifications
You must be signed in to change notification settings - Fork 0
/
.configure_bash.sh
197 lines (140 loc) · 5.2 KB
/
.configure_bash.sh
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
### Imports ###
[ -f ~/.bash_profile ] && echo "Sourcing ~/.bash_profile" && . ~/.bash_profile
### End: Imports ###
### functions ###
function is_yes {
ans=$(echo "$1" | tr "[:upper:]" "[:lower:]") # To lowercase.
[ "$ans" = "y" ] || [ "$ans" = "yes" ]
return $?
}
function is_no {
[ "$1" = "n" ] || [ "$1" = "N" ]
return $?
}
function is_valid_answer {
is_yes "$1" || is_no "$1"
return $?
}
# https://apple.stackexchange.com/questions/34810/create-a-command-to-focus-a-specific-window-from-anywhere-in-os
# function notify
# https://apple.stackexchange.com/a/115373
function do_action {
# $1: description.
# $2: string of chained commands.
# $3: interactive mode "y" or "n".
# Utilises global 'X_INTERACTIVE' to prompt user. Defaults to "y" if missing.
interactive=$3
should_ask=${interactive:="y"}
# Ask to do action if interactive mode.
if [ "$should_ask" = "y" ]; then
echo
while ! is_valid_answer "$do_action_ans" ; do
read -r -p "$1 [y/n]: " do_action_ans
done
# Make lowercase.
do_action_ans=$(echo "$do_action_ans" | tr "[:upper:]" "[:lower:]")
else
do_action_ans="y"
fi
# Install if accepted.
if [ "$do_action_ans" = "y" ]; then
eval "$2"
fi
}
# OS
[[ "$OSTYPE" == "darwin"* ]] ; IS_MAC=$?
[[ "$OSTYPE" == "linux-gnu"* ]] ; IS_UBUNTU=$?
# Attempt to install requirements first.
# https://github.com/pyenv/pyenv/wiki#suggested-build-environment
echo ; echo ; echo ; echo "==============================================================="
if [ $IS_UBUNTU == 0 ]; then
[ ! "$(which sudo)" ] && apt install -y sudo
do_action "Attempt to install requirements (build-essential, procps, curl, file, git, ssh)" "sudo apt update -y ; sudo apt upgrade -y ; sudo apt install -y build-essential procps curl file git ssh" "$X_INTERACTIVE"
elif [ $IS_MAC == 0 ]; then
do_action "Attempt to install requirements (curl, git)" "brew install git curl" "$X_INTERACTIVE"
do_action "Install xcode-select" "xcode-select --install" "$X_INTERACTIVE"
fi
# Change default terminal to bash.
chsh -s /bin/bash
# Initialise global 'X_INTERACTIVE'. Defaults to "y".
X_INTERACTIVE=${X_INTERACTIVE:="y"}
echo "X_INTERACTIVE=$X_INTERACTIVE"
echo
# Get user input if missing 'interactive'.
echo
echo
while ! is_valid_answer "$X_INTERACTIVE" ; do
read -r -p "Install with interactive mode? [y/n]: " X_INTERACTIVE
done
# Make lowercase.
X_INTERACTIVE=$(echo "$X_INTERACTIVE" | tr "[:upper:]" "[:lower:]") # https://stackoverflow.com/a/2264451/12616507
# Go to home directory.
cd ~ || exit
pwd
### brew ###
# Install brew if it doesn't exist.
if [ ! "$(which brew)" ]; then
# Non-interactive install.
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Update PATH and current shell.
# TODO: Just manually add this to bash_profile
# echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> $HOME/.bash_profile
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
# Update brew.
brew update && brew upgrade && brew upgrade --cask
brew install gcc # Recommended by brew.
### bitwarden ###
do_action "Install bitwarden-cli?" "brew install bitwarden-cli"
### wifi-password ###
do_action "Install wifi-password (requires MacOS)?" "brew install wifi-password"
### docker ###
do_action "Install docker?" "brew install docker"
### colima ###
# Replacement for docker-desktop.
# https://github.com/abiosoft/colima
do_action "Install colima?" "brew install colima && colima start"
### ncdu ###
# Directory explorer.
do_action "Install ncdu?" "brew install ncdu"
### jq ###
# JSON processor for CLI.
# https://stedolan.github.io/jq/
do_action "Install jq?" "brew install jq"
### bash-completion ###
do_action "Install bash-completion?" "brew install bash-completion"
### git ###
do_action "Install git?" "brew install git"
### pyenv ###
# Config already added to .bash_profile.
# do_action "Install pyenv?" "git clone https://github.com/pyenv/pyenv.git ~/.pyenv"
do_action "Install pyenv?" "brew install pyenv"
# git clone https://github.com/pyenv/pyenv.git ~/.pyenv
### gitlab-cli ###
do_action "Install gitlab-cli (glab)?" "brew install glab"
### spotify ###
do_action "Install spotify?" "brew install spotify"
### github-cli ###
do_action "Install github-cli (gh)?" "brew install gh"
### macOS ###
if [[ "$OSTYPE" == "darwin"* ]]; then
# Cask packages are macOS only.
### google-chrome ###
do_action "Install google-chrome?" "brew install --cask google-chrome"
### alt-tab ###
# Enables tabbing similar to Windows.
# https://alt-tab-macos.netlify.app/
do_action "Install alt-tab?" "brew install --cask alt-tab"
### iterm2 ###
do_action "Install iterm2?" "brew install --cask iterm2"
### visual-studio-code ###
do_action "Install visual-studio-code?" "brew install --cask visual-studio-code"
### bitwarden ###
do_action "Install bitwarden?" "brew install --cask bitwarden"
### 1password ###
do_action "Install 1password?" "brew install --cask 1password"
do_action "Install 1password-cli?" "brew install --cask 1password-cli"
fi
# Restart terminal
exec "$SHELL"