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'51PROMPT="$PROMPT_VCS_PREFIX"'%F{yellow}${PROMPT_HOST} %F{blue}%~ ${LINEUP}%F{green}<%D{%H:%M}>%f'52PROMPT+="${NEWLINE}%B%F{red}%(?..[%?] )%f$%b "5354# hooks55function xterm_title_precmd () {56 print -Pn '\e]2;%n@%m %1~\a'57}58function xterm_title_preexec () {59 print -Pn '\e]2;%n@%m %1~ %# '60 print -n "${(q)1}\a"61}6263function source_env {64 if [[ -x .env ]]65 then66 set -a; source .env; set +a67 fi68}6970function py_venv {71 PYENV=${PYENV:-venv}7273 if [[ -f "$PYENV/bin/activate" ]]; then74 if [[ -n "$VIRTUAL_ENV" && $(realpath "$VIRTUAL_ENV") != $(realpath "$PYENV") ]]; then75 # if running venv is not the same as current one, deavtivate it first76 deactivate77 fi7879 if [ -z "$VIRTUAL_ENV" ]; then80 # if no running venv(avoid activate multiple times), active current one81 . $PYENV/bin/activate82 fi8384 # do nothing if current one is activated85 else86 unset PYENV87 fi8889 if [[ -n "$VIRTUAL_ENV" && -z "$PYENV" ]]; then90 if [[ $PWD != $(dirname $VIRTUAL_ENV)/* ]]; then91 deactivate92 fi93 fi94}9596pipe_command_output_precmd() {97 if ! builtin zle; then98 print -n "\e]133;D\e\\"99 fi100}101pipe_command_output_preexec() {102 print -n "\e]133;C\e\\"103}104105if [[ "$TERM" == (screen*|xterm*|rxvt*) ]]; then106 add-zsh-hook -Uz precmd xterm_title_precmd107 add-zsh-hook -Uz preexec xterm_title_preexec108109 add-zsh-hook -Uz precmd pipe_command_output_precmd110 add-zsh-hook -Uz preexec pipe_command_output_preexec111 # add-zsh-hook chpwd source_env112 # add-zsh-hook chpwd py_venv113fi114115116# active when start zsh in home dir117# source_env118# py_venv119120# other configuration files121if [ -f "$HOME/.zshrc" ]; then source $HOME/.zshrc; fi122123if [ -f "$ZDOTDIR/.zshalias" ]; then source $ZDOTDIR/.zshalias; fi124125if [ -f "$HOME/.zshalias" ]; then source $HOME/.zshalias; fi126127# launch applications128[[ -x "$(command -v gpgconf)" && -d "$HOME/.gnupg" ]] && gpgconf --launch gpg-agent && gpg-connect-agent updatestartuptty /bye >/dev/null129130131if [ -f "/usr/share/fzf/completion.zsh" ]; then source /usr/share/fzf/completion.zsh; fi132if [ -f "/usr/share/fzf/key-bindings.zsh" ]; then source /usr/share/fzf/key-bindings.zsh; fi133export FZF_CTRL_T_COMMAND="command find -L . -mindepth 1 -maxdepth 3 \\( -path '*/.*' \\) -prune \134 -o -type f -print \135 -o -type d -print \136 -o -type l -print 2> /dev/null | cut -b3-"137138stty -ixon