25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

167 lines
4.5 KiB

  1. #-*-mode: Shell-script; coding: utf-8;-*-
  2. # zsh specific global aliases
  3. alias -g silent="> /dev/null 2>&1"
  4. alias -g noerr="2> /dev/null"
  5. alias -g stdboth="2>&1"
  6. # mainly for firefox, because it can suck up the cycles, but not when
  7. # in a SIGSTOP state you can't use any power then firefox.
  8. alias -g sigcont='kill -CONT '
  9. alias -g sigstop='kill -STOP '
  10. # Keybindings, what few there are.
  11. bindkey -v
  12. bindkey '^P' push-line # Saves the current line and returns to it afterwards.
  13. # General history options
  14. export HISTSIZE=5000
  15. export SAVEHIST=${HISTSIZE}
  16. export HISTFILE=~/.zsh_history
  17. # I like my options
  18. setopt append_history
  19. setopt extended_history
  20. setopt hist_reduce_blanks
  21. setopt hist_no_store
  22. setopt hist_ignore_dups
  23. setopt histignorespace
  24. setopt no_hist_beep
  25. setopt no_list_beep
  26. setopt share_history
  27. setopt inc_append_history
  28. setopt auto_menu
  29. setopt bash_auto_list
  30. # Options that don't need to be set.
  31. unsetopt bad_pattern # No, don't warn me on bad file patterns kthxbai.
  32. # The rest of the story (tm) (c) (r) in option settings.
  33. setopt equals
  34. setopt notify
  35. setopt auto_cd
  36. setopt glob_dots
  37. setopt print_exit_value # I love you zsh for this, print out non zero exits.
  38. other_term()
  39. {
  40. case $TERM in
  41. *xterm*|*rxvt*|(dt|k|e)term)
  42. print -Pn "\e]2;%~\a"
  43. ;;
  44. sun-cmd)
  45. print -Pn "\e]l%~\e\\"
  46. ;;
  47. *)
  48. ;;
  49. esac
  50. }
  51. chpwd()
  52. {
  53. [[ -o interactive ]] || return
  54. case $TERM in
  55. eterm-color) # getting emacs terminal to not be annoying... sucks
  56. print -Pn ""
  57. ;;
  58. *)
  59. if [[ $SSH_TTY != '' ]]; then
  60. case $ORIG_TERM in
  61. eterm-color)
  62. print -Pn ""
  63. ;;
  64. *)
  65. other_term
  66. ;;
  67. esac
  68. fi
  69. ;;
  70. esac
  71. }
  72. # Needs to be reviewed a bit.
  73. zstyle ':completion:*' squeeze-slashes true
  74. zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
  75. zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
  76. zstyle ':completion:*:*:*:*:processes' force-list always
  77. # No need to setup ssh known host parsing as root, just regular users.
  78. # This is pretty old using compctl, need to update eventually.
  79. if [[ "$LOGNAME" != "root" ]]; then
  80. zmodload zsh/mathfunc
  81. if [[ -f "$HOME/.ssh/known_hosts" ]]; then
  82. hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*})
  83. zstyle ':completion:*:(ssh|scp|cssh):*' hosts $hosts
  84. zstyle ':completion:*:*:*:hosts-host' ignored-patterns '|1|*' loopback localhost
  85. fi
  86. zstyle ':completion:::complete*' use-cache 1
  87. # This really should be closer to the definition of extract.
  88. compctl -g '*.tar.bz2 *.tbz2 *.tbz *.tar.gz *.tgz *.bz2 *.gz *.jar *.zip *.rar *.tar *.Z *.tZ *.tar.Z' + -g '*(-/)' extract
  89. fi
  90. # More history options for newer zsh versions
  91. setopt share_history
  92. setopt hist_save_no_dups
  93. setopt hist_find_no_dups
  94. setopt hist_no_functions
  95. setopt hist_expire_dups_first
  96. bindkey ' ' magic-space # Complete spaces too dammit, i'm lazy.
  97. alias edirs='ls -d **/*(/^F)' # empty directories
  98. zstyle ':completion:*:*:kill:*' menu yes select
  99. zstyle ':completion:*:kill:*' force-list always
  100. zstyle ':completion:*:kill:*:processes' command "ps x"
  101. zstyle ':completion:*' menu select=2
  102. autoload -U compinit
  103. autoload -U colors && colors
  104. autoload -Uz vcs_info
  105. bindkey -e
  106. local userat="%{$fg[blue]%}%n%(!.%{$fg[red]%}.%{$fg[blue]%})%{$reset_color%}%B@%b%{$fg[blue]%}%m%b"
  107. local pwd="%B%~%b"
  108. local userchar="%(!.#.$)"
  109. zstyle ':vcs_info:*' enable git
  110. zstyle ':vcs_info:*' check-for-changes true
  111. setopt prompt_subst
  112. precmd()
  113. {
  114. vcs_info
  115. }
  116. # +N/-N upstream info
  117. function +vi-git-st() {
  118. local ahead behind
  119. local -a gitstatus
  120. ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l | sed -e 's|^ *||g')
  121. behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l | sed -e 's|^ *||g')
  122. (( $ahead )) && gitstatus+=( "+${ahead}" )
  123. (( $behind )) && gitstatus+=( "-${behind}" )
  124. hook_com[misc]+=${(j:/:)gitstatus}
  125. }
  126. # Untracked crap in the repo not covered by .gitignore?
  127. function +vi-git-untracked(){
  128. if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \
  129. git status --porcelain | grep '??' &> /dev/null ; then
  130. hook_com[staged]+="%{$fg[red]%}N"
  131. fi
  132. }
  133. local branch="%{$fg[green]%}%b%c%u%{$fg[green]%}%{$reset_color%}"
  134. zstyle ':vcs_info:*' formats "%m $branch"
  135. zstyle ':vcs_info:*' actionformats "%a $branch"
  136. zstyle ':vcs_info:*' stagedstr "%{$fg[blue]%}S"
  137. zstyle ':vcs_info:*' unstagedstr "%{$fg[blue]%}M"
  138. zstyle ':vcs_info:git*+set-message:*' hooks git-untracked git-st
  139. PROMPT="%(!.#.$) " # $ as a user # as root
  140. RPROMPT='${vcs_info_msg_0_} ${PWD/#$HOME/~}'