-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash.sh
executable file
·79 lines (61 loc) · 2.38 KB
/
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
#!/bin/bash
cd "$(dirname "${BASH_SOURCE[0]}")" \
&& . "../../utils.sh" \
&& . "./utils.sh"
change_default_bash() {
declare -r LOCAL_SHELL_CONFIG_FILE="$HOME/.bash.local"
local configs=""
local pathConfig=""
local newShellPath=""
local brewPrefix=""
# Try to get the path of the `Bash`
# version installed through `Homebrew`.
brewPrefix="$(brew_prefix)" \
|| return 1
pathConfig="PATH=\"$brewPrefix/bin:\$PATH\""
configs="
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$pathConfig
export PATH
"
newShellPath="$brewPrefix/bin/bash" \
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Add the path of the `Bash` version installed through `Homebrew`
# to the list of login shells from the `/etc/shells` file.
#
# This needs to be done because applications use this file to
# determine whether a shell is valid (e.g.: `chsh` consults the
# `/etc/shells` to determine whether an unprivileged user may
# change the login shell for her own account).
#
# http://www.linuxfromscratch.org/blfs/view/7.4/postlfs/etcshells.html
if ! grep "$newShellPath" < /etc/shells &> /dev/null; then
execute \
"printf '%s\n' '$newShellPath' | sudo tee -a /etc/shells" \
"Bash (add '$newShellPath' in '/etc/shells')" \
|| return 1
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set latest version of `Bash` as the default
# (macOS uses by default an older version of `Bash`).
chsh -s "$newShellPath" &> /dev/null
print_result $? "Bash (use latest version)"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# If needed, add the necessary configs in the
# local shell configuration file.
if ! grep "^$pathConfig" < "$LOCAL_SHELL_CONFIG_FILE" &> /dev/null; then
execute \
"printf '%s' '$configs' >> $LOCAL_SHELL_CONFIG_FILE \
&& . $LOCAL_SHELL_CONFIG_FILE" \
"Bash (update $LOCAL_SHELL_CONFIG_FILE)"
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
main() {
print_in_purple "\n Bash\n\n"
brew_install "Bash" "bash" \
&& change_default_bash
brew_install "Bash Completion" "bash-completion"
brew_install "Bash Completion 2" "bash-completion2" "homebrew/versions"
}
main