Skip to content

Instantly share code, notes, and snippets.

@grammy-jiang
Last active January 7, 2023 14:36
Show Gist options
  • Save grammy-jiang/23b689b67b4dde3e1e8d8cdec52736d7 to your computer and use it in GitHub Desktop.
Save grammy-jiang/23b689b67b4dde3e1e8d8cdec52736d7 to your computer and use it in GitHub Desktop.
zsh configuration
#!/usr/bin/env bash
echo "Install dependencies now..."
sudo -- sh -c "apt update && apt install -y curl fzf gawk git python3-pygments sqlite3 ssh-askpass wget zsh"
if [ -f ~/.zshrc ]; then
mv ~/.zshrc ~/.zshrc.`date +%s`.bak
fi
if [ -d ~/.oh-my-zsh ]; then
echo "Oh My ZSH exists, update it now..."
git -C ~/.oh-my-zsh pull
else
echo "Install Oh My ZSH now..."
sh -c "$(curl -fsSL https://git.io/JvzfK)" "" --unattended
fi
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
if [ -d $HOME/.oh-my-zsh/custom/themes/powerlevel10k ]; then
echo "Powerlevel10k exists, update it now..."
git -C $HOME/.oh-my-zsh/custom/themes/powerlevel10k pull
else
zsh -c "git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $HOME/.oh-my-zsh/custom/themes/powerlevel10k"
fi
echo "Update .zshrc now..."
{
echo "
if ! command -v direnv &> /dev/null
then
curl -sfL https://direnv.net/install.sh | bash
fi
zstyle :omz:plugins:ssh-agent agent-forwarding on
zstyle :omz:plugins:ssh-agent identities id_rsa
# 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
"
cat ~/.zshrc
} >~/.zshrc.new && mv ~/.zshrc.new ~/.zshrc
export EXPRESSION='s/plugins=(git)/plugins=( \
\# cloud \
aws \
\
\# devops \
ansible \
\
\# git \
git \
git-auto-fetch \
tig \
\
\# container \
docker \
docker-compose \
\# helm \
\# kubectl \
\
\# misc \
colorize \
colored-man-pages \
common-aliases \
direnv \
firewalld \
gpg-agent \
history \
mosh \
ssh-agent \
sudo \
tmux \
vi-mode \
\
\# package management \
command-not-found \
dnf \
ubuntu \
\
\# python \
pip \
pipenv \
pyenv \
python \
virtualenv \
\
\# virtual machine \
vagrant \
)/'
sed --expression "$EXPRESSION" --in-place ~/.zshrc
echo 'export RPI=$(cat /proc/cpuinfo | grep "Model" | sed "s/Model\s*:\s//")' >> ~/.zshrc
echo "
export PYTHON_CONFIGURE_OPTS=\"--enable-shared\"" >>~/.zshrc
echo "
ZLE_RPROMPT_INDENT=0" >>~/.zshrc
# shellcheck disable=SC2016
echo '
source $ZSH_CUSTOM/themes/powerlevel10k/powerlevel10k.zsh-theme
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh' >>~/.zshrc
echo "Download p10k configuration file..."
wget --quiet --output-document=$HOME/.p10k.zsh https://git.io/Jvphr
echo '
export ZPLUG_HOME=$ZSH_CUSTOM/plugins/zplug
source $ZPLUG_HOME/init.zsh' >>~/.zshrc
export ZPLUG_HOME=$HOME/.oh-my-zsh/custom/plugins/zplug
if [ -d $ZPLUG_HOME ]; then
echo "Zplug exists, update now..."
git -C $ZPLUG_HOME pull
else
echo "Install Zplug..."
git clone --depth=1 https://github.com/zplug/zplug $ZPLUG_HOME
fi
echo "Zplug status"
zsh -c "source ~/.zshrc && zplug status"
echo "Install fzf as zsh plugins..."
echo '
zplug "junegunn/fzf", as:command, hook-build:"./install --bin", use:"bin/{fzf-tmux,fzf}"
' >>~/.zshrc
if [ -d $ZPLUG_HOME/repos/junegunn/fzf ]; then
zsh -c 'source ~/.zshrc && zplug update junegunn/fzf'
else
zsh -c "source ~/.zshrc && zplug install junegunn/fzf"
fi
echo '
source $ZPLUG_HOME/repos/junegunn/fzf/shell/key-bindings.zsh
source $ZPLUG_HOME/repos/junegunn/fzf/shell/completion.zsh
' >>~/.zshrc
echo "Install k as zsh plugins..."
echo '
zplug "supercrabtree/k", as:plugin
' >>~/.zshrc
if [ -d $ZPLUG_HOME/repos/supercrabtree/k ]; then
zsh -c 'source ~/.zshrc && zplug update supercrabtree/k'
else
zsh -c "source ~/.zshrc && zplug install supercrabtree/k"
fi
echo "Install enchancd as zsh plugins..."
echo '
zplug "b4b4r07/enhancd", as:plugin
export ENHANCD_HOOK_AFTER_CD="k"
' >>~/.zshrc
if [ -d $ZPLUG_HOME/repos/b4b4r07/enhancd ]; then
zsh -c 'source ~/.zshrc && zplug update b4b4r07/enhancd'
else
zsh -c "source ~/.zshrc && zplug install b4b4r07/enhancd"
fi
echo "Install zsh-autosuggestions as zsh plugins..."
echo '
export ZSH_AUTOSUGGEST_USE_ASYNC=true
export ZSH_AUTOSUGGEST_STRATEGY=(history completion)
zplug "zsh-users/zsh-autosuggestions", as:plugin
' >>~/.zshrc
if [ -d $ZPLUG_HOME/repos/zsh-users/zsh-autosuggestions ]; then
zsh -c 'source ~/.zshrc && zplug update zsh-users/zsh-autosuggestions'
else
zsh -c "source ~/.zshrc && zplug install zsh-users/zsh-autosuggestions"
fi
echo "Install zsh-syntax-highlighting as zsh plugins..."
echo '
export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#839496,bold,underline"
zplug "zsh-users/zsh-syntax-highlighting", as:plugin
' >>~/.zshrc
if [ -d $ZPLUG_HOME/repos/zsh-users/zsh-syntax-highlighting ]; then
zsh -c 'source ~/.zshrc && zplug update zsh-users/zsh-syntax-highlighting'
else
zsh -c "source ~/.zshrc && zplug install zsh-users/zsh-syntax-highlighting"
fi
echo "Install zsh-history-substring-search as zsh plugins..."
echo '
zplug "zsh-users/zsh-history-substring-search", as:plugin
' >>~/.zshrc
if [ -d $ZPLUG_HOME/repos/zsh-users/zsh-history-substring-search ]; then
zsh -c 'source ~/.zshrc && zplug update zsh-users/zsh-history-substring-search'
else
zsh -c "source ~/.zshrc && zplug install zsh-users/zsh-history-substring-search"
fi
echo 'zplug load' >>~/.zshrc
echo "Change user default shell to zsh..."
sudo -- sh -c "usermod --shell `which zsh` $USER"
echo '
if [ -n "$(which kubeadm)" ]; then
# shellcheck source=/usr/bin/kubeadm
source <(kubeadm completion zsh)
fi
if [ -n "$(which kubectl)" ]; then
# shellcheck source=/usr/bin/kubectl
source <(kubectl completion zsh)
fi
' >> ~/.zshrc
echo '
if [ -n "$(which crio)" ]; then
# shellcheck source=/usr/bin/crio
source <(crio completion zsh)
fi
if [ -n "$(which crio-status)" ]; then
# shellcheck source=/usr/bin/crio-status
source <(crio-status completion zsh)
fi
' >> ~/.zshrc
echo '
if [ -n "$(which podman)" ]; then
# shellcheck source=/usr/bin/podman
source <(podman completion zsh)
fi
' >> ~/.zshrc
@grammy-jiang
Copy link
Author

grammy-jiang commented Apr 10, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment