You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

679 lines
21KB

  1. # vim: ft=zsh
  2. #
  3. # Download Patched fonts from
  4. # https://github.com/gabrielelana/awesome-terminal-fonts/tree/patching-strategy/patched
  5. #
  6. #---------------------------------- Pre Setup ---------------------------------
  7. # Source this file in your .zshrc:
  8. # source $HOME/.zsh/zshrc
  9. autoload colors; colors
  10. autoload -Uz add-zsh-hook
  11. LAST_RETURN_VALUE=0
  12. # Characters
  13. if [[ -n $(echo '\u2603' 2>/dev/null) ]] then
  14. MULTIBYTE_SUPPORTED="\u2603"
  15. fi
  16. if [[ -n $MULTIBYTE_SUPPORTED ]] then
  17. UNSTAGED_CHARACTER="\ue168"
  18. CHANGES_CHARACTER="\ue16b"
  19. UNTRACKED_CHARACTER="\ue16c"
  20. BRANCH_CHARACTER="\ue822"
  21. DETACHED_CHARACTER="\ue899"
  22. REVISION_CHARACTER="\ue821"
  23. FAILED_CHARACTER="\ue125"
  24. SUCCESS_CHARACTER="\ue124"
  25. SUPERUSER_CHARACTER="\ue22b"
  26. JOBS_CHARACTER="\ue12a"
  27. NO_JOBS_CHARACTER="\u2022"
  28. AHEAD_CHARACTER="\ue174 "
  29. BEHIND_CHARACTER="\ue175 "
  30. ACTIONS_CHARACTER="\ue831"
  31. SEGMENT_SEPARATOR_FORWARD="\ue0b0"
  32. SEGMENT_SEPARATOR_BACKWARD="\ue0b2"
  33. else
  34. UNSTAGED_CHARACTER="!"
  35. CHANGES_CHARACTER="*"
  36. UNTRACKED_CHARACTER="?"
  37. BRANCH_CHARACTER="~"
  38. DETACHED_CHARACTER="%"
  39. REVISION_CHARACTER="r"
  40. FAILED_CHARACTER="X"
  41. SUCCESS_CHARACTER="V"
  42. SUPERUSER_CHARACTER="#"
  43. JOBS_CHARACTER="O"
  44. NO_JOBS_CHARACTER="."
  45. AHEAD_CHARACTER="+"
  46. BEHIND_CHARACTER="-"
  47. ACTIONS_CHARACTER="!"
  48. SEGMENT_SEPARATOR_FORWARD=""
  49. SEGMENT_SEPARATOR_BACKWARD=""
  50. fi
  51. #---------------------------------- Helpers -----------------------------------
  52. # Search file up in directory tree. Either print path to found file or nothing
  53. find_up () {
  54. path=$(pwd)
  55. while [[ "$path" != "" ]]; do
  56. if [[ -e "$path/$1" ]]; then
  57. echo "$path/$1"
  58. return;
  59. fi
  60. path=${path%/*}
  61. done
  62. }
  63. command-exists () {
  64. return $(command -v $1 >/dev/null);
  65. }
  66. NEWLINE=$'\n'
  67. #---------------------------------- Listings ----------------------------------
  68. if command-exists dircolors; then
  69. eval "$(dircolors -b)"
  70. fi
  71. if command-exists exa; then
  72. alias ls='exa --git --long --all --extended --time-style long-iso'
  73. else
  74. LSOPTS="-lAvF --color=auto" # long mode, show all, natural sort, type squiggles, friendly sizes
  75. alias ls="ls $LSOPTS"
  76. fi;
  77. #---------------------------------- Tab completion ----------------------------
  78. # Force a reload of completion system if nothing matched; this fixes installing
  79. # a program and then trying to tab-complete its name
  80. _force_rehash() {
  81. (( CURRENT == 1 )) && rehash
  82. return 1 # Because we didn't really complete anything
  83. }
  84. # Always use menu completion, and make the colors pretty!
  85. zstyle ':completion:*' menu select yes
  86. zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
  87. # Completers to use: rehash, general completion, then various magic stuff and
  88. # spell-checking. Only allow two errors when correcting
  89. zstyle ':completion:*' completer _force_rehash _complete _ignored _match _correct _approximate _prefix
  90. zstyle ':completion:*' max-errors 2
  91. # When looking for matches, first try exact matches, then case-insensiive, then partial word completion
  92. zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'r:|[._-]=** r:|=**'
  93. # Turn on caching, which helps with e.g. apt
  94. zstyle ':completion:*' use-cache on
  95. zstyle ':completion:*' cache-path "$HOME/.zsh/cache"
  96. mkdir -p $HOME/.zsh/cache
  97. # Show nice warning when nothing matched
  98. zstyle ':completion:*:warnings' format '%No matches: %d%b'
  99. # Show titles for completion types and group by type
  100. zstyle ':completion:*:descriptions' format "%U%B%F{yellow}ยป %d%u%b%f"
  101. zstyle ':completion:*' group-name ''
  102. # Ignore some common useless files
  103. zstyle ':completion:*' ignored-patterns '*?.pyc' '__pycache__'
  104. zstyle ':completion:*:*:rm:*:*' ignored-patterns
  105. # Directories
  106. zstyle ':completion:*:default' list-colors "${(s.:.)LS_COLORS}"
  107. zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories
  108. zstyle ':completion:*:*:cd:*:directory-stack' menu yes select
  109. zstyle ':completion:*:-tilde-:*' group-order 'named-directories' 'path-directories' 'users' 'expand'
  110. zstyle ':completion:*' squeeze-slashes true
  111. # kill: advanced kill completion
  112. zstyle ':completion::*:kill:*:*' command 'ps xf -U $USER -o pid,%cpu,cmd'
  113. zstyle ':completion::*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;32'
  114. # sudo completion
  115. zstyle ':completion:*:sudo:*' command-path append /sbin /usr/sbin
  116. SSH_HOSTS=($([[ -f $HOME/.ssh/config ]] && print -n $(cat $HOME/.ssh/config | sed '/^Host [^*]/!d;s/Host *\([^ \#]\+\)/\1/' | sort)))
  117. zstyle ':completion:*:ssh:*' hosts $SSH_HOSTS
  118. zstyle ':completion:*:scp:*' hosts $SSH_HOSTS
  119. zstyle ':completion:*:ssh:*' users # disables users completion
  120. zstyle ':completion:*:scp:*' users # disables users completion
  121. # maven completions (from zsh-users/zsh-completions)
  122. zstyle ':completion:*:*:mvn:*:matches' group 'yes'
  123. zstyle ':completion:*:*:mvn:*:options' description 'yes'
  124. zstyle ':completion:*:*:mvn:*:options' auto-description '%d'
  125. # Always do mid-word tab completion
  126. setopt complete_in_word
  127. # don't expand aliases _before_ completion has finished
  128. setopt complete_aliases
  129. #---------------------------------- Corrections -------------------------------
  130. # dont correct arguments to dot-files
  131. CORRECT_IGNORE='[._]*'
  132. CORRECT_IGNORE_FILE='[._]*'
  133. #---------------------------------- Prediction --------------------------------
  134. autoload predict-on
  135. autoload predict-off
  136. zle -N predict-on
  137. zle -N predict-off
  138. bindkey "^Z" predict-on # C-z
  139. bindkey "^X^Z" predict-off # C-x C-z
  140. #---------------------------------- History -----------------------------------
  141. setopt append_history # Allow multiple terminal sessions to all append to one zsh command history
  142. setopt extended_history # save timestamp of command and duration
  143. setopt inc_append_history # Add comamnds as they are typed, don't wait until shell exit
  144. setopt hist_expire_dups_first # when trimming history, lose oldest duplicates first
  145. setopt hist_ignore_dups # Do not write events to history that are duplicates of previous events
  146. setopt hist_ignore_space # remove command line from history list when first character on the line is a space
  147. setopt hist_find_no_dups # When searching history don't display results already cycled through twice
  148. setopt hist_reduce_blanks # Remove extra blanks from each command line being added to history
  149. setopt hist_verify # don't execute, just expand history
  150. setopt share_history # imports new commands and appends typed commands to history
  151. setopt hist_no_store # remove the history (fc -l) command from the history when invoked.
  152. export HISTFILE=~/.zsh_history
  153. export HISTSIZE=1000000
  154. export SAVEHIST=1000000
  155. #---------------------------------- Prompt ------------------------------------
  156. # Based on agnoster's Theme - https://gist.github.com/3712874
  157. CURRENT_BG='NONE'
  158. prompt_segment() {
  159. local direction newbg newfg text
  160. direction="$1"
  161. newbg="$2"
  162. newfg="$3"
  163. text="$4"
  164. if [[ -z $text ]]; then return; fi
  165. if [[ $newbg != $CURRENT_BG ]]; then
  166. if [[ "$direction" == 'forward' ]]; then
  167. if [[ $CURRENT_BG != 'NONE' ]]; then
  168. print -n "%{%K{$newbg}%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR_FORWARD%{%F{$newfg}%}"
  169. else
  170. print -n "%{%K{$newbg}%F{$newfg}%}"
  171. fi
  172. else
  173. print -n "%{%F{$newbg}%}$SEGMENT_SEPARATOR_BACKWARD%{%F{$newfg}%K{$newbg}%}"
  174. fi
  175. fi
  176. print -n " $text "
  177. CURRENT_BG=$newbg
  178. }
  179. # End the prompt, closing any open segments
  180. prompt_end() {
  181. if [[ -n $CURRENT_BG ]]; then
  182. print -n "%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR_FORWARD"
  183. fi
  184. CURRENT_BG=''
  185. }
  186. prompt_clear() {
  187. print -n "%{%k%f%}"
  188. CURRENT_BG=''
  189. }
  190. ### Prompt components
  191. # Each component will draw itself, and hide itself if no information needs to be shown
  192. # Root privileges
  193. prompt_root() {
  194. if [[ $UID -eq 0 ]]; then
  195. print -n $SUPERUSER_CHARACTER
  196. fi
  197. }
  198. # Different username
  199. prompt_user() {
  200. local user=$USER
  201. if command-exists whoami && [[ -z $user ]] then
  202. user=$(whoami)
  203. fi
  204. if [[ "$user" != "$DEFAULT_USER" && $UID -ne 0 ]]; then
  205. print -n $user
  206. fi
  207. }
  208. # Different host
  209. prompt_host() {
  210. if [[ -n "$SSH_CONNECTION" ]]; then
  211. print -n "%m"
  212. fi
  213. }
  214. # Makefile exists
  215. prompt_makefile() {
  216. if [[ -f Makefile ]]; then
  217. print -n "make"
  218. fi
  219. }
  220. # Status:
  221. # - was there an error
  222. # - are there background jobs?
  223. prompt_status() {
  224. local symbols
  225. symbols=()
  226. if [[ $LAST_RETURN_VALUE -ne 0 ]]; then
  227. symbols+="%{%F{red}%}$FAILED_CHARACTER%{%f%}"
  228. else
  229. symbols+="%{%F{green}%}$SUCCESS_CHARACTER%{%f%}"
  230. fi
  231. if [[ $(jobs -l) ]]; then
  232. symbols+="%{%F{cyan}%}$JOBS_CHARACTER%{%f%}"
  233. else
  234. symbols+="%{%F{white}%}$NO_JOBS_CHARACTER%{%f%}"
  235. fi
  236. echo "$symbols"
  237. }
  238. ## Main prompt
  239. prompt_forward() {
  240. CURRENT_BG='NONE'
  241. prompt_segment forward black default "$(prompt_status)"
  242. prompt_segment forward red yellow "$(prompt_root)"
  243. prompt_segment forward magenta black "$(prompt_user)"
  244. prompt_segment forward cyan black "$(prompt_host)"
  245. prompt_segment forward blue black '%~' # prompt directory
  246. prompt_end
  247. prompt_clear
  248. }
  249. ## Reverse prompt
  250. prompt_backward() {
  251. CURRENT_BG='NONE'
  252. prompt_segment backward magenta black "$MAVEN_PROJECT" # prompt maven project
  253. prompt_segment backward cyan black "$PACKAGE_JSON_PROJECT" # prompt package.json project
  254. prompt_segment backward cyan black "$(prompt_makefile)"
  255. prompt_segment backward yellow black "$vcs_info_msg_0_" # prompt vcs
  256. prompt_segment backward green black "%T" # prompt time
  257. prompt_clear
  258. }
  259. prompt2_forward() {
  260. CURRENT_BG='NONE'
  261. prompt_segment forward black default "$(prompt_status)"
  262. prompt_segment forward red yellow "$(prompt_root)"
  263. prompt_segment forward magenta black "$(prompt_user)"
  264. prompt_segment forward cyan black "$(prompt_host)"
  265. prompt_segment forward blue black '%~' # prompt directory
  266. prompt_segment forward red black '%_' # unmatched quote
  267. prompt_end
  268. prompt_clear
  269. }
  270. prompt_precmd() {
  271. vcs_info
  272. PROMPT="%{%f%b%k%}$(prompt_forward) "
  273. PS="$PROMPT"
  274. PS2="%{%f%b%k%}$(prompt2_forward) "
  275. RPROMPT="%{%f%b%k%}$(prompt_backward)"
  276. PRS="$RPROMPT"
  277. SPROMPT="Correct %{%F{red}%}%R%{%f%} to %{%F{green}%}%r%f? [%Uy%ues|%Un%uo|%Ua%ubort|%Ue%udit] "
  278. }
  279. ZLE_RPROMPT_INDENT=1
  280. prompt_opts=(cr subst percent)
  281. add-zsh-hook precmd prompt_precmd
  282. #---------------------------------- VCS ---------------------------------------
  283. autoload -Uz vcs_info
  284. zstyle ':vcs_info:*' enable git hg svn
  285. zstyle ':vcs_info:*' check-for-changes true
  286. zstyle ':vcs_info:*' get-revision true
  287. # these formats are set for PROMPT
  288. zstyle ':vcs_info:*' formats "%s $BRANCH_CHARACTER%b $REVISION_CHARACTER%i%u"
  289. zstyle ':vcs_info:*' actionformats "%s $BRANCH_CHARACTER%b $REVISION_CHARACTER%i%u [%a]"
  290. zstyle ':vcs_info:*' branchformat '%b'
  291. zstyle ':vcs_info:hg*' unstagedstr "$CHANGES_CHARACTER"
  292. zstyle ':vcs_info:hg*' hgrevformat "%r" # default "%r:%h"
  293. zstyle ':vcs_info:git*' formats "$BRANCH_CHARACTER%b%u%c%m" # git is standard
  294. zstyle ':vcs_info:git*' actionformats "$BRANCH_CHARACTER%b%u%c%m $ACTIONS_CHARACTER%a"
  295. zstyle ':vcs_info:git*' unstagedstr " $UNSTAGED_CHARACTER"
  296. zstyle ':vcs_info:git*' stagedstr " $CHANGES_CHARACTER"
  297. zstyle ':vcs_info:git*+set-message:*' hooks git-additional
  298. function +vi-git-additional() {
  299. local ahead behind
  300. local -a branchstatus
  301. ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
  302. (( $ahead )) && branchstatus+=( " $AHEAD_CHARACTER${ahead}" )
  303. behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
  304. (( $behind )) && branchstatus+=( " $BEHIND_CHARACTER${behind}" )
  305. hook_com[misc]="${(j::)branchstatus}"
  306. if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' && \
  307. -n $(git status --porcelain | grep -E '^\?\?' 2> /dev/null | tail -n1) ]]; then
  308. hook_com[unstaged]+=" $UNTRACKED_CHARACTER"
  309. fi
  310. }
  311. #---------------------------------- Screen ------------------------------------
  312. function title {
  313. # param: title to use
  314. local prefix=''
  315. # If I'm in a screen, all the windows are probably on the same machine, so
  316. # I don't really need to title every single one with the machine name.
  317. # On the other hand, if I'm not logged in as me (but, e.g., root), I'd
  318. # certainly like to know that!
  319. if [[ $USER != "$DEFAULT_USER" ]]; then
  320. prefix="[$USER] "
  321. fi
  322. # Set screen window title
  323. if [[ $TERM == "screen"* ]]; then
  324. print -n "\ek$prefix$1\e\\"
  325. fi
  326. # Prefix the xterm title with the current machine name, but only if I'm not
  327. # on a local machine. This is tricky, because screen won't reliably know
  328. # whether I'm using SSH right now! So just assume I'm local iff I'm not
  329. # running over SSH *and* not using screen. Local screens are fairly rare.
  330. prefix=$HOST
  331. if [[ $SSH_CONNECTION == '' && $TERM != "screen"* ]]; then
  332. prefix=''
  333. fi
  334. # If we're showing host and not default user prepend it
  335. if [[ $prefix != '' && $USER != "$DEFAULT_USER" ]]; then
  336. prefix="$USER@$prefix"
  337. fi
  338. # Wrap it in brackets
  339. if [[ $prefix != '' ]]; then
  340. prefix="[$prefix] "
  341. fi
  342. # Set xterm window title
  343. if [[ $TERM == "xterm"* || $TERM == "screen"* ]]; then
  344. print -n "\e]2;$prefix$1\a"
  345. fi
  346. }
  347. function title_precmd {
  348. # Shorten homedir back to '~'
  349. local shortpwd=${PWD/$HOME/\~}
  350. title "zsh $shortpwd"
  351. }
  352. function title_preexec {
  353. title $*
  354. }
  355. add-zsh-hook preexec title_preexec
  356. add-zsh-hook precmd title_precmd
  357. #---------------------------------- Bindings ----------------------------------
  358. bindkey -v
  359. # General movement
  360. # Taken from http://wiki.archlinux.org/index.php/Zsh and Ubuntu's inputrc
  361. bindkey "\e[1~" beginning-of-line
  362. bindkey "\e[4~" end-of-line
  363. bindkey "\e[5~" beginning-of-history
  364. bindkey "\e[6~" end-of-history
  365. bindkey "\e[3~" delete-char
  366. bindkey "\e[2~" quoted-insert
  367. bindkey "\e[1;5C" forward-word
  368. bindkey "\e[1;5D" backward-word
  369. bindkey "\e[5C" forward-word
  370. bindkey "\eOc" emacs-forward-word
  371. bindkey "\e[5D" backward-word
  372. bindkey "\eOd" emacs-backward-word
  373. bindkey "\e\e[C" forward-word
  374. bindkey "\e\e[D" backward-word
  375. bindkey ' ' magic-space # do history expansion on space
  376. # for non RH/Debian xterm, can't hurt for RH/Debian xterm
  377. bindkey "\eOH" beginning-of-line
  378. bindkey "\eOF" end-of-line
  379. # for freebsd console
  380. bindkey "\e[H" beginning-of-line
  381. bindkey "\e[F" end-of-line
  382. # Tab completion
  383. expand-or-complete-with-indicator() {
  384. print -Pn "%{%F{red}...%f%}"
  385. zle expand-or-complete
  386. zle redisplay
  387. }
  388. zle -N expand-or-complete-with-indicator
  389. bindkey "^I" expand-or-complete-with-indicator
  390. bindkey "^r" history-incremental-search-backward
  391. bindkey "\e[Z" reverse-menu-complete # shift-tab to reverse menu
  392. # Up/down arrow.
  393. # I want shared history for ^R, but I don't want another shell's activity to
  394. # mess with up/down. This does that.
  395. down-line-or-local-history() {
  396. zle set-local-history 1
  397. zle down-line-or-history
  398. zle set-local-history 0
  399. }
  400. zle -N down-line-or-local-history
  401. up-line-or-local-history() {
  402. zle set-local-history 1
  403. zle up-line-or-history
  404. zle set-local-history 0
  405. }
  406. zle -N up-line-or-local-history
  407. bindkey "\e[A" up-line-or-local-history
  408. bindkey "\e[B" down-line-or-local-history
  409. #---------------------------------- Aliases ----------------------------------
  410. # Use interactive sudo instead of su
  411. alias su="sudo -u root -i"
  412. # disable sudo correction for commands
  413. alias sudo="nocorrect sudo"
  414. # More powerful terminal reset
  415. # \e< - resets \e[?2l which puts terminal into VT52 mode
  416. # reset - normal terminal reset
  417. # stty sane - puts tty in sane state (like accepting input, no character translation etc.)
  418. # setterm -reset - puts reset terminal string, as identified by setterm
  419. # tput reset - puts terminal reset strings from terminfo
  420. # clear - simple clear terminal window
  421. # \033c - exactly "<ESC>c" which is VT100 code for resetting terminal
  422. alias reset='echo -e "\e<"; reset; stty sane; setterm -reset; tput reset; clear; echo -e "\033c"'
  423. # Shortcuts for clipboard manipulation
  424. alias xclip-in='xclip -selection c -in'
  425. alias xclip-out='xclip -selection c -out'
  426. # Standard bd usage
  427. alias bd=". bd -si"
  428. #---------------------------------- VIM pager --------------------------------
  429. vim_pager() {
  430. local source_file;
  431. if [ ! -t 1 ]; then
  432. echo "Cannot use vim pager with non-terminal output" 1>&2
  433. return 1
  434. fi
  435. if [ $# -gt 0 ]; then
  436. source_file="$@";
  437. elif [ ! -t 0 ]; then
  438. source_file="-";
  439. else
  440. echo "Input stream or file name missing" 1>&2
  441. return 2
  442. fi
  443. vim --cmd 'let no_plugin_maps = 1' -c 'runtime! macros/less.vim' $source_file
  444. }
  445. alias vless='vim_pager'
  446. #---------------------------------- Maven ------------------------------------
  447. # Read project information from current directory - needed for prompt
  448. maven_read_project() {
  449. local location parts
  450. location=$(find_up pom.xml)
  451. if [[ ! -r "$location" || -z $commands[xmllint] ]]; then
  452. MAVEN_PROJECT=""
  453. return 1;
  454. fi
  455. # executing xmllint takes some time, so this does it in single execution
  456. parts=($(echo "cat /*[local-name()='project']/*[local-name()='artifactId']/text()\n" \
  457. "cat /*[local-name()='project']/*[local-name()='version']/text()\n" \
  458. "cat /*[local-name()='project']/*[local-name()='parent']/*[local-name()='version']/text()\n" | \
  459. xmllint --shell $location 2>/dev/null | \
  460. sed '/^\/ >/d' | \
  461. sed '/^ -------/d'))
  462. if [[ "${#parts}" > 1 ]]; then
  463. MAVEN_PROJECT="${parts[1]}@${parts[2]}"
  464. else
  465. MAVEN_PROJECT="pom!"
  466. fi;
  467. }
  468. add-zsh-hook chpwd maven_read_project
  469. #---------------------------------- package.json ------------------------------------
  470. # Read project information from current directory - needed for prompt
  471. package_json_read_project() {
  472. local location parts
  473. location=$(find_up package.json)
  474. if [[ ! -r "$location" || -z $commands[jq] ]]; then
  475. PACKAGE_JSON_PROJECT=""
  476. return 1;
  477. fi
  478. PACKAGE_JSON_PROJECT=$(jq -r '.name + "@" + .version' $location)
  479. }
  480. add-zsh-hook chpwd package_json_read_project
  481. #---------------------------------- Copy zshrc remote -------------------------
  482. sshc() {
  483. local source target
  484. source=${ZDOTDIR:-$HOME}
  485. target="/tmp/.zdot-${RANDOM}"
  486. consolidate-config
  487. ssh -q -o "ControlPath=/tmp/.cm-%r@%h:%p" -o "ControlMaster=yes" -o "ControlPersist=yes" $1 'false'
  488. ssh -q -o "ControlPath=/tmp/.cm-%r@%h:%p" $1 "mkdir $target"
  489. scp -q -o "ControlPath=/tmp/.cm-%r@%h:%p" $source/.zshrc-consolidated $1:$target/.zshrc
  490. ssh -q -o "ControlPath=/tmp/.cm-%r@%h:%p" $1 -t "ZDOTDIR=$target exec zsh -l"
  491. ssh -q -o "ControlPath=/tmp/.cm-%r@%h:%p" $1 "rm -r $target"
  492. ssh -q -o "ControlPath=/tmp/.cm-%r@%h:%p" -O stop $1
  493. }
  494. consolidate-config() {
  495. local initial final
  496. initial=${ZDOTDIR:-$HOME}/.zshrc
  497. final=${ZDOTDIR:-$HOME}/.zshrc-consolidated
  498. cp $initial $final
  499. while true; do
  500. found=$(grep -oP '^source \K.*$' $final)
  501. if [[ -z $found ]]; then
  502. break;
  503. fi
  504. replaced=${(e)found}
  505. if [[ $replaced != /* ]]; then
  506. replaced=$(dirname $final)/$replaced
  507. fi
  508. sed -i "\#^source $found\$# r $replaced${NEWLINE}d" $final
  509. done
  510. }
  511. #---------------------------------- Miscellaneous ----------------------------
  512. setopt extended_glob
  513. setopt correct # try to correct the spelling of commands.
  514. setopt correct_all # try to correct the spelling of all arguments in a line.
  515. setopt numeric_glob_sort # if numeric filenames are matched by a filename generation pattern, sort the filenames numerically rather than lexicographically.
  516. setopt nomatch # if there is match on file pattern, dont run command (instead of running command with unchanged parameters)
  517. setopt interactive_comments # allow comments in command line
  518. setopt multios # enable multiple input/output redirections that work as expected
  519. unsetopt beep # (dont) beep on errors
  520. unsetopt notify # (dont) report the status of background jobs immediately, rather than waiting until just before printing a prompt.
  521. unsetopt auto_cd # (dont) enter the directory that was inputed as command
  522. unsetopt auto_remove_slash # (dont) remove last slash when next character is delimiter
  523. unsetopt csh_junkie_quotes # (dont) complain if a quoted expression runs off the end of a line; prevent quoted expressions from containing un-escaped newlines.
  524. # Don't count common path separators as word characters
  525. WORDCHARS=${WORDCHARS//[&.;\/]}
  526. # Report time if command takes too long
  527. REPORTTIME=5
  528. TIMEFMT=$(echo "$fg[green]${SEGMENT_SEPARATOR_BACKWARD}$bg[green]$fg[black] %*Es $fg[yellow]$SEGMENT_SEPARATOR_BACKWARD$bg[yellow]$fg[black] %P $reset_color")
  529. # Don't glob with commands that expects glob patterns
  530. for command in find wget git; \
  531. alias $command="noglob $command"
  532. # load zsh extended move
  533. autoload -Uz zmv
  534. #---------------------------------- Addons ------------------------------------
  535. if [[ -d ${ZDOTDIR:-$HOME}/.zsh/zsh-syntax-highlighting ]]; then
  536. source ${ZDOTDIR:-$HOME}/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
  537. fi
  538. #---------------------------------- Machine specific --------------------------
  539. if [[ -r $HOME/.zlocal ]]; then
  540. source $HOME/.zlocal
  541. fi
  542. #---------------------------------- Post Setup --------------------------------
  543. # at last initialize completion
  544. autoload -Uz compinit
  545. if [[ -n ${ZDOTDIR}/.zcompdump(#qN.mh+24) ]]; then
  546. compinit
  547. else
  548. compinit -C
  549. fi
  550. store_last_return_value() {
  551. LAST_RETURN_VALUE="$?"
  552. }
  553. # Store last return value into separate variable
  554. # This must be exactly first precmd function, because other precmd might modify $?
  555. precmd_functions=(store_last_return_value $precmd_functions)
  556. # If kubectl is present, load completions from it.
  557. # This must be done after compinit was called
  558. if [[ $commands[kubectl] ]]; then
  559. source <(kubectl completion zsh);
  560. fi