Dotfiles for different machines on different branches.
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.

144 lines
4.3 KiB

  1. # Disable ctrl-s and ctrl-q.
  2. stty -ixon
  3. setopt autocd autopushd \
  4. # Enable autosuggestions
  5. source ~/gitrepos/pc/zsh-autosuggestions/zsh-autosuggestions.zsh
  6. bindkey '^ ' autosuggest-accept
  7. # Enable colors and change prompt
  8. autoload -U colors && colors
  9. autoload -Uz vcs_info
  10. precmd_vcs_info() { vcs_info }
  11. precmd_functions+=( precmd_vcs_info )
  12. zstyle ':vcs_info:*' enable git
  13. zstyle ':vcs_info:git*:*' get-revision true
  14. zstyle ':vcs_info:git*:*' check-for-changes true
  15. zstyle ':vcs_info:git*' formats "(%s) %c%u %b%m"
  16. zstyle ':vcs_info:git*' actionformats "(%s|%a) %12.12i %c%u %b%m"
  17. setopt prompt_subst
  18. # Show remote ref name and number of commits ahead-of or behind
  19. function +vi-git-st() {
  20. local ahead behind remote
  21. local -a gitstatus
  22. # Are we on a remote-tracking branch?
  23. remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \
  24. --symbolic-full-name 2>/dev/null)/refs\/remotes\/}
  25. if [[ -n ${remote} ]] ; then
  26. # for git prior to 1.7
  27. # ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l)
  28. ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
  29. (( $ahead )) && gitstatus+=( " ${c3}+${ahead}${c2}" )
  30. # for git prior to 1.7
  31. # behind=$(git rev-list HEAD..origin/${hook_com[branch]} | wc -l)
  32. behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
  33. (( $behind )) && gitstatus+=( "${c4}-${behind}${c2}" )
  34. hook_com[branch]="${hook_com[branch]} [${remote}${(j:/:)gitstatus}]"
  35. fi
  36. }
  37. # Show count of stashed changes
  38. function +vi-git-stash() {
  39. local -a stashes
  40. if [[ -s ${hook_com[base]}/.git/refs/stash ]] ; then
  41. stashes=$(git stash list 2>/dev/null | wc -l)
  42. hook_com[misc]+=" (${stashes} stashed)"
  43. fi
  44. }
  45. zstyle ':vcs_info:git*+set-message:*' hooks git-st git-stash
  46. PROMPT='%B%{$fg[red]%}[%{$fg[yellow]%}%n%{$fg[green]%}@%{$fg[blue]%}%M %{$fg[magenta]%}%~%{$fg[red]%}]%{$reset_color%}$%b '
  47. RPROMPT='%B%{$fg[magenta]%}$vcs_info_msg_0_%{$reset_color%}%b'
  48. # History in cache directory
  49. HISTSIZE=10000
  50. SAVEHIST=10000
  51. # Basic auto/tab complete
  52. autoload -U compinit
  53. zstyle ':completion:*' menu select
  54. zmodload zsh/complist
  55. compinit
  56. _comp_options+=(globdots) # Include hidden files
  57. # Enable vi mode
  58. bindkey -v
  59. export KEYTIMEOUT=1
  60. # Vim bindings in tab mode
  61. bindkey -M menuselect 'h' vi-backward-char
  62. bindkey -M menuselect 'k' vi-up-line-or-history
  63. bindkey -M menuselect 'l' vi-forward-char
  64. bindkey -M menuselect 'j' vi-down-line-or-history
  65. bindkey -v '^?' backward-delete-char
  66. # Vim Cursor shape
  67. function zle-keymap-select {
  68. if [[ ${KEYMAP} == vicmd ]] ||
  69. [[ $1 = 'block' ]]; then
  70. echo -ne '\e[1 q'
  71. elif [[ ${KEYMAP} == main ]] ||
  72. [[ ${KEYMAP} == viins ]] ||
  73. [[ ${KEYMAP} == '' ]]; then
  74. echo -ne '\e[5 q'
  75. fi
  76. }
  77. zle -N zle-keymap-select
  78. zle-line-init() {
  79. zle -K viins
  80. echo -ne "\e[5 q"
  81. }
  82. zle -N zle-line-init
  83. echo -ne '\e[5 q'
  84. preexec() { echo -ne '\e[5 q' ;}
  85. # Vim copy and paste fix in terminal
  86. function x11-clip-wrap-widgets() {
  87. local copy_or_paste=$1
  88. shift
  89. for widget in $@; do
  90. if [[ $copy_or_paste == "copy" ]]; then
  91. eval "
  92. function _x11-clip-wrapped-$widget() {
  93. zle .$widget
  94. xclip -in -selection clipboard <<<\$CUTBUFFER
  95. }
  96. "
  97. else
  98. eval "
  99. function _x11-clip-wrapped-$widget() {
  100. CUTBUFFER=\$(xclip -out -selection clipboard)
  101. zle .$widget
  102. }
  103. "
  104. fi
  105. zle -N $widget _x11-clip-wrapped-$widget
  106. done
  107. }
  108. local copy_widgets=(
  109. vi-yank vi-yank-eol vi-delete vi-backward-kill-word vi-change-whole-line
  110. )
  111. local paste_widgets=(
  112. vi-put-{before,after}
  113. )
  114. # NB: can atm. only wrap native widgets
  115. x11-clip-wrap-widgets copy $copy_widgets
  116. x11-clip-wrap-widgets paste $paste_widgets
  117. # starts one or multiple args in background
  118. background() {
  119. for ((i=2;i<=$#;i++)); do
  120. ${@[1]} ${@[$i]} &> /dev/null &|
  121. done
  122. }
  123. source $HOME/.config/zsh/suffixaliasrc 2>/dev/null # Load suffix aliases
  124. [ -f "$HOME/.config/aliasrc" ] && source "$HOME/.config/aliasrc" # Load aliases
  125. # Load command-not-found-handler
  126. source /usr/share/doc/pkgfile/command-not-found.zsh
  127. # Load zsh-syntax-highlighting; should be last.
  128. source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh 2>/dev/null
  129. pfetch