BSDG33KCLUB

very cool zsh prompt script :)

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