1# Try to start tmux first, avoid load zsh configs multiple times2# Auto start tmux when connect with ssh and SSHTMUX env setted3if [[ -v SSHTMUX ]] && [[ -x "$(command -v tmux)" ]]; then4 if [[ $- =~ i ]] && [[ -z "$TMUX" ]] && [[ -n "$SSH_TTY" ]]; then5 exec tmux new-session -A -s ${HOST%%.*}6 fi7fi89# config history10HISTFILE=~/.histfile11HISTSIZE=1000012SAVEHIST=1000013setopt EXTENDED_HISTORY14setopt HIST_EXPIRE_DUPS_FIRST15setopt HIST_IGNORE_DUPS16setopt HIST_IGNORE_SPACE17setopt HIST_REDUCE_BLANKS18setopt HIST_FIND_NO_DUPS19setopt HIST_SAVE_NO_DUPS2021bindkey -e2223# set path24[ $path[(Ie)$HOME/.local/bin] -eq "0" ] && path+=("$HOME/.local/bin")25[ -x "$(command -v go)" ] && [ $path[(Ie)$(go env GOPATH)/bin] -eq "0" ] && path+=("$(go env GOPATH)/bin")26[ -z "$PYTHONUSERBASE" ] || path+=($PYTHONUSERBASE/bin)2728# auto completions29autoload -Uz compinit promptinit30compinit3132# prompt33promptinit34# prompt walters3536# vcs37autoload -Uz vcs_info3839setopt PROMPT_SUBST40vcs_info 2>/dev/null41if [ $? -eq 0 ]; then42 add-zsh-hook -Uz precmd vcs_info43 zstyle ':vcs_info:git:*' formats '%F{cyan}[%b]%f '44 PROMPT_VCS_PREFIX='${vcs_info_msg_0_}'45fi46export PROMPT_EOL_MARK=''4748NEWLINE=$'\n'49PROMPT_HOST='%n'50[[ -n $SSH_CLIENT ]] && PROMPT_HOST+='@%U%m%u'51_CURRENTNET=$(ip netns identify $$ 2>/dev/null)52[[ -n "$_CURRENTNET" ]] && PROMPT_NETNS="%F{magenta}<$_CURRENTNET>%f "5354PROMPT='$PROMPT_NETNS'"$PROMPT_VCS_PREFIX"'%F{yellow}${PROMPT_HOST} %F{blue}%~ ${LINEUP}%F{green}<%D{%H:%M}>%f'55PROMPT+="${NEWLINE}%B%F{red}%(?..[%?] )%f$%b "5657# hooks58function xterm_title_precmd () {59 print -Pn '\e]2;%n@%m %1~\a'60}61function xterm_title_preexec () {62 print -Pn '\e]2;%n@%m %1~ %# '63 print -n "${(q)1}\a"64}6566function source_env {67 if [[ -x .env ]]68 then69 set -a; source .env; set +a70 fi71}7273function py_venv {74 PYENV=${PYENV:-venv}7576 if [[ -f "$PYENV/bin/activate" ]]; then77 if [[ -n "$VIRTUAL_ENV" && $(realpath "$VIRTUAL_ENV") != $(realpath "$PYENV") ]]; then78 # if running venv is not the same as current one, deavtivate it first79 deactivate80 fi8182 if [ -z "$VIRTUAL_ENV" ]; then83 # if no running venv(avoid activate multiple times), active current one84 . $PYENV/bin/activate85 fi8687 # do nothing if current one is activated88 else89 unset PYENV90 fi9192 if [[ -n "$VIRTUAL_ENV" && -z "$PYENV" ]]; then93 if [[ $PWD != $(dirname $VIRTUAL_ENV)/* ]]; then94 deactivate95 fi96 fi97}9899pipe_command_output_precmd() {100 if ! builtin zle; then101 print -n "\e]133;D\e\\"102 fi103}104pipe_command_output_preexec() {105 print -n "\e]133;C\e\\"106}107108if [[ "$TERM" == (screen*|xterm*|rxvt*) ]]; then109 add-zsh-hook -Uz precmd xterm_title_precmd110 add-zsh-hook -Uz preexec xterm_title_preexec111112 add-zsh-hook -Uz precmd pipe_command_output_precmd113 add-zsh-hook -Uz preexec pipe_command_output_preexec114 # add-zsh-hook chpwd source_env115 # add-zsh-hook chpwd py_venv116fi117118119# active when start zsh in home dir120# source_env121# py_venv122123# other configuration files124if [ -f "$HOME/.zshrc" ]; then source $HOME/.zshrc; fi125126if [ -f "$ZDOTDIR/.zshalias" ]; then source $ZDOTDIR/.zshalias; fi127128if [ -f "$HOME/.zshalias" ]; then source $HOME/.zshalias; fi129130# launch applications131[[ -x "$(command -v gpgconf)" && -d "$HOME/.gnupg" && ! -S $HOME/.gnupg/S.gpg-agent ]] && \132 gpgconf --launch gpg-agent && gpg-connect-agent updatestartuptty /bye >/dev/null133134135if [ -f "/usr/share/fzf/completion.zsh" ]; then source /usr/share/fzf/completion.zsh; fi136if [ -f "/usr/share/fzf/key-bindings.zsh" ]; then source /usr/share/fzf/key-bindings.zsh; fi137export FZF_CTRL_T_COMMAND="command find -L . -mindepth 1 -maxdepth 3 \\( -path '*/.*' \\) -prune \138 -o -type f -print \139 -o -type d -print \140 -o -type l -print 2> /dev/null | cut -b3-"141142stty -ixon