zshrc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. ####################################################
  2. # Customized configuration for ZSH based on prezto #
  3. ####################################################
  4. #
  5. # TMPDIR
  6. #
  7. export TMPDIR="${HOME}/tmp"
  8. if [[ ! -d "${TMPDIR}" ]]; then
  9. mkdir -p "${TMPDIR}"
  10. fi
  11. #
  12. # Using zpresto
  13. #
  14. export ZDOTDIR="$(dirname "$(readlink -f "${0}")")"
  15. if [[ -f "${ZDOTDIR}/prezto/init.zsh" ]]; then
  16. source "${ZDOTDIR}/prezto/init.zsh"
  17. zstyle ':completion::complete:*' cache-path "${TMPDIR}/.zcompcache"
  18. # Remove first '\n' in PS1
  19. export PS1="$(echo "${PS1}" | sed ':a;N;$!ba;s/\n//')"
  20. fi
  21. #
  22. # Load some colors
  23. #
  24. autoload colors zsh/terminfo
  25. if [[ "${terminfo[colors]}" -ge 8 ]]; then
  26. colors
  27. fi
  28. for color in RED GREEN YELLOW BLUE MAGENTA CYAN ORANGE WHITE; do
  29. eval COLOR_$color='$terminfo[bold]$fg[${(L)color}]'
  30. eval COLOR_LIGHT_$color='$fg[${(L)color}]'
  31. done
  32. COLOR_RESET="$terminfo[sgr0]"
  33. #
  34. # Pager
  35. #
  36. VIMPAGER="$(readlink -f "${ZDOTDIR}/../tools/vimpager/vimpager")"
  37. if (( $+commands[vim] )) && [[ -f "${VIMPAGER}" ]]; then
  38. export PAGER="${VIMPAGER}"
  39. alias less="${PAGER}"
  40. alias more="${PAGER}"
  41. export VIMPAGER_RC="$(readlink -f "${ZDOTDIR}/../tools/vim/vimpagerrc")"
  42. if [[ ! -f "${VIMPAGER_RC}" ]]; then
  43. unset VIMPAGER_RC
  44. fi
  45. elif (( $+commands[less] )); then
  46. export PAGER=less
  47. alias more="${PAGER}"
  48. elif (( $+commands[more] )); then
  49. export PAGER=more
  50. fi
  51. export GIT_PAGER="${PAGER}"
  52. unset VIMPAGER
  53. #
  54. # Vim
  55. #
  56. VIMRC="$(readlink -f "${ZDOTDIR}/../tools/vim/vimrc")"
  57. if [[ -f "${VIMRC}" ]]; then
  58. export VIMINIT="source ${VIMRC}"
  59. fi
  60. unset VIMRC
  61. #
  62. # Git
  63. #
  64. GIT_IDENTITY_OPTS=
  65. if [[ -n "${LC_SSH_FULLNAME}" ]]; then
  66. GIT_IDENTITY_OPTS="-c 'user.name=${LC_SSH_FULLNAME}' ${GIT_IDENTITY_OPTS}"
  67. fi
  68. if [[ -n "${LC_SSH_EMAIL}" ]]; then
  69. GIT_IDENTITY_OPTS="-c 'user.email=${LC_SSH_EMAIL}' ${GIT_IDENTITY_OPTS}"
  70. fi
  71. GIT_FAKE_HOME="$(readlink -f "${ZDOTDIR}/../tools/git")"
  72. if [[ -f "${GIT_FAKE_HOME}/.gitconfig" ]]; then
  73. GIT_OPTS="LC_MESSAGES=en_US.UTF-8 HOME=${GIT_FAKE_HOME}"
  74. alias git="${GIT_OPTS} git ${GIT_IDENTITY_OPTS}"
  75. alias g="${GIT_OPTS} git ${GIT_IDENTITY_OPTS}"
  76. unset GIT_OPTS
  77. fi
  78. unset GIT_FAKE_HOME GIT_IDENTITY_OPTS
  79. #
  80. # Tmux
  81. #
  82. TMUX_OPTS="-2"
  83. TMUX_CONF="$(readlink -f "${ZDOTDIR}/../tools/tmux/tmux.conf")"
  84. if [[ -f "${TMUX_CONF}" ]]; then
  85. TMUX_OPTS="${TMUX_OPTS} -f ${TMUX_CONF}"
  86. fi
  87. alias tmux="TMPDIR= tmux ${TMUX_OPTS}"
  88. unset TMUX_OPTS TMUX_CONF
  89. #
  90. # Common aliases / functions
  91. #
  92. alias ls='ls -h --color=auto'
  93. alias l='ls -lh --color=auto'
  94. alias rm='rm -i'
  95. alias mv='mv -i'
  96. alias cp='cp -i'
  97. export GREP_OPTIONS="--color=auto"
  98. alias mgrep="grep -rnisH"
  99. alias grep="grep"
  100. alias rsu="sudo -E zsh"
  101. alias reloadsh="exec zsh"
  102. alias md="mkdir -p"
  103. mcd() { mkdir -p "$@" && cd "$@" }
  104. alias aug='sudo apt-get update && sudo apt-get upgrade'
  105. if (( $+commands[ccze] )) ; then
  106. alog='tail -n 300 -F /var/log/auth.log | ccze'
  107. mlog='tail -n 300 -F /var/log/mail.log | ccze'
  108. slog='tail -n 300 -F /var/log/syslog | ccze'
  109. else
  110. alog='tail -n 300 -F /var/log/auth.log'
  111. mlog='tail -n 300 -F /var/log/mail.log'
  112. slog='tail -n 300 -F /var/log/syslog'
  113. fi
  114. scp_nosec='scp -o '\''StrictHostKeyChecking=no'\'' -o '\''UserKnownHostsFile=/dev/null'\'
  115. ssh_nosec='ssh -o '\''StrictHostKeyChecking=no'\'' -o '\''UserKnownHostsFile=/dev/null'\'
  116. #
  117. # History options
  118. #
  119. setopt extendedhistory # add a timestamp and the duration of each command
  120. setopt sharehistory # _all_ zsh sessions share the same history files
  121. setopt histignorealldups # ignores duplications
  122. export HISTSIZE=1000000
  123. export SAVEHIST=1000000
  124. export HISTFILE="${TMPDIR}/.zhistory"
  125. #
  126. # Zsh options
  127. #
  128. export LISTPROMPT # in order to scroll if completion list is too big
  129. setopt auto_cd # a command like % /usr/local is equivalent to cd /usr/local
  130. setopt nohup # don't send HUP signal when closing term session
  131. setopt extended_glob # in order to use #, ~ and ^ for filename generation
  132. setopt always_to_end # move to cursor to the end after completion
  133. setopt notify # report the status of backgrounds jobs immediately
  134. setopt correct # try to correct the spelling if possible
  135. setopt rmstarwait # wait 10 seconds before querying for a rm which contains a *
  136. setopt noflowcontrol # disable xon/xoff
  137. setopt histnostore # don't store history command in history
  138. setopt nobanghist # don't care of '!' in commands
  139. setopt emacs # zle in emacs mode
  140. setopt pushdignoredups # ignore dups in pushd stack
  141. setopt auto_continue # send SIGCONT to jobs disowned
  142. setopt auto_list # list choice on ambiguous command
  143. setopt auto_pushd # cd = pushd
  144. setopt pushd_ignore_dups # ignore dups in pushd
  145. setopt pushd_silent # don't print stack after push/pop
  146. setopt bang_hist # yeah ! expansion (use bash !$ for example)
  147. setopt chase_links # cd to a symlink is in fact cd to the true dir
  148. setopt ksh_option_print # modify setopt output
  149. setopt long_list_jobs # list jobs in long format
  150. setopt no_rm_star_wait # dont't idle 10 seconds
  151. #
  152. # Zle config
  153. #
  154. # autoescape specials chars with urls
  155. autoload -U url-quote-magic
  156. zle -N self-insert url-quote-magic
  157. # insert sudo at beggining of current command
  158. insert-sudo-prefix () {
  159. local prefix
  160. prefix='sudo'
  161. if [ "${BUFFER:0:${#prefix}}" != "$prefix" ]; then
  162. BUFFER="$prefix $BUFFER"
  163. CURSOR=$(($CURSOR + $#prefix + 1))
  164. fi
  165. }
  166. zle -N insert-sudo-prefix
  167. bindkey "^b" insert-sudo-prefix
  168. # make home and end keys work with tmux
  169. bindkey "^[[H" beginning-of-line
  170. bindkey "^[[F" end-of-line
  171. #
  172. # MOTD
  173. #
  174. if [[ -z "${TMUX}" ]] && [[ -z "${SUDO_UID}" ]]; then
  175. if [[ -z "${LC_SSH_EMAIL}" || -z "${LC_SSH_FULLNAME}" ]]; then
  176. printf "\n${COLOR_RED}You environment seems to not be properly configured: LC_SSH_EMAIL and LC_SSH_FULLNAME have to be set and forwarded through the ssh connection.${COLOR_RESET}\n"
  177. exit 1
  178. else
  179. printf "\n${COLOR_LIGHT_GREEN}You are logged in as ${COLOR_YELLOW}${LC_SSH_FULLNAME}${COLOR_RESET} <${COLOR_YELLOW}${LC_SSH_EMAIL}${COLOR_RESET}>\n"
  180. fi
  181. if [[ ! -e "${SSH_AUTH_SOCK}" ]]; then
  182. printf "${COLOR_LIGHT_YELLOW}Be warned that your ssh agent is not foarwarded${COLOR_RESET}\n"
  183. fi
  184. fi