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.

149 lines
4.6 KiB

  1. # Disable ctrl-s and ctrl-q.
  2. stty -ixon
  3. setopt autocd autopushd \
  4. # Enable autosuggestions
  5. source /usr/share/zsh/plugins/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. PS1='%B%{$fg[blue]%}[%{$fg[blue]%}%n%{$fg[blue]%}@%{$fg[blue]%}%M %{$fg[blue]%}%~%{$fg[blue]%}]%{$reset_color%}\$%b '
  47. RPROMPT='%B%{$fg[blue]%}$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. zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' # Case insensitive completion
  55. zmodload zsh/complist
  56. compinit
  57. _comp_options+=(globdots) # Include hidden files
  58. # Enable vi mode
  59. bindkey -v
  60. export KEYTIMEOUT=1
  61. # Vim bindings in tab mode
  62. bindkey -M menuselect 'h' vi-backward-char
  63. bindkey -M menuselect 'k' vi-up-line-or-history
  64. bindkey -M menuselect 'l' vi-forward-char
  65. bindkey -M menuselect 'j' vi-down-line-or-history
  66. bindkey -v '^?' backward-delete-char
  67. # Vim Cursor shape
  68. function zle-keymap-select {
  69. if [[ ${KEYMAP} == vicmd ]] ||
  70. [[ $1 = 'block' ]]; then
  71. echo -ne '\e[1 q'
  72. elif [[ ${KEYMAP} == main ]] ||
  73. [[ ${KEYMAP} == viins ]] ||
  74. [[ ${KEYMAP} == '' ]]; then
  75. echo -ne '\e[5 q'
  76. fi
  77. }
  78. zle -N zle-keymap-select
  79. zle-line-init() {
  80. zle -K viins
  81. echo -ne "\e[5 q"
  82. }
  83. zle -N zle-line-init
  84. echo -ne '\e[5 q'
  85. preexec() { echo -ne '\e[5 q' ;}
  86. # Vim copy and paste fix in terminal
  87. function x11-clip-wrap-widgets() {
  88. local copy_or_paste=$1
  89. shift
  90. for widget in $@; do
  91. if [[ $copy_or_paste == "copy" ]]; then
  92. eval "
  93. function _x11-clip-wrapped-$widget() {
  94. zle .$widget
  95. xclip -in -selection clipboard <<<\$CUTBUFFER
  96. }
  97. "
  98. else
  99. eval "
  100. function _x11-clip-wrapped-$widget() {
  101. CUTBUFFER=\$(xclip -out -selection clipboard)
  102. zle .$widget
  103. }
  104. "
  105. fi
  106. zle -N $widget _x11-clip-wrapped-$widget
  107. done
  108. }
  109. local copy_widgets=(
  110. vi-yank vi-yank-eol vi-delete vi-backward-kill-word vi-change-whole-line
  111. )
  112. local paste_widgets=(
  113. vi-put-{before,after}
  114. )
  115. # NB: can atm. only wrap native widgets
  116. x11-clip-wrap-widgets copy $copy_widgets
  117. x11-clip-wrap-widgets paste $paste_widgets
  118. # starts one or multiple args in background
  119. background() {
  120. for ((i=2;i<=$#;i++)); do
  121. ${@[1]} ${@[$i]} &> /dev/null &|
  122. done
  123. }
  124. source $HOME/.config/zsh/suffixaliasrc 2>/dev/null # Load suffix aliases
  125. [ -f "$HOME/.config/aliasrc" ] && source "$HOME/.config/aliasrc" # Load aliases
  126. # Load command-not-found-handler
  127. source /usr/share/doc/pkgfile/command-not-found.zsh
  128. # Load zsh-syntax-highlighting; should be last.
  129. source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh 2>/dev/null
  130. if [[ -n "$PS1" ]] && [[ -z "$TMUX" ]] && [[ -n "$SSH_CONNECTION" ]]; then
  131. tmux attack-session -t $USER || tmux new-session -s $USER
  132. fi
  133. pfetch