zshrc 6.4 KB

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