notes/config/zsh/init.zsh

326 lines
10 KiB
Bash

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.config/oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="bracket" # set by `omz`
# ZSH_THEME="powerlevel10k/powerlevel10k"
# POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir vcs)
# POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs time virtualenv)
# POWERLEVEL9K_MODE="nerdfont-complete"
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# 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="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# 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"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
HIST_STAMPS="yyyy-mm-dd"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
BASE_PLGS=(
git
z
extract
colorize
cp
colored-man-pages
)
if [[ "" != $(which fzf) ]]; then
BASE_PLGS+=(fzf)
fi
function test_and_source() {
filepath=$1
if [[ -f $filepath ]]; then
source $filepath
return 0
fi
return 1
}
function test_and_source_first() {
filepath_list=$1
for filepath in ${filepath_list}
do
test_and_source $filepath
if [[ $? -eq 0 ]]; then
break
fi
done
}
VIRTUALENV_PATHS=(
"/usr/bin/virtualenvwrapper.sh" # For Archlinux based OS
"/usr/local/bin/virtualenvwrapper.sh" # For BSD based OS
"/usr/share/virtualenvwrapper/virtualenvwrapper.sh" # For debian
"/opt/homebrew/bin/virtualenvwrapper.sh" # For MacOS arm
)
for VIRTUALENV in ${VIRTUALENV_PATHS[@]}
do
test_and_source $VIRTUALENV
if [[ $? -eq 0 ]]; then
BASE_PLGS+=(virtualenv virtualenvwrapper)
break
fi
done
unset VIRTUALENV_PATHS
ZSH_SYSTEM_PLUGINS=(
"/usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh"
"/usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh"
"/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
)
# test_and_source_first $ZSH_AUTOSUGGEST_PLUGINS
for PLUGIN in ${ZSH_SYSTEM_PLUGINS}
do
if [[ -f $PLUGIN ]]; then
source $PLUGIN
fi
done
unset ZSH_SYSTEM_PLUGINS
if [[ -d "$ZSH/custom/plugins/zsh-autosuggestions" ]]; then
BASE_PLGS+=(zsh-autosuggestions)
fi
if [[ -d "$ZSH/custom/plugins/zsh-syntax-highlighting" ]]; then
BASE_PLGS+=(zsh-syntax-highlighting)
fi
plugins=(${BASE_PLGS[@]})
unset BASE_PLGS
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='mvim'
# fi
export EDITOR='vim'
alias vimdiff='vi -d'
# delete remote branch
alias gpod='git push origin --delete'
# pip alias
alias piu='pip install -U'
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# ssh
if [[ -f $HOME/.ssh/id_ed25519 ]]; then
export SSH_KEY_PATH="$HOME/.ssh/id_ed25519"
elif [[ -f $HOME/.ssh/id_rsa ]]; then
export SSH_KEY_PATH="$HOME/.ssh/id_rsa"
fi
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
export LOCAL=$HOME/.local
export CONF=$HOME/.config
export LOG=$LOCAL/var/log
# npm config
if [[ -d $HOME/.local/node ]]; then
export NODE_HOME=$HOME/.local/node
export NODE_PATH=$NODE_PATH:$HOME/.local/npm/lib/node_modules
export PATH=$HOME/.local/npm/bin:$NODE_HOME/bin:$PATH
fi
function update_dlv () {
go install github.com/go-delve/delve/cmd/dlv@latest
}
# golang config
goinfo=$(echo $(which go))
if [[ $goinfo =~ "not found" ]]; then
# echo "go not found"
else
export GOPATH=$HOME/Projects/Go
export PATH=$HOME/.local/bin:$GOROOT/bin:$GOPATH/bin:$PATH
# export GOROOT=$(go env | grep -Eo '(GOROOT=.*)' | grep -Eo '(=.*)' | sed 's/=//g' | sed 's/"//g')
# export GOROOT=/usr/lib/go
export $(go env | grep 'GOROOT' | sed 's/"//g' | sed "s/'//g")
# export GOROOT=$HOME/.local/go
# :${JAVA_HOME}/bin:${PATH}
export GO111MODULE=on
fi
# 阿里云镜像
# export GOPROXY=https://mirrors.aliyun.com/goproxy/
# 中国golang镜像
# GOPROXY=https://goproxy.io
# go env -w GOPROXY=https://goproxy.cn,direct
export GOPROXY=https://goproxy.cn
# rust config
export CARGO_HOME=$HOME/.cargo
export PATH=$CARGO_HOME/bin:$PATH
# [[ -f ~/.fzf.zsh ]] && source ~/.fzf.zsh
# MacOS settings
if [[ $(uname -s) = "Darwin" ]]; then
# icoding
export ICODING_HOME=$HOME/.local/icoding
export PATH=$ICODING_HOME:$PATH
# MySQL 5.7 at MacOS
# For compilers to find mysql@5.7
if [[ $(uname -m) = "arm64" ]]; then
export MYSQL_HOME="/opt/homebrew/Cellar/mysql@5.7/5.7.38"
export LDFLAGS="-L/opt/homebrew/opt/mysql@5.7/lib"
export CPPFLAGS="-I/opt/homebrew/opt/mysql@5.7/include"
export PATH="/opt/homebrew/opt/go@1.17/bin:$PATH"
export PG_HOME="/opt/homebrew/opt/postgresql@15"
export LDFLAGS="-L/opt/homebrew/opt/postgresql@15/lib:$LDFLAGS"
export CPPFLAGS="-I/opt/homebrew/opt/postgresql@15/include:$CPPFLAGS"
export PATH="$PG_HOME/bin:$PATH"
else
export MYSQL_HOME="/usr/local/opt/mysql@5.7"
export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib -L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/mysql@5.7/include -I/usr/local/opt/openssl@1.1/include"
fi
export PATH=$MYSQL_HOME/bin:$PATH
export PKG_CONFIG_PATH=$MYSQL_HOME/lib/pkgconfig
# export VIRTUALENVWRAPPER_PYTHON="/usr/local/bin/python3"
export PATH="/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands":$PATH
# export GITSTATUS_LOG_LEVEL=DEBUG
# tig_completion=/usr/local/etc/bash_completion.d/tig-completion.bash
# if [[ -f $tig_completion ]]; then
# source $tig_completion
# fi
# android platform-tools
export PATH="$HOME/.local/platform-tools":$PATH
# php config
# export PATH="/opt/homebrew/opt/php@7.4/bin:$PATH"
# export PATH="/opt/homebrew/opt/php@7.4/sbin:$PATH"
# export LDFLAGS="-L/opt/homebrew/opt/php@7.4/lib"
# export CPPFLAGS="-I/opt/homebrew/opt/php@7.4/include"
alias sed="gsed"
# export GOPROXY=https://goproxy.baidu-int.com
# Update homebrew config
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
# node@16
export PATH="/opt/homebrew/opt/node@16/bin:$PATH"
# set go build
export GO_1_17_BIN=$GOROOT/bin
export GO_1_18_BIN=$GOROOT/bin
fi
if [[ -d "$LOCAL/jvm/OpenJDK8" ]]; then
export JAVA_HOME="$LOCAL/jvm/OpenJDK8"
# export GRAALVM_HOME=$JAVA_HOME
export JRE_HOME=${JAVA_HOME}/jre
export CLASS_PATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=$JAVA_HOME/bin:$PATH
# using maven from idea
IDEA_HOME="/opt/idea"
MVN_HOME=${IDEA_HOME}/plugins/maven/lib/maven3
export PATH=${MVN_HOME}/bin:$PATH
fi
if [[ -d "/opt/cuda/lib64" ]]; then
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/cuda/lib64/
fi
if [[ -d "/opt/openresty" ]]; then
export PATH=/opt/openresty/bin:$PATH
fi
if [[ -d "$LOCAL/node" ]]; then
export PATH=$LOCAL/node/bin:$PATH
fi
if [[ -d "$LOCAL/share/nvim/mason/bin" ]]; then
export PATH="$LOCAL/share/nvim/mason/bin":$PATH
fi
if [[ $XDG_SESSION_TYPE = "x11" ]]; then
alias pbcopy="xclip -sel clipboard"
alias pbpaste="xclip -sel clipboard -o"
elif [[ $XDG_SESSION_TYPE = "wayland" ]]; then
alias pbcopy="wl-copy"
alias pbpaste="wl-paste"
fi
# if type kitty >/dev/null 2>&1; then
# alias icat="kitty +kitten icat"
# alias kssh="kitty +kitten ssh"
# fi