-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.sh
executable file
·69 lines (55 loc) · 1.59 KB
/
user.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
#!/bin/bash -e
# shellcheck disable=SC2155
cd "$(dirname "${BASH_SOURCE[0]}")"
function prepend() {
awk "{print \"$1\" \$0}"
}
function section() {
echo -e "\e[1m\e[34m$*\e[0m"
}
function git-get {
if [ ! -d "$2" ]; then
echo "Cloning $1 to $2"
git clone -q "$1" "$2"
else
echo "Updating $1 in $2"
git -C "$2" pull -q;
fi
}
function file-get {
echo "Downloading $1 to $2"
curl -s -fLo "$2" --create-dirs "$1"
}
function install-code-extensions {
local INSTALLED_EXTENSIONS=$(code --list-extensions)
local UNEXPECTED=$(comm --output-delimiter=--- -3 \
<(echo "$INSTALLED_EXTENSIONS" | tr " " "\n" | sort) \
<(echo "$@" | tr " " "\n" | sort) | grep -v ^---)
if [[ -n "$UNEXPECTED" ]]; then
echo Unexpected extensions installed:
echo "$(echo "$UNEXPECTED" | sed 's/ /\n /g')"
fi
for EXTENSION in "$@"; do
if ! echo "$INSTALLED_EXTENSIONS" | grep -qw "$EXTENSION"; then
code --install-extension "$EXTENSION" 2>&1;
fi
done
}
function ln-all {
for FILE in "$@"; do
if [[ -f "$FROM/$FILE.desktop" ]]; then
ln -sf "$FROM/$FILE.desktop" "$TO"
fi
done
}
if [[ -z "$USER_PROFILE" ]] || [[ ! -d "user/$USER_PROFILE" ]]; then
# shellcheck disable=SC2046
echo Invalid \$USER_PROFILE, use one of the following: $(ls user)
exit 1
fi
if [ ! -f "$HOME/.ssh/id_rsa.pub" ]; then
echo "Generating ssh key..."
ssh-keygen -C "$HOSTNAME" -f "$HOME/.ssh/id_rsa" -P "";
fi
# shellcheck disable=SC1090
source "./user/$USER_PROFILE/user.sh"