Skip to content

Instantly share code, notes, and snippets.

@MnifR
Last active May 16, 2021 18:46
Show Gist options
  • Save MnifR/7d0dcdb0ec1a6351cd05f7cca71c8b2a to your computer and use it in GitHub Desktop.
Save MnifR/7d0dcdb0ec1a6351cd05f7cca71c8b2a to your computer and use it in GitHub Desktop.
Automation of the installation of ZSH shell with the OhMyZSH framework, tmux and various plugins and its minimal configuration file. It also includes fonts.
#!/bin/bash
set -o errexit
set -o pipefail
APPS="zsh git curl wget unzip neofetch tmux"
OS=$(source /etc/os-release && echo "${ID}")
DATE=$(date '+%d.%m.%Y_%Hh%M')
# Installation of packages
case ${OS} in
"debian" | "ubuntu" | "linuxmint" | "pop")
sudo apt update && sudo apt install $APPS -y
;;
"arch" | "manjaro")
sudo pacman -Sy $APPS --noconfirm
;;
"fedora" | "centos")
sudo dnf install $APPS -y
;;
"solus")
sudo eopkg install $APPS -y
;;
*)
echo -e "\e[31mSystem can't be defined."
exit
;;
esac
# Fonts installlation
if [[ ! -d /usr/share/fonts/hack ]]; then
wget https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Hack.zip -O "${HOME}"/hack.zip
unzip "${HOME}"/hack.zip -d "${HOME}"/hack && rm "$HOME"/hack.zip
find "${HOME}"/hack/ -iname "*Windows*" -exec rm {} \;
sudo mkdir -p /usr/share/fonts/hack
sudo mv "${HOME}"/hack/* /usr/share/fonts/hack
rmdir "${HOME}"/hack
fi
# Change default shell
sudo chsh -s /usr/bin/zsh "${USER}"
# Backup old zshrc
if [[ -f "${HOME}"/.zshrc ]]; then
cp "${HOME}"/.zshrc "${HOME}"/.zshrc.backup_"${DATE}"
elif [[ ! -f "${HOME}"/.zshrc ]]; then
touch "${HOME}"/.zshrc
fi
# Backup old installation of oh-my-zsh
if [[ -d "${HOME}"/.oh-my-zsh ]]; then
mv "${HOME}"/.oh-my-zsh "${HOME}"/.oh-my-zsh.backup_"${DATE}"
fi
# Installation OhMyZsh + powerlevel10k + plugins
git clone https://github.com/ohmyzsh/ohmyzsh.git "${HOME}"/.oh-my-zsh
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/zsh-completions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
echo '# Path to your oh-my-zsh installation
export ZSH="$HOME/.oh-my-zsh"
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block, everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# Fix slowness of pastes with zsh-syntax-highlighting.zsh
pasteinit() {
OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
zle -N self-insert url-quote-magic
}
pastefinish() {
zle -N self-insert $OLD_SELF_INSERT
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish
source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
export ZSH_HIGHLIGHT_MAXLENGTH="60"
# ZSH Theme
ZSH_THEME="powerlevel10k/powerlevel10k"
# Uncomment the following line to use case-sensitive completion.
CASE_SENSITIVE="off"
# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
DISABLE_AUTO_UPDATE="off"
# Uncomment the following line to automatically update without prompting.
DISABLE_UPDATE_PROMPT="off"
# Uncomment the following line to change how often to auto-update (in days).
export UPDATE_ZSH_DAYS=15
# Uncomment the following line if pasting URLs and other text is messed up.
DISABLE_MAGIC_FUNCTIONS="true"
# Uncomment the following line to disable colors in ls.
DISABLE_LS_COLORS="off"
# Uncomment the following line to disable auto-setting terminal title.
DISABLE_AUTO_TITLE="off"
# Uncomment the following line to enable command auto-correction.
ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
COMPLETION_WAITING_DOTS="true"
# History time stamp
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
HIST_STAMPS="dd.mm.yyyy"
# ZSH plugins
plugins=(
git
kubectl
zsh-autosuggestions
zsh-completions
zsh-syntax-highlighting)
source $ZSH/oh-my-zsh.sh
# User configuration
export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
if [[ -n $SSH_CONNECTION ]]; then
export EDITOR='vim'
else
export EDITOR='vim'
fi
# Compilation flags
export ARCHFLAGS="-arch x86_64"
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh' > "${HOME}"/.zshrc
echo '# Tmux Config
tmux_conf_new_pane_retain_current_path=false
tmux_conf_new_window_retain_current_path=false
set -g default-terminal "xterm-256color"
set -g monitor-activity on
set -g visual-activity on
set -g base-index 1
set -g pane-base-index 1
set -g xterm-keys on
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
bind-key -n F2 new-window
bind-key -n F3 previous-window
bind-key -n F4 next-window
bind-key -n F5 split-window -v
bind-key -n F6 split-window -h
bind-key -n F8 command-prompt -I "#W" "rename-window '%%'"
bind-key -n F7 command-prompt "find-window '%%'"
bind-key -n F10 setw synchronize-panes
bind-key -n F11 resize-pane -Z
bind-key -n F12 kill-pane
bind-key -n S-Left resize-pane -L
bind-key -n S-Right resize-pane -R
bind-key -n S-Up resize-pane -U
bind-key -n S-Down resize-pane -D
set -g status-interval 60
set -g status-right "#(uptime -p) "
set -g status-style "fg=colour246,bg=colour235"
set -g pane-border-style fg=colour237
set -g pane-active-border-style fg=colour242
set-window-option -g window-status-current-style fg=colour166,bright
bind r source-file ~/.tmux.conf \; display "Tmux Reloaded" ' > "${HOME}"/.tmux.conf
echo -e "\e[32mInstallation is finished you must relaunch your $USER session to apply the configurations.\n\e[32mTo get display of special characters, you must set up fonts in your terminal options.\e[0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment