zshrc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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_OPTIONS=()
  71. if [[ -n "${LC_SSH_FULLNAME}" ]]; then
  72. GIT_OPTIONS+=(-c "user.name=${LC_SSH_FULLNAME}")
  73. fi
  74. if [[ -n "${LC_SSH_EMAIL}" ]]; then
  75. GIT_OPTIONS+=(-c "user.email=${LC_SSH_EMAIL}")
  76. fi
  77. export GIT_OPTIONS
  78. export GIT_FAKE_HOME="$(readlink -f "${ZDOTDIR}/../tools/git")"
  79. if [[ -f "${GIT_FAKE_HOME}/.gitconfig" ]]; then
  80. git() {
  81. (
  82. export LC_MESSAGES='en_US.UTF-8'
  83. export HOME="${GIT_FAKE_HOME}"
  84. =git ${GIT_OPTIONS} $@
  85. )
  86. }
  87. fi
  88. #
  89. # Tmux
  90. #
  91. TMUX_OPTS="-2"
  92. TMUX_CONF="$(readlink -f "${ZDOTDIR}/../tools/tmux/tmux.conf")"
  93. if [[ -f "${TMUX_CONF}" ]]; then
  94. TMUX_OPTS="${TMUX_OPTS} -f ${TMUX_CONF}"
  95. fi
  96. alias tmux="TMPDIR= tmux ${TMUX_OPTS}"
  97. unset TMUX_OPTS TMUX_CONF
  98. #
  99. # Common aliases / functions
  100. #
  101. alias ls='ls -h --color=auto'
  102. alias l='ls -lh --color=auto'
  103. alias rm='rm -i'
  104. alias mv='mv -i'
  105. alias cp='cp -i'
  106. export GREP_OPTIONS="--color=auto"
  107. alias mgrep="grep -rnisH"
  108. alias grep="grep"
  109. alias rsu="sudo -E zsh"
  110. alias reloadsh="exec zsh"
  111. alias md="mkdir -p"
  112. mcd() { mkdir -p "$@" && cd "$@" }
  113. alias aug='sudo apt-get update && sudo apt-get upgrade'
  114. if (( $+commands[ccze] )) ; then
  115. alias alog='tail -n 300 -F /var/log/auth.log | ccze'
  116. alias mlog='tail -n 300 -F /var/log/mail.log | ccze'
  117. alias slog='tail -n 300 -F /var/log/syslog | ccze'
  118. else
  119. alias alog='tail -n 300 -F /var/log/auth.log'
  120. alias mlog='tail -n 300 -F /var/log/mail.log'
  121. alias slog='tail -n 300 -F /var/log/syslog'
  122. fi
  123. alias sscp_nosec='scp -o '\''StrictHostKeyChecking=no'\'' -o '\''UserKnownHostsFile=/dev/null'\'
  124. alias ssh_nosec='ssh -o '\''StrictHostKeyChecking=no'\'' -o '\''UserKnownHostsFile=/dev/null'\'
  125. #
  126. # History options
  127. #
  128. setopt extendedhistory # add a timestamp and the duration of each command
  129. setopt sharehistory # _all_ zsh sessions share the same history files
  130. setopt histignorealldups # ignores duplications
  131. export HISTSIZE=1000000
  132. export SAVEHIST=1000000
  133. export HISTFILE="${TMPDIR}/.zhistory"
  134. #
  135. # Zsh options
  136. #
  137. export LISTPROMPT # in order to scroll if completion list is too big
  138. setopt auto_cd # a command like % /usr/local is equivalent to cd /usr/local
  139. setopt nohup # don't send HUP signal when closing term session
  140. setopt extended_glob # in order to use #, ~ and ^ for filename generation
  141. setopt always_to_end # move to cursor to the end after completion
  142. setopt notify # report the status of backgrounds jobs immediately
  143. setopt correct # try to correct the spelling if possible
  144. setopt rmstarwait # wait 10 seconds before querying for a rm which contains a *
  145. setopt noflowcontrol # disable xon/xoff
  146. setopt histnostore # don't store history command in history
  147. setopt nobanghist # don't care of '!' in commands
  148. setopt emacs # zle in emacs mode
  149. setopt pushdignoredups # ignore dups in pushd stack
  150. setopt auto_continue # send SIGCONT to jobs disowned
  151. setopt auto_list # list choice on ambiguous command
  152. setopt auto_pushd # cd = pushd
  153. setopt pushd_ignore_dups # ignore dups in pushd
  154. setopt pushd_silent # don't print stack after push/pop
  155. setopt bang_hist # yeah ! expansion (use bash !$ for example)
  156. setopt chase_links # cd to a symlink is in fact cd to the true dir
  157. setopt ksh_option_print # modify setopt output
  158. setopt long_list_jobs # list jobs in long format
  159. setopt no_rm_star_wait # dont't idle 10 seconds
  160. #
  161. # Zle config
  162. #
  163. # autoescape specials chars with urls
  164. autoload -U url-quote-magic
  165. zle -N self-insert url-quote-magic
  166. # insert sudo at beggining of current command
  167. insert-sudo-prefix () {
  168. local prefix
  169. prefix='sudo'
  170. if [ "${BUFFER:0:${#prefix}}" != "$prefix" ]; then
  171. BUFFER="$prefix $BUFFER"
  172. CURSOR=$(($CURSOR + $#prefix + 1))
  173. fi
  174. }
  175. zle -N insert-sudo-prefix
  176. bindkey "^b" insert-sudo-prefix
  177. # make home and end keys work with tmux
  178. bindkey "^[[H" beginning-of-line
  179. bindkey "^[[F" end-of-line
  180. #
  181. # MOTD
  182. #
  183. if [[ "${LC_SSH_VARS}" = 1 ]]; then
  184. if [[ -z "${TMUX}" ]] && [[ -z "${SUDO_UID}" ]]; then
  185. if [[ -z "${LC_SSH_EMAIL}" || -z "${LC_SSH_FULLNAME}" ]]; then
  186. 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"
  187. else
  188. 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"
  189. fi
  190. if [[ ! -e "${SSH_AUTH_SOCK}" ]]; then
  191. printf "${COLOR_LIGHT_YELLOW}Be warned that your ssh agent is not foarwarded${COLOR_RESET}\n"
  192. fi
  193. fi
  194. fi