zshrc 6.7 KB

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