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'
 51_CURRENTNET=$(ip netns identify $$ 2>/dev/null)
 52[[ -n "$_CURRENTNET" ]] && PROMPT_NETNS="%F{magenta}<$_CURRENTNET>%f "
 53
 54PROMPT='$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 "
 56
 57# hooks
 58function 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}
 65
 66pipe_command_output_precmd() {
 67	if ! builtin zle; then
 68		print -n "\e]133;D\e\\"
 69	fi
 70}
 71pipe_command_output_preexec() {
 72  print -n "\e]133;C\e\\"
 73}
 74
 75if [[ "$TERM" == (screen*|xterm*|rxvt*) ]]; then
 76	add-zsh-hook -Uz precmd xterm_title_precmd
 77	add-zsh-hook -Uz preexec xterm_title_preexec
 78
 79	add-zsh-hook -Uz precmd pipe_command_output_precmd
 80	add-zsh-hook -Uz preexec pipe_command_output_preexec
 81fi
 82
 83# other configuration files
 84if [ -f "$HOME/.zshrc" ]; then source $HOME/.zshrc; fi
 85if [ -f "$ZDOTDIR/.zshalias" ]; then source $ZDOTDIR/.zshalias; fi
 86if [ -f "$HOME/.zshalias" ]; then source $HOME/.zshalias; fi
 87
 88# launch applications
 89[[ -x "$(command -v gpgconf)" && -d "$HOME/.gnupg" && ! -S $HOME/.gnupg/S.gpg-agent ]] && \
 90    gpgconf --launch gpg-agent && gpg-connect-agent updatestartuptty /bye >/dev/null
 91
 92# load fzf
 93if [ -f "/usr/share/fzf/completion.zsh" ]; then source /usr/share/fzf/completion.zsh; fi
 94if [ -f "/usr/share/fzf/key-bindings.zsh" ]; then source /usr/share/fzf/key-bindings.zsh; fi
 95
 96export FZF_CTRL_T_COMMAND="command find -L . -mindepth 1 -maxdepth 3 \\( -path '*/.*' \\) -prune \
 97       -o -type f -print \
 98       -o -type d -print \
 99       -o -type l -print 2> /dev/null | cut -b3-"
100
101stty -ixon