dotfiles

Alpine Linux dotfiles

git clone git://git.lin.moe/dotfiles.git

  1# Try to start tmux first, avoid load zsh configs multiple times
  2# Auto start tmux when connect with ssh and SSHTMUX env setted
  3if [[ -v SSHTMUX ]] && [[ -x "$(command -v tmux)" ]]; then
  4	if [[ $- =~ i ]] && [[ -z "$TMUX" ]] && [[ -n "$SSH_TTY" ]]; then
  5		exec tmux new-session -A -s  ${HOST%%.*}
  6	fi
  7fi
  8
  9# config history
 10HISTFILE=~/.histfile
 11HISTSIZE=10000
 12SAVEHIST=10000
 13setopt EXTENDED_HISTORY
 14setopt HIST_EXPIRE_DUPS_FIRST
 15setopt HIST_IGNORE_DUPS
 16setopt HIST_IGNORE_SPACE
 17setopt HIST_REDUCE_BLANKS
 18setopt HIST_FIND_NO_DUPS
 19setopt HIST_SAVE_NO_DUPS
 20
 21bindkey -e
 22
 23# set path
 24[ $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)
 27
 28# auto completions
 29autoload -Uz compinit promptinit
 30compinit
 31
 32# prompt
 33promptinit
 34# prompt walters
 35
 36# vcs
 37autoload -Uz vcs_info
 38
 39setopt PROMPT_SUBST
 40vcs_info 2>/dev/null
 41if [ $? -eq 0 ]; then
 42	add-zsh-hook -Uz precmd vcs_info
 43	zstyle ':vcs_info:git:*' formats '[%F{cyan}%b%f] '
 44  PROMPT_VCS_PREFIX='${vcs_info_msg_0_}'
 45fi
 46export PROMPT_EOL_MARK=''
 47
 48NEWLINE=$'\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 "
 53
 54# hooks
 55function 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}
 62
 63function source_env {
 64	if [[ -x .env ]]
 65	then
 66		set -a; source .env; set +a
 67	fi
 68}
 69
 70function py_venv {
 71	PYENV=${PYENV:-venv}
 72
 73	if [[ -f "$PYENV/bin/activate" ]]; then
 74		if [[ -n "$VIRTUAL_ENV" && $(realpath "$VIRTUAL_ENV") != $(realpath "$PYENV") ]]; then
 75			# if running venv is not the same as current one, deavtivate it first
 76			deactivate
 77		fi
 78
 79		if [ -z "$VIRTUAL_ENV" ]; then
 80			# if no running venv(avoid activate multiple times), active current one
 81			. $PYENV/bin/activate
 82		fi
 83
 84		# do nothing if current one is activated
 85	else
 86		unset PYENV
 87	fi 
 88
 89	if [[ -n "$VIRTUAL_ENV" && -z "$PYENV" ]]; then
 90		if [[ $PWD != $(dirname $VIRTUAL_ENV)/* ]]; then
 91		    deactivate
 92		fi
 93	fi
 94}
 95
 96pipe_command_output_precmd() {
 97	if ! builtin zle; then
 98		print -n "\e]133;D\e\\"
 99	fi
100}
101pipe_command_output_preexec() {
102  print -n "\e]133;C\e\\"
103}
104
105if [[ "$TERM" == (screen*|xterm*|rxvt*) ]]; then
106	add-zsh-hook -Uz precmd xterm_title_precmd
107	add-zsh-hook -Uz preexec xterm_title_preexec
108
109	add-zsh-hook -Uz precmd pipe_command_output_precmd
110	add-zsh-hook -Uz preexec pipe_command_output_preexec
111	# add-zsh-hook chpwd source_env
112	# add-zsh-hook chpwd py_venv
113fi
114
115
116# active when start zsh in home dir
117# source_env
118# py_venv
119
120# other configuration files
121if [ -f "$HOME/.zshrc" ]; then source $HOME/.zshrc; fi
122
123if [ -f "$ZDOTDIR/.zshalias" ]; then source $ZDOTDIR/.zshalias; fi
124
125if [ -f "$HOME/.zshalias" ]; then source $HOME/.zshalias; fi
126
127# launch applications
128[[ -x "$(command -v gpgconf)" && -d "$HOME/.gnupg" ]]  && gpgconf --launch gpg-agent && gpg-connect-agent updatestartuptty /bye >/dev/null
129
130
131if [ -f "/usr/share/fzf/completion.zsh" ]; then source /usr/share/fzf/completion.zsh; fi
132if [ -f "/usr/share/fzf/key-bindings.zsh" ]; then source /usr/share/fzf/key-bindings.zsh; fi
133export 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-"
137
138stty -ixon