Advertisement
unixwz0r

.zshrc

Dec 30th, 2014
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.60 KB | None | 0 0
  1. ## .zshrc
  2. # by Jorge Schrauwen <[email protected]>
  3. # Version 2014071701
  4. #
  5. # How to install
  6. # curl -sk "https://docu.blackdot.be/getRaw.php?onlyCode=true&id=configuration:zsh" -o ~/.zshrc
  7. #
  8. # Change Log
  9. # - 20130717: add alias for pyedit
  10. # - 20130716: cleaner sbin handling on solaris
  11. # - 20130629: support for omnios.blackdot.be
  12. # - 20130625: revert some OmniOS stuff due to better understanding of isaexec
  13. # - 20130621: check if staff group on omnios and add sbin to path
  14. # - 20130615: parse .zprofile
  15. # - 20130520: added some stuff for OmniOS
  16. # - 20120308: fixed some mac stuff
  17. # - 20120823: automatic update
  18. # - 20120821: add support to disable UTF-8 checkmark with .znofancy
  19. echo ""
  20. figlet Tux Hat Linux
  21. echo ""
  22. #archey3 -c yellow
  23. echo ""
  24. echo "To setup Tux Hat Linux type ./setup-tuxhat"
  25. echo ""
  26. echo "What you see, is what you get!"
  27. echo ""
  28. # {{{ updater
  29. NZSHRC="https://docu.blackdot.be/getRaw.php?onlyCode=true&id=configuration:zsh"
  30. CHECK_UPDATE=1
  31. AUTO_UPDATE=1
  32. # }}}
  33.  
  34. # {{{ options
  35. ## change directory
  36. setopt auto_cd # drop cd
  37. setopt cd_able_vars # if var is valid dir, change to var
  38.  
  39. ## enable command correction
  40. #setopt correct
  41. setopt correct_all
  42.  
  43. # prevent file overwrite
  44. setopt no_clobber
  45.  
  46. ## pound sign in interactive prompt
  47. setopt interactive_comments
  48.  
  49. ## superglobs
  50. setopt extended_glob
  51. unsetopt case_glob
  52.  
  53. # expansions performed in prompt
  54. setopt prompt_subst
  55. setopt magic_equal_subst
  56.  
  57. # prompt about background jobs on exit
  58. setopt check_jobs
  59.  
  60. # notify on job complete
  61. setopt notify
  62. # }}}
  63.  
  64. # {{{ variables
  65. # preferences
  66. export EDITOR='nano'
  67. export PAGER='less'
  68. # }}}
  69.  
  70. # {{{ aliasses
  71. # include external aliasses
  72. [ -f ~/.aliasses ] && source ~/.aliasses
  73.  
  74. # nano wrapping
  75. alias nano='nano -w'
  76. alias pyedit='nano -ET2 -w'
  77.  
  78. # default for ls
  79. alias ll='ls -l'
  80. alias lr='ls -R'
  81. # }}}
  82.  
  83. # {{{ advanced
  84. ## fix url quote's
  85. if [[ ${ZSH_VERSION//\./} -ge 420 ]] ; then
  86. autoload -U url-quote-magic
  87. zle -N self-insert url-quote-magic
  88. fi
  89.  
  90. ## os specific
  91. case $OSTYPE in linux*)
  92. # colorization
  93. [ -f /etc/DIR_COLORS ] && eval $(dircolors -b /etc/DIR_COLORS)
  94. [ -f ~/.dir_colors ] && eval $(dircolors -b ~/.dir_colors)
  95.  
  96. if [ -n "${LS_COLORS}" ]; then
  97. export ZLSCOLORS="${LS_COLORS}"
  98. alias ls='ls --color=auto'
  99. alias grep='grep --color=auto'
  100. fi
  101. ;; esac
  102. case $OSTYPE in solaris*)
  103. # detect root or staff
  104. [ $UID -eq 0 ] && WANT_SBIN=1
  105. [ `groups | grep -c staff` -gt 0 ] && WANT_SBIN=1
  106. [ -n $WANT_SBIN ] && export PATH=/usr/sbin:$PATH
  107.  
  108. # check for omni repository
  109. [ -d /opt/omni/bin ] && export PATH=/opt/omni/bin:$PATH
  110. [ -d /opt/omni/sbin ] && [ -n $WANT_SBIN ] && export PATH=/opt/omni/sbin:$PATH
  111. [ -d /opt/omni/share/man ] && export MANPATH=/opt/omni/share/man:$MANPATH
  112.  
  113. # check for obd repository
  114. [ -d /opt/obd/bin ] && export PATH=/opt/obd/bin:$PATH
  115. [ -d /opt/obd/sbin ] && [ -n $WANT_SBIN ] && export PATH=/opt/obd/sbin:$PATH
  116. [ -d /opt/obd/share/man ] && export MANPATH=$MANPATH:/opt/obd/share/man
  117.  
  118. # check for sfw
  119. [ -d /usr/sfw/bin ] && export PATH=/usr/sfw/bin:$PATH
  120.  
  121. # check for gnu
  122. [ -d /usr/gnu/bin ] && export PATH=/usr/gnu/bin:$PATH
  123.  
  124. # check for local
  125. [ -d /usr/local/bin ] && export PATH=/usr/local/bin:$PATH
  126. [ -d /usr/local/sbin ] && [ -n $WANT_SBIN ] && export PATH=/usr/local/sbin:$PATH
  127.  
  128. # check for opencsw
  129. if [ -d /opt/csw/bin ]; then
  130. [ $UID = 0 ] && export PATH=/opt/csw/sbin:$PATH
  131. export PATH=/opt/csw/gnu:/opt/csw/bin:$PATH
  132. fi
  133.  
  134. # colorization
  135. alias ls='ls --color=auto'
  136. if [ "`which grep`" = "/usr/gnu/bin/grep" ]; then
  137. alias grep='grep --color=auto'
  138. fi
  139. ;; esac
  140. case $OSTYPE in darwin*)
  141. # colorization
  142. export CLICOLOR=1
  143. alias ls='ls -G'
  144.  
  145. # macports (with gnu)
  146. if [ -e /opt/local/bin/port ]; then
  147. export PATH=/opt/local/libexec/gnubin:/opt/local/bin:/opt/local/sbin:$PATH
  148. export MANPATH=/opt/local/share/man:$MANPATH
  149. if [ -f ~/.dir_colors ]; then
  150. eval $(dircolors -b ~/.dir_colors)
  151. export ZLSCOLORS="${LS_COLORS}"
  152. unalias ls &> /dev/null
  153. alias ls='ls --color=auto'
  154. fi
  155. if [ -e /opt/local/bin/python2 ]; then
  156. alias python='/opt/local/bin/python2'
  157. fi
  158. fi
  159. ;; esac
  160. # zsh shortcuts
  161. case $OSTYPE in linux*|darwin*)
  162. alias zshenable='chsh -s $(which zsh)'
  163. alias zshdisable='chsh -s $(which bash)'
  164. ;; esac
  165. case $OSTYPE in solaris*)
  166. alias zshenable='sudo usermod -s $(which zsh) ${USER}'
  167. alias zshdisable='sudo usermod -s $(which bash) ${USER}'
  168. ;; esac
  169.  
  170. ## host specific
  171. case ${HOST:r} in
  172. (Axion|Axino)
  173. # add a little info banner
  174. if [[ $SHLVL -eq 1 ]] ; then
  175. clear
  176. echo
  177. print -P "\e[1;33m Welcome to: \e[1;34m%m"
  178. print -P "\e[1;33m Running: \e[1;34m`uname -srm`\e[1;33m on \e[1;34m%l"
  179. print -P "\e[1;33m It is:\e[1;34m %D{%r} \e[1;33m on \e[1;34m%D{%A %b %f %G}"
  180. echo
  181. tput sgr0
  182. fi
  183.  
  184. # proper UTF-8
  185. export LANG=en_US.UTF-8
  186.  
  187. # host color
  188. PROMPT_HOST_COLOR=magenta
  189. ;;
  190. (yami)
  191. # host color
  192. PROMPT_HOST_COLOR=green
  193. ;;
  194. *)
  195. # default host color
  196. PROMPT_HOST_COLOR=blue
  197. ;;
  198. esac
  199.  
  200. ## local configuration
  201. [[ -e ~/.zprofile ]] && source ~/.zprofile
  202. # }}}
  203.  
  204. # {{{ prompt
  205. # enable colors module
  206. autoload -U colors && colors
  207.  
  208. # utf8 checkmarks
  209. PROMPT_CO='.'
  210. PROMPT_CE='!'
  211. case $LANG in *UTF-8)
  212. case $TERM in (xterm*)
  213. if [ ! -f ~/.znofancy ]; then
  214. PROMPT_CO='✓'
  215. PROMPT_CE='✗'
  216. fi
  217. ;; esac
  218. ;; esac
  219.  
  220. THEME=minimal
  221. case $THEME in
  222. gentoo)
  223. PROMPT='%(!.%{$fg_bold[red]%}.%{$fg_bold[green]%}%n@)%m %{$fg_bold[blue]%}%(!.%1~.%~) %#%{$reset_color%} '
  224. ;;
  225. gentoo-server)
  226. PROMPT='%(!.%{$fg_bold[red]%}.%{$fg_bold[yellow]%}%n@)%m %{$fg_bold[blue]%}%(!.%1~.%~) %#%{$reset_color%} '
  227. ;;
  228. minimal)
  229. PROMPT=$'%{$fg_bold[grey]%}-(%{$reset_color%}%{$fg_bold[white]%}%1~%{$reset_color%}%{$fg_bold[grey]%})-[%{$reset_color%}%(?,%{$fg_bold[green]%}$PROMPT_CO%{$reset_color%},%{$fg_bold[red]%}$PROMPT_CE%{$reset_color%})%{$fg_bold[grey]%}]-%{$reset_color%}%(!.%{$fg_bold[red]%}.%{$fg_bold[yellow]%}){%{$reset_color%} '
  230. RPROMPT=$'%(!.%{$fg_bold[red]%}.%{$fg_bold[yellow]%})}%{$reset_color%}%{$fg_bold[grey]%}-(%{$reset_color%}%{$fg_bold[$PROMPT_HOST_COLOR]%}%n@%m%{$reset_color%}%{$fg_bold[grey]%})-%{$reset_color%}'
  231. ;;
  232. *)
  233. PROMPT=$'%{$fg_bold[grey]%}[%{$fg_bold[yellow]%}%m %{$fg_bold[grey]%}:: %(!.%{$fg_bold[red]%}.%{$fg_bold[green]%})%n%{$fg_bold[grey]%}][%{$fg_bold[blue]%}%~%{$fg_bold[grey]%}]\n[%{$fg[white]%}%D{%H:%M:%S} %{$fg_bold[grey]%}- %(?,%{$fg_bold[green]%}✓%{$reset_color%},%{$fg_bold[red]%}✗%{$reset_color%})%{$fg_bold[grey]%}]%(!.%{$fg_bold[red]%}#.%{$fg_bold[green]%}$)%{$reset_color%} '
  234. ;;
  235. esac
  236. unset THEME
  237. # }}}
  238.  
  239. # {{{ history
  240. # history file
  241. HISTFILE=~/.zhistory
  242. HISTSIZE=10000
  243. SAVEHIST=10000
  244.  
  245. # share history file
  246. setopt share_history
  247. setopt inc_append_history
  248.  
  249. # ignore duplicates
  250. setopt hist_ignore_all_dups
  251.  
  252. # ignore entries starting with a space
  253. setopt hist_ignore_space
  254. # }}}
  255.  
  256. # {{{ keybindings
  257. # generic
  258. bindkey "\e[1~" beginning-of-line # Home
  259. bindkey "\e[4~" end-of-line # End
  260. bindkey "\e[5~" beginning-of-history # PageUp
  261. bindkey "\e[6~" end-of-history # PageDown
  262. bindkey "\e[2~" quoted-insert # Ins
  263. bindkey "\e[3~" delete-char # Del
  264. bindkey "\e[5C" forward-word
  265. bindkey "\eOc" emacs-forward-word
  266. bindkey "\e[5D" backward-word
  267. bindkey "\eOd" emacs-backward-word
  268. bindkey "\e\e[C" forward-word
  269. bindkey "\e\e[D" backward-word
  270. bindkey "\e[Z" reverse-menu-complete # Shift+Tab
  271. bindkey ' ' magic-space # becasue I am lazy
  272.  
  273. # for rxvt
  274. bindkey "\e[7~" beginning-of-line # Home
  275. bindkey "\e[8~" end-of-line # End
  276.  
  277. # for non RH/Debian xterm, can't hurt for RH/Debian xterm
  278. bindkey "\eOH" beginning-of-line
  279. bindkey "\eOF" end-of-line
  280.  
  281. # for freebsd/darwin console
  282. bindkey "\e[H" beginning-of-line
  283. bindkey "\e[F" end-of-line
  284. # }}}
  285.  
  286. # {{{ auto completion
  287. ## base
  288. autoload -U compinit && compinit
  289.  
  290. ## complete from withing word
  291. setopt complete_in_word
  292.  
  293. ## complete aliases
  294. setopt complete_aliases
  295.  
  296. ## pretty menu's
  297. zstyle ':completion:*' menu select=1
  298. zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
  299. setopt auto_menu # show menu on 2nd <tab>
  300. setopt list_rows_first # use row list if possible
  301.  
  302. ## Ignore completions for commands that we dont have
  303. zstyle ':completion:*:functions' ignored-patterns '_*'
  304.  
  305. ## enable case-insensitive completion
  306. zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
  307.  
  308. ## enable caching
  309. zstyle ':completion::complete:*' use-cache on
  310. zstyle ':completion::complete:*' cache-path ~/.zcache
  311.  
  312. ## Prevent re-suggestion
  313. zstyle ':completion:*:rm:*' ignore-line yes
  314. zstyle ':completion:*:scp:*' ignore-line yes
  315. zstyle ':completion:*:ls:*' ignore-line yes
  316.  
  317. ## enable killall menu
  318. zstyle ':completion:*:processes-names' command 'ps -u $(whoami) -o comm='
  319. zstyle ':completion:*:processes-names' menu yes select
  320. zstyle ':completion:*:processes-names' force-list always
  321.  
  322. ## enable kill menu
  323. zstyle ':completion:*:kill:*' command 'ps -u $(whoami) -o pid,pcpu,pmem,cmd'
  324. zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;32'
  325. zstyle ':completion:*:*:kill:*' menu yes select
  326. zstyle ':completion:*:kill:*' force-list always
  327. zstyle ':completion:*:kill:*' insert-ids single
  328.  
  329. ## enable make completion
  330. compile=(all clean compile disclean install remove uninstall)
  331. compctl -k compile make
  332.  
  333. ## ssh host completion
  334. if [ ! -f ~/.ssh/config ]; then
  335. [ -f ~/.ssh/known_hosts ] && rm ~/.ssh/known_hosts
  336. mkdir -p ~/.ssh
  337. echo "HashKnownHosts no" >>! ~/.ssh/config
  338. chmod 0600 ~/.ssh/config
  339. fi
  340. zstyle -e ':completion::*:ssh:*:hosts' hosts 'reply=(${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) /dev/null)"}%%[# ]*}//,/ })'
  341. zstyle ':completion:*:ssh:*' group-order hosts-domain hosts-host users hosts-ipaddr
  342.  
  343. ## ssh user completion cleanup
  344. zstyle ':completion:*:ssh:*:users' ignored-patterns \
  345. adm alias apache at bin cron cyrus daemon distcache exim ftp games gdm \
  346. guest gopher haldaemon halt mail man messagebus mysql named news nobody nut \
  347. nfsnobody lp operator portage postfix postgres postmaster qmaild qmaill qmailp \
  348. qmailq qmailr qmails rpmbuild rpc rpcuser shutdown smmsp squid sshd sync saslauth \
  349. uucp vcsa vpopmail xfs
  350. # }}}
  351.  
  352. # {{{ functions
  353. # update .zshrc
  354. zshupdate() {
  355. # main
  356. if [ -z "`which curl`" ]; then
  357. echo 'Please install curl!'
  358. exit
  359. fi
  360. NV=`curl -sk ${NZSHRC} | head -n3 | tail -n1 | awk '{ print $3 }'`
  361. OV=`cat ~/.zshrc | head -n3 | tail -n1 | awk '{ print $3 }'`
  362. [ -z "${NV}" ] && NV=0
  363.  
  364. if [ ${NV} -gt ${OV} ]; then
  365. echo -n "[>>] Updating from ${OV} to ${NV} ...\r"
  366. mv ~/.zshrc ~/.zshrc.old
  367. curl -sk ${NZSHRC} -o ~/.zshrc
  368. source ~/.zshrc
  369. echo '[OK]'
  370. else
  371. echo "[OK] No update needed."
  372. fi
  373. }
  374.  
  375. # auto update check
  376. if [ ${CHECK_UPDATE} -gt 0 ]; then
  377. if [ `find ~/.zshrc -mmin +1440` ]; then
  378. touch ~/.zshrc
  379. NV=`curl -sk -m 3 ${NZSHRC} | head -n3 | tail -n1 | awk '{ print $3 }'`
  380. OV=`cat ~/.zshrc | head -n3 | tail -n1 | awk '{ print $3 }'`
  381. [ -z "${NV}" ] && NV=0
  382.  
  383. if [ ${NV} -gt ${OV} ]; then
  384. if [ ${CHECK_UPDATE} -gt 0 ]; then
  385. zshupdate
  386. else
  387. echo "Please run zshupdate to update .zshrc to version ${NV}!"
  388. fi
  389. fi
  390. fi
  391. fi
  392.  
  393. # remove ssh known_hosts key
  394. delete_sshhost() {
  395. if [[ -z "$1" ]] ; then
  396. echo "usage: \e[1;36mdelete_sshhost \e[1;0m< host >"
  397. echo " Removes the specified host from ssh known host list"
  398. else
  399. sed -i -e "/$1/d" $HOME/.ssh/known_hosts
  400. fi
  401. }
  402. # }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement