zshrc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. alias mgrep="grep --color=auto -rnisH"
  114. alias rsu="sudo -E zsh"
  115. alias reloadsh="exec zsh"
  116. alias md="mkdir -p"
  117. mcd() { mkdir -p "$@" && cd "$@" }
  118. alias aug='sudo apt-get update && sudo apt-get upgrade'
  119. if (( $+commands[ccze] )) ; then
  120. alias alog='tail -n 300 -F /var/log/auth.log | ccze'
  121. alias mlog='tail -n 300 -F /var/log/mail.log | ccze'
  122. alias slog='tail -n 300 -F /var/log/syslog | ccze'
  123. else
  124. alias alog='tail -n 300 -F /var/log/auth.log'
  125. alias mlog='tail -n 300 -F /var/log/mail.log'
  126. alias slog='tail -n 300 -F /var/log/syslog'
  127. fi
  128. alias sscp_nosec='scp -o '\''StrictHostKeyChecking=no'\'' -o '\''UserKnownHostsFile=/dev/null'\'
  129. alias ssh_nosec='ssh -o '\''StrictHostKeyChecking=no'\'' -o '\''UserKnownHostsFile=/dev/null'\'
  130. #
  131. # History options
  132. #
  133. setopt extendedhistory # add a timestamp and the duration of each command
  134. setopt sharehistory # _all_ zsh sessions share the same history files
  135. setopt histignorealldups # ignores duplications
  136. export HISTSIZE=1000000
  137. export SAVEHIST=1000000
  138. export HISTFILE="${TMPDIR}/.zhistory"
  139. #
  140. # Zsh options
  141. #
  142. export LISTPROMPT # in order to scroll if completion list is too big
  143. setopt clobber # Allows > redirection to truncate existing files, and >> to create files
  144. setopt checkjobs # Report the status of background and suspended jobs before exiting a shell
  145. setopt auto_cd # a command like % /usr/local is equivalent to cd /usr/local
  146. setopt nohup # don't send HUP signal when closing term session
  147. setopt extended_glob # in order to use #, ~ and ^ for filename generation
  148. setopt always_to_end # move to cursor to the end after completion
  149. setopt notify # report the status of backgrounds jobs immediately
  150. setopt correct # try to correct the spelling if possible
  151. setopt noflowcontrol # disable xon/xoff
  152. setopt histnostore # don't store history command in history
  153. setopt nobanghist # don't care of '!' in commands
  154. setopt emacs # zle in emacs mode
  155. setopt pushdignoredups # ignore dups in pushd stack
  156. setopt auto_continue # send SIGCONT to jobs disowned
  157. setopt auto_list # list choice on ambiguous command
  158. setopt auto_pushd # cd = pushd
  159. setopt pushd_ignore_dups # ignore dups in pushd
  160. setopt pushd_silent # don't print stack after push/pop
  161. setopt bang_hist # yeah ! expansion (use bash !$ for example)
  162. setopt chase_links # cd to a symlink is in fact cd to the true dir
  163. setopt ksh_option_print # modify setopt output
  164. setopt long_list_jobs # list jobs in long format
  165. setopt no_rm_star_wait # dont't idle 10 seconds
  166. #
  167. # Zle config
  168. #
  169. # autoescape specials chars with urls
  170. autoload -U url-quote-magic
  171. zle -N self-insert url-quote-magic
  172. # insert sudo at beggining of current command
  173. insert-sudo-prefix () {
  174. local prefix
  175. prefix='sudo'
  176. if [ "${BUFFER:0:${#prefix}}" != "$prefix" ]; then
  177. BUFFER="$prefix $BUFFER"
  178. CURSOR=$(($CURSOR + $#prefix + 1))
  179. fi
  180. }
  181. zle -N insert-sudo-prefix
  182. bindkey "^b" insert-sudo-prefix
  183. # make home and end keys work with tmux
  184. bindkey "^[[H" beginning-of-line
  185. bindkey "^[[F" end-of-line
  186. #
  187. # MOTD
  188. #
  189. if [[ "${LC_SSH_VARS}" = 1 ]]; then
  190. if [[ -z "${TMUX}" ]] && [[ -z "${SUDO_UID}" ]]; then
  191. if [[ -z "${LC_SSH_EMAIL}" || -z "${LC_SSH_FULLNAME}" ]]; then
  192. 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"
  193. else
  194. 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"
  195. fi
  196. if [[ ! -e "${SSH_AUTH_SOCK}" ]]; then
  197. printf "${COLOR_LIGHT_YELLOW}Be warned that your ssh agent is not forwarded${COLOR_RESET}\n"
  198. fi
  199. fi
  200. fi
  201. #
  202. # NVM
  203. #
  204. export NVM_DIR="/usr/local/nvm"
  205. if [ -s "$NVM_DIR/nvm.sh" ]; then
  206. . "$NVM_DIR/nvm.sh"
  207. fi
  208. #
  209. # Node JS related tools
  210. #
  211. alias npm="HOME=${HOME}/tmp npm"
  212. alias grunt="HOME=${HOME}/tmp grunt"
  213. alias bower="HOME=${HOME}/tmp bower"
  214. alias gulp="HOME=${HOME}/tmp gulp"
  215. alias yarn="HOME=${HOME}/tmp yarn"