-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathohmyzsh.sh
More file actions
executable file
·98 lines (92 loc) · 3.85 KB
/
Copy pathohmyzsh.sh
File metadata and controls
executable file
·98 lines (92 loc) · 3.85 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
#!/bin/bash
echo "Use this script to install zsh and change default shell to it, then install ohmyzsh"
if [ "$USER" = "root" ]; then
SUDO=""
else
echo "This script need root permission."
sudo echo "Go ahead..."
SUDO="sudo"
fi
if [ -x "$(command -v apt)" ]; then
$SUDO apt install -y zsh
elif [ -x "$(command -v yum)" ]; then
$SUDO yum install -y zsh
elif [ -x "$(command -v brew)" ]; then
brew install zsh
else
echo You may need to install zsh manually.
fi
if [ -f /etc/pam.d/chsh ]; then
# Make `chsh` no need to input password
# $SUDO python -c "fn='/etc/pam.d/chsh';a,b='required','sufficient';fp=open(fn,'a+');s=fp.read();fp.truncate();fp.write(s.replace(b,a));fp.close()"
$SUDO python -c "fn='/etc/pam.d/chsh';a,b='required','sufficient';fp=open(fn);s=fp.read();fp.close();fp=open(fn,'w');fp.write(s.replace(a,b));fp.close()"
fi
if [ -f /bin/zsh ]; then
ZSH_EXEC=/bin/zsh
else
ZSH_EXEC=$(which zsh)
fi
chsh -s $ZSH_EXEC
# Uncomment the following lines to expand PATH and plugins
#sh -c 'echo "[ -s \$HOME/.bash_aliases ] && source \$HOME/.bash_aliases" >> $HOME/.zshrc'
#sh -c 'echo "[ -s \$HOME/.local/bin ] && export PATH=\$HOME/.local/bin:/usr/local/bin:\$PATH" >> $HOME/.zshrc'
#sh -c 'echo "export ZSH=\$HOME/.oh-my-zsh" >> $HOME/.zshrc'
#sh -c 'echo "ZSH_THEME=random" >> $HOME/.zshrc'
#sh -c 'echo "plugins=(git pip python poetry)" >> $HOME/.zshrc'
#sh -c 'echo "[ -s \$ZSH/oh-my-zsh.sh ] && source \$ZSH/oh-my-zsh.sh" >> $HOME/.zshrc'
if [[ -v REMOTE ]]; then
echo REMOTE value "$REMOTE" will be used to install ohmyzsh
else
if [[ -v OMZ_REPO ]]; then
echo use $OMZ_REPO for oh-my-zsh installing
else
if [[ -v USE_GITEE ]]; then
OMZ_REPO="https://gitee.com/mirrors/oh-my-zsh"
else
OMZ_REPO="https://github.com/ohmyzsh/oh-my-zsh"
fi
fi
if [[ $OMZ_REPO == *.git ]]; then
export REMOTE="$OMZ_REPO"
else
export REMOTE="$OMZ_REPO.git"
fi
fi
# TODO: Check oh-my-zsh.zip exists to support offline install
INSTALL_SCRIPT="./oh-my-zsh/tools/install.sh"
if [[ $REMOTE == http* ]]; then
if [[ $(git config http.sslVerify) == "false" ]]; then
if [ -f $INSTALL_SCRIPT ]; then
echo "Using $INSTALL_SCRIPT to install"
else
cd /tmp
if [ -d oh-my-zsh ]; then
echo directory 'oh-my-zsh' exists, skip clone
else
git clone $REMOTE
if [ -d oh-my-zsh ]; then
echo Success to clone oh-my-zsh
else
git clone $REMOTE
fi
fi
fi
REMOTE=$REMOTE sh $INSTALL_SCRIPT
else
FETCHING="curl -fsSL $OMZ_REPO/raw/master/tools/install.sh"
echo "--> $FETCHING"
REMOTE=$REMOTE sh -c "$($FETCHING --connect-timeout "15" max-time "20")" --keep-zshrc
fi
elif [[ $REMOTE == ssh* ]]; then
cd /tmp
[ -d oh-my-zsh ] || git clone $REMOTE
REMOTE=$REMOTE $($INSTALL_SCRIPT)
fi
# Uncomment the following lines to add custom plugin
#export PLUGIN="zsh-autosuggestions"
#([[ -f $PLUGIN.tar.xz ]] && tar xf $PLUGIN.tar.xz) || ([[ -f $PLUGIN-master.zip ]] && unzip $PLUGIN-master.zip && mv $PLUGIN-master $PLUGIN)
#[[ -d $PLUGIN ]] || git clone ${PLUGIN_REPO:-git@github.com:zsh-users/zsh-autosuggestions.git}
#[[ -d ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/ ]] || mkdir -p ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/
#mv $PLUGIN ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/
#python -c "import os,sys;p=os.path.expanduser('~/.zshrc');f=open(p);s=f.read();f.close();v='zsh-autosuggestions';c='You can run the following command to activate plugin:\n\n source '+p+'\n';v in s and sys.exit(c);ss=s.splitlines();a='plugins=(';t=[i for i in ss if i.startswith(a)];assert t, 'Failed to auto change, you can manually edit {}'.format(p);line=t[0].replace(a,a+v+' ');new=s.replace(t[0],line);f=open(p,'w');f.write(new);f.close();print(c)"
#source ~/.zshrc