通过 alias 命令为常用的组合设置别名,可以有效增加日常使用便捷性。但是此处不推荐对较为大众化的命令进行别名覆盖,否则容易出现意想不到的问题。但是,alias ip=ip -color 这种无伤大雅的别名覆盖并不会存在太多隐患。
1 2 3 4 5 6 7 8 9 10 11
alias ll='ls -lFh' alias la='ls -al' alias l='ls -1' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' aliasdir='ls' alias ip='ip -color' if [[ $os_type != "OpenWrt" ]]; then # alias vim='nvim' fi
# 开启自动纠正错误 ENABLE_CORRECTION="true" #======================== oh-my-zsh 设置 END ========================
#======================== 插件配置 BEGIN ======================== plugins=( bundler dotenv git macos rake rbenv ruby zsh-autosuggestions zsh-syntax-highlighting ) #======================== 插件配置 END ========================
#======================== 启用 oh-my-zsh 配置 BEGIN ======================== source$ZSH/oh-my-zsh.sh #======================== 启用 oh-my-zsh 配置 END ========================
#======================== pip 设置 BEGIN ======================== # (1) pip 默认设置为 pip3 alias pip='pip3' alias ipython='ipython3' # (2) pip 自动补全 function _pip_completion { local words cword read -Ac words read -cn cword reply=( $( COMP_WORDS="$words[*]" \ COMP_CWORD=$(( cword-1 )) \ PIP_AUTO_COMPLETE=1 $words[1] ) ) } compctl -K _pip_completion pip3 # (3) 设置 Python3-pip 的自动更新函数 function_pip_update () { pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo -H pip3 install -U } #======================== pip 设置 END ========================
#======================== 别名 BEGIN ======================== alias ll='ls -lFh' alias la='ls -a' alias l='ls -1' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' aliasdir='ls' alias ip='ip -color' aliasdirs='dirs -lpv' #======================== 别名 END ========================
#======================== Terminal Color BEGIN ======================== LS_COLORS=$LS_COLORS:'di=0;36' ; export LS_COLORS #======================== Terminal Color END ========================
#======================== TeXLive 配置 BEGIN ======================== # TeX Live 的相关设置: # (1) 导入系统的参考手册 # (2) TeX Live 配置与系统类型有关,与 Linux 发行版无关,因此只需用 uname 查询内核即可 is_texlive_installed="false" function_set_texlive () { # (1) 判断 texlive 是否已安装 texlive_folder='/usr/local/texlive/' if [ -d ${texlive_folder} ]; then max_texlive_version=`ls -1 -r ${texlive_folder} | grep -E '20*' | head -n 1` if [[ -n ${max_texlive_version} ]]; then
# A. 更改环境变量 is_texlive_installed="true"
# B. 设置操作系统对应的环境变量 if [[ $os_type == "macOS" ]]; then export MANPATH=/usr/local/texlive/${max_texlive_version}/texmf-dist/doc/man:${MANPATH} export INFOPATH=/usr/local/texlive/${max_texlive_version}/texmf-dist/doc/info:${INFOPATH} export PATH=/usr/local/texlive/${max_texlive_version}/bin/universal-darwin:${PATH} elif [[ $os_type == "Linux" ]]; then export MANPATH=/usr/local/texlive/${max_texlive_version}/texmf-dist/doc/man:${MANPATH} export INFOPATH=/usr/local/texlive/${max_texlive_version}/texmf-dist/doc/info:${INFOPATH} export PATH=/usr/local/texlive/${max_texlive_version}/bin/x86_64-linux:${PATH} else # 抛出异常,等待日后处理此类系统类型 echo"系统类型无法识别" fi fi fi } # (2) 执行 set_texlive 函数 _set_texlive; #======================== TeXLive 配置 END ========================
#======================== UPDATE 设置 BEGIN ======================== # 系统自动更新,该函数不区分系统 function os-update () { # (1) 更新 TeX Live print -P "%F{cyan}Step 1/3 tlmgr update%f" if [[ $is_texlive_installed == "true" ]]; then sudo tlmgr update --self --all elif [[ $is_texlive_installed == "false" ]]; then print -P "%F{white}INFO: No installation of texlive was detected, please check it%f" fi
# (2) 更新 miniconda Python,不使用系统 Python print -P "%F{cyan}Step 2/3: Updating Miniconda%f" print -P "%F{white}NOTE: Only the base virtual environment will be updated.%f" conda activate base conda upgrade -n base --yes --all
# for rxvt bindkey"\e[8~" end-of-line bindkey"\e[7~" beginning-of-line # for non RH/Debian xterm, can't hurt for RH/DEbian xterm bindkey"\eOH" beginning-of-line bindkey"\eOF" end-of-line # for freebsd console bindkey"\e[H" beginning-of-line bindkey"\e[F" end-of-line # completion in the middle of a line bindkey'^i' expand-or-complete-prefix
# 其他相关 export harbor="app-registry.proxy.littlenewton.cn" export PATH=${HOME}/bin/:$PATH fi #======================== 环境变量 END ========================
# >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! __conda_setup="$('/home/newton/bin/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then eval"$__conda_setup" else if [ -f "/home/newton/bin/miniconda3/etc/profile.d/conda.sh" ]; then . "/home/newton/bin/miniconda3/etc/profile.d/conda.sh" else export PATH="/home/newton/bin/miniconda3/bin:$PATH" fi fi unset __conda_setup # <<< conda initialize <<<
#======================== K8S BEGIN ======================== function enable_k8s_autocompletion { ifcommand -v kubectl >/dev/null 2>&1; then if kubectl get node $(hostname) -o=jsonpath='{.metadata.labels}' | grep -q 'node-role.kubernetes.io/control-plane'; then source ~/.zsh/kubectl_auto_completion.sh source ~/.zsh/kubeadm_auto_completion.sh fi fi } current_hostname=$(hostname)
if [[ "$current_hostname" == "epyc-debian" ]]; then enable_k8s_autocompletion; fi #======================== K8S END ========================
# Zsh related config file. export ZDOTDIR="$XDG_CONFIG_HOME/zsh" export HISTFILE="$ZDOTDIR/.zhistory" # History filepath export HISTSIZE=10000 # Maximum events for internal history export SAVEHIST=10000 # Maximum events in history file