zshrc 6.6 KB

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