-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzsh_powerlevel10k.sh
156 lines (138 loc) · 4.07 KB
/
zsh_powerlevel10k.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
#!/bin/sh
set -e
THEME=powerlevel10k/powerlevel10k
PLUGINS=""
ZSHRC_APPEND=""
while getopts ":t:p:a:" opt; do
case ${opt} in
t) THEME=$OPTARG
;;
p) PLUGINS="${PLUGINS}$OPTARG "
;;
a) ZSHRC_APPEND="$ZSHRC_APPEND\n$OPTARG"
;;
\?)
echo "Invalid option: $OPTARG" 1>&2
;;
:)
echo "Invalid option: $OPTARG requires an argument" 1>&2
;;
esac
done
shift $((OPTIND -1))
echo
echo "Installing Oh-My-Zsh with:"
echo " THEME = $THEME"
echo " PLUGINS = $PLUGINS"
echo
check_dist() {
(
. /etc/os-release
echo $ID
)
}
check_version() {
(
. /etc/os-release
echo $VERSION_ID
)
}
install_dependencies() {
DIST=`check_dist`
VERSION=`check_version`
echo "###### Installing dependencies for $DIST"
if [ "`id -u`" = "0" ]; then
Sudo=''
elif which sudo; then
Sudo='sudo'
else
echo "WARNING: 'sudo' command not found. Skipping the installation of dependencies. "
echo "If this fails, you need to do one of these options:"
echo " 1) Install 'sudo' before calling this script"
echo "OR"
echo " 2) Install the required dependencies: git curl zsh"
return
fi
case $DIST in
alpine)
$Sudo apk add --update --no-cache git curl zsh
;;
centos | amzn)
$Sudo yum update -y
$Sudo yum install -y git curl
$Sudo yum install -y ncurses-compat-libs # this is required for AMZN Linux (ref: https://github.com/emqx/emqx/issues/2503)
$Sudo curl http://mirror.ghettoforge.org/distributions/gf/el/7/plus/x86_64/zsh-5.1-1.gf.el7.x86_64.rpm > zsh-5.1-1.gf.el7.x86_64.rpm
$Sudo rpm -i zsh-5.1-1.gf.el7.x86_64.rpm
$Sudo rm zsh-5.1-1.gf.el7.x86_64.rpm
;;
*)
$Sudo apt-get update
$Sudo apt-get -y install git curl zsh locales
if [ "$VERSION" != "14.04" ]; then
$Sudo apt-get -y install locales-all
fi
$Sudo locale-gen en_US.UTF-8
esac
}
zshrc_template() {
_HOME=$1;
_THEME=$2; shift; shift
_PLUGINS=$*;
cat <<EOM
if [[ -r "$HOME/.cache/p10k-instant-prompt-$USER.zsh" ]]; then
source "$HOME/.cache/p10k-instant-prompt-$USER.zsh"
fi
export LANG='en_US.UTF-8'
export LANGUAGE='en_US:en'
export LC_ALL='en_US.UTF-8'
export TERM=xterm-256color
##### Zsh/Oh-my-Zsh Configuration
export ZSH="$_HOME/.oh-my-zsh"
ZSH_THEME="${_THEME}"
plugins=($_PLUGINS)
EOM
printf "$ZSHRC_APPEND"
printf "\nsource \$ZSH/oh-my-zsh.sh\n"
printf "[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh\n"
}
powerline10k_config() {
cat <<EOM
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_last"
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(user dir vcs status)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
POWERLEVEL9K_STATUS_OK=false
POWERLEVEL9K_STATUS_CROSS=true
EOM
}
install_dependencies
cd /tmp
# Install On-My-Zsh
if [ ! -d $HOME/.oh-my-zsh ]; then
sh -c "$(curl https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" "" --unattended
fi
# Generate plugin list
plugin_list=""
for plugin in $PLUGINS; do
if [ "`echo $plugin | grep -E '^http.*'`" != "" ]; then
plugin_name=`basename $plugin`
git clone $plugin $HOME/.oh-my-zsh/custom/plugins/$plugin_name
else
plugin_name=$plugin
fi
plugin_list="${plugin_list}$plugin_name "
done
# Handle themes
if [ "`echo $THEME | grep -E '^http.*'`" != "" ]; then
theme_repo=`basename $THEME`
THEME_DIR="$HOME/.oh-my-zsh/custom/themes/$theme_repo"
git clone $THEME $THEME_DIR
theme_name=`cd $THEME_DIR; ls *.zsh-theme | head -1`
theme_name="${theme_name%.zsh-theme}"
THEME="$theme_repo/$theme_name"
fi
# Generate .zshrc
zshrc_template "$HOME" "$THEME" "$plugin_list" > $HOME/.zshrc
# Install powerlevel10k if no other theme was specified
if [ "$THEME" = "powerlevel10k/powerlevel10k" ]; then
git clone https://github.com/romkatv/powerlevel10k $HOME/.oh-my-zsh/custom/themes/powerlevel10k
fi