-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathINSTALL.sh
More file actions
executable file
·139 lines (114 loc) · 4.48 KB
/
INSTALL.sh
File metadata and controls
executable file
·139 lines (114 loc) · 4.48 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
135
136
137
138
#!/usr/bin/env bash
# Author: @franciscolourenco
echo
# ------------------------------- Links -------------------------------------
createLink () {
rm -rf $2
ln -s $1 $2
linkResults="$linkResults\n $1 <-- $2@"
}
linkSafely () {
if [ -e $2 ] && [ "`diff -rq $1 $2`" ]; then
echo 'There is already a file at "'$2'" which is different from the one you are trying to install'.
read -p 'Do you wish to overwrite? (y/n) '
[ "$REPLY" == "y" ] && createLink $1 $2
[ "$REPLY" != "y" ] && linkResults="$linkResults\n$2 X $1"
else
createLink $1 $2
fi
}
repoDir="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
IFS=$'\n'
toReplace="home/"
for file in $(cd $repoDir && find home -type f \( ! -iname ".*" \)) ; do
destination="${file/$toReplace/$HOME/.}"
dirname=$(dirname $destination)
basename=$(basename $destination)
[ -d $dirname ] || mkdir -p "$dirname"
linkSafely "$repoDir/$file" "$destination"
done
[ "$linkResults" ] && echo "Created symbolic links:"
echo -e "$linkResults" | sed s:"$HOME":"~":g | column -t && echo
# ------------------------------ rmate ------------------------------------
[ -n "$SSH_CLIENT" ] && ! hash rmate 2>/dev/null && {
read -p "Do you want to install rmate to edit files remotely using Sublime Text?(y/n)"
[ "$REPLY" == "y" ] && {
echo "Installing rmate..."
echo ""
sudo wget -O /usr/local/bin/rmate https://raw.github.com/aurora/rmate/master/rmate
sudo chmod a+x /usr/local/bin/rmate
}
}
# ------------------------------- Git -------------------------------------
hash git 2>/dev/null && {
read -p "Do you wish to configure git?(y/n) "
[ "$REPLY" == "y" ] && {
gitlocal="$HOME/.gitlocal"
# name
read -p "Name: "
[ "$REPLY" ] && git config -f "$gitlocal" user.name "$REPLY"
# email
read -p "Email: "
[ "$REPLY" ] && git config -f "$gitlocal" user.email "$REPLY"
if hash rmate 2>/dev/null; then
git config -f "$gitlocal" core.editor "rmate -w"
else
# make git wait for sublime text otherwise commit doesn't work
read -p "Do you want to edit commit messages using Sublime Text?(y/n)"
[ "$REPLY" == "y" ] && git config -f "$gitlocal" core.editor "subl -w -n --command toggle_side_bar"
fi
# use keychain to retrieve passwords on repositories cloned via https
[ "`uname`" == "Darwin" ] && git config -f "$gitlocal" credential.helper "osxkeychain"
echo
echo "Your preferences were saved in $gitlocal"
echo "This file may be used for configurations specific to this machine."
echo
}
}
# ------------------------------- install/activate homebrew/fishfish ------------------------------------------
if [[ `uname` == "Darwin" ]]; then
# Install homebrew
if ! [ -x /opt/homebrew/bin/brew ]; then
echo ""
echo "Installing homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
# Install fish shell
if ! hash fish 2>/dev/null; then
echo ""
echo "Installing fish shell..."
/opt/homebrew/bin/brew install fish
fi
# Install packages from Brewfile
if [ -f "Brewfile" ]; then
echo ""
read -p "Would you like to install packages and apps from Brewfile? (y/n) " REPLY
if [ "$REPLY" == "y" ]; then
echo "Installing packages from Brewfile..."
/opt/homebrew/bin/brew bundle
fi
fi
# Add fish to shells
if ! grep -q "/opt/homebrew/bin/fish" /etc/shells; then
echo ""
echo "Adding fish to shells..."
sudo sh -c "echo /opt/homebrew/bin/fish >> /etc/shells"
fi
# Check if fish is already set as default shell
if [ "$(dscl . -read /Users/$USER UserShell | awk '{print $2}')" != "/opt/homebrew/bin/fish" ]; then
echo ""
echo "Setting fish as default shell..."
chsh -s /opt/homebrew/bin/fish
fi
# Install fisher and fisher plugins
if ! [[ -f "$HOME/.config/fish/functions/fisher.fish" ]]; then
echo ""
echo "Installing fisher plugins..."
/opt/homebrew/bin/fish -c "curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher update"
fi
echo ""
echo "Entering fish..."
/opt/homebrew/bin/fish --login
else
echo "To install fish shell visit: https://fishshell.com/"
fi