BSDG33KCLUB

very cool zsh prompt script

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