1
1
Fork 0

setup zsh updates

This commit is contained in:
david 2018-05-13 19:36:41 +02:00
parent d5bffdc1b2
commit 8652b1eee5
3 changed files with 129 additions and 1 deletions

View File

@ -2,6 +2,14 @@
_My personal collection of handy scripts. mostly bash._
## setup_zsh
One-line installer for zsh, oh-my-zsh and various zsh plugins.
```
curl -fsSL https://socialg.it/david/scripts/raw/master/setup_zsh.sh | bash
```
## mc.sh
A minecraft server hosting helper script.
@ -19,4 +27,3 @@ usage: mc option <server>
stop <server> Stop server instance
console <server> Connect to server console
```

121
setup_zsh.sh Normal file
View File

@ -0,0 +1,121 @@
#!/usr/bin/env bash
#
# download and setup zsh, oh-my-zsh and various zsh plugins
#
# author: david@socialnerds.org
# license: MIT
# git: https://socialg.it/david/scripts.git
# version 0.1
# **** vars ****
command="$0"
root="$HOME/.dotfiles"
plugins="$root/zsh"
timestamp=$(date +"%Y%m%d%H%M")
repo="https://socialg.it/david/dotfiles.git"
dependencies="awk tee ls git wget curl rm mv sleep date"
debug=1
# **** functions ****
message() {
if [ $1 == "e" ]; then
level="\033[31m✗\033[0m"
elif [ $1 == "i" ]; then
level="\033[32m✓\033[0m"
elif [ $1 == "w" ]; then
level="\033[33m!\033[0m"
elif [ $1 == "d" ]; then
if [ $debug -eq 1 ]; then
level="\033[2md\033[0m"
else
return 0
fi
else
message e "Unknown message level[$1]."
return 1
fi
echo -e [$level] ${@:2}
sleep 0.1
}
failsafe() {
if [ $1 -ne 0 ]; then
message e "Installer died horribly!"
if [ $2 ]; then
message d "Dumping last output to stdout."
echo ${@:2}
fi
exit 1
fi
}
cleanup() {
# Get rid of preexisting data at destination
destination=$1
if [ -a "$destination.old" ]; then
message e "A previous backup exists. Move elsewhere or delete first[$destination.old]."
exit 1
else
if [ -h $destination ]; then
link=$(ls -la $destination | awk '{print $9" "$10" "$11}')
# It should be safe to just remove symbolic links because no data is actually deleted.
message d "Symbolic link exists, attempting to remove it[$link]."
output=$(rm $destination 2>&1); failsafe $? $output
message i "Removed symbolic link[$link]."
elif [ -a $destination ]; then
# Rename data to $destination.old
message d "Data exists at install destination, attempting to create a backup[$destination.old]."
output="", output=$(mv $destination $destination.old 2>&1); failsafe $? $output
message i "Created a backup of a preexisting data[$destination.old]."
fi
fi
}
# **** start of script ****
message d "Warming up installer."
#message d "Initiating preflight checks."
# check dependencies, fail with a list of missing
# can i write to ~ and ~/.oh-my-zsh
# remove everything in 5 seconds: ~/.dotfiles ~/.dotfiles.old ~/.myzsh ~/.oh-my-zsh ~/.zshrc
message w "your old configs will be deleted in 5 seconds [terminate deletion with Ctrl-C]"
sleep 5
rm -rf $HOME/.dotfiles
rm -rf $HOME/.dotfiles.old
rm -rf $HOME/.myzsh
rm -rf $HOME/.oh-my-zsh
rm $HOME/.zshrc
# invoke oh-my-zh installer
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
message i "oh-my-zsh installed"
# set $ZSH_THEME="" in .zshrc
cat $HOME.zshrc | sed "s/^ZSH_THEME=\"robbyrussell\"/ZSH_THEME=\"\"/g" > $HOME/.zshrc
message i "oh-my-zsh theme deactivated"
# clone plugins
cd $ZSH_CUSTOM/plugins/
git clone https://github.com/sindresorhus/pure.git pure
git clone https://github.com/mafredri/zsh-async.git async
git clone https://socialg.it/david/zsh-david.git zsh-david
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git zsh-syntax-highlighting
git clone https://github.com/skx/sysadmin-util.git sysadmin-util
git clone https://github.com/TamCore/autoupdate-oh-my-zsh-plugins.git autoupdate
git clone https://github.com/zsh-users/zsh-autosuggestions.git zsh-autosuggestions
cd -
message i "all plugins cloned"
# set $plugins in .zshrc
plugins=(git zsh-autosuggestions autoupdate sysadmin-util zsh-syntax-highlighting zsh-david async pure)
cat $HOME/.zshrc | sed "/plugins=(/,/)/d; s/source \$ZSH\/oh-my-zsh.sh/plugins=($plugins); source \$ZSH\/oh-my-zsh.sh/g" | sed $'s/; /\\\n/g' > $HOME/.zshrc
message i "activated zsh plugins [$plugins]"
message d "Installer finished."
# **** end of script ****