Guest User

Untitled

a guest
May 12th, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.34 KB | None | 0 0
  1. export TERM="xterm-256color"
  2.  
  3. setopt menu_complete inc_append_history autocd recexact longlistjobs
  4. setopt histignorealldups autopushd nobgnice autoparamslash
  5.  
  6. autoload -U history-search-end
  7. zle -N history-beginning-search-backward-end history-search-end
  8. zle -N history-beginning-search-forward-end history-search-end
  9.  
  10. ### Set variables
  11. #################
  12. CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/zsh"
  13. HISTFILE="$CONFIG_DIR/.zhistory"
  14. HISTSIZE=1000
  15. SAVEHIST=1000
  16.  
  17. # Custom bin paths
  18. [ -d "$HOME/scripts" ] && PATH="$HOME/scripts/sh:$PATH"
  19. [ -d "/opt/bin" ] && PATH="/opt/bin:$PATH"
  20. PATH="/usr/local/bin:/usr/local/sbin/:$PATH"
  21.  
  22. # Custom locations
  23. ZSH_CUSTOM_COMPLETION_PATH="$CONFIG_DIR/custom/completion/"
  24.  
  25. ### Load colors
  26. ###############
  27. autoload colors zsh/terminfo
  28. [ "$terminfo[colors]" -ge 8 ] && colors
  29. for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
  30.    eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
  31.    eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
  32.    (( count = $count + 1 ))
  33. done
  34.  
  35. ### set common functions
  36. ########################
  37. function url_encode() {
  38.     # Works only with python3
  39.     python3 -c \
  40.         "import urllib.parse; print(urllib.parse.quote(input()))" <<< "$1"
  41. }
  42. function maketar() { tar cvzf "${1%%/}.tar.gz"  "${1%%/}/"; }
  43. function makezip() { zip -r "${1%%/}.zip" "$1" ; }
  44.  
  45. ### Set alias
  46. #############
  47. alias cls="clear"
  48. alias ..="cd .."
  49. alias cd..="cd .."
  50. alias ll="ls -lisa --color=auto"
  51. alias dfd="df -h /dev/nvme0n1p2 --output=source,fstype,size,used,avail,pcent"
  52. alias ls="ls -CF --color=auto"
  53. alias psgrep="ps aux | grep -v grep | grep -i -e VSZ -e"
  54. alias grep='grep --color=auto'
  55. alias open="xdg-open"
  56. alias vibindings="bindkey -v"
  57. alias embindings="bindkey -e"
  58.  
  59. ### Add custom completions
  60. ##########################
  61. [ -d "$ZSH_CUSTOM_COMPLETION_PATH" ] && fpath+="$ZSH_CUSTOM_COMPLETION_PATH"
  62.  
  63. ### Bind keys
  64. #############
  65. autoload -U compinit
  66. compinit
  67. bindkey -e
  68. bindkey "^?" backward-delete-char
  69. bindkey "\e[3~" delete-char
  70. bindkey "\e[1;5D" backward-word
  71. bindkey "\e[1;5C" forward-word
  72. bindkey '^[OH' beginning-of-line
  73. bindkey '^[OF' end-of-line
  74. bindkey '^[[5~' up-line-or-history
  75. bindkey '^[[6~' down-line-or-history
  76. bindkey "^[[A" history-beginning-search-backward-end
  77. bindkey "^[[B" history-beginning-search-forward-end
  78. bindkey "^r" history-incremental-search-backward
  79. bindkey ' ' magic-space    # also do history expansion on space
  80. bindkey '^I' complete-word # complete on tab, leave expansion to _expand
  81.  
  82. ### Completion Settings
  83. #######################
  84. zstyle ':completion::complete:*' use-cache on
  85. zstyle ':completion::complete:*' cache-path "$CONFIG_DIR/cache/$HOST"
  86. zstyle ':completion:*' list-prompt \
  87.     '%SAt %p: Hit TAB for more, or the character to insert%s'
  88. zstyle ':completion:*' menu select=1 _complete _ignored _approximate
  89. zstyle -e ':completion:*:approximate:*' max-errors \
  90.     'reply=( $(( ($#PREFIX+$#SUFFIX)/2 )) numeric )'
  91. zstyle ':completion:*' select-prompt \
  92.     '%SScrolling active: current selection at %p%s'
  93.  
  94. ### Completion Styles
  95. #####################
  96. zstyle ':completion:*::::' completer _expand _complete _ignored _approximate
  97.  
  98. # allow one error for every three characters typed in approximate completer
  99. zstyle -e ':completion:*:approximate:*' max-errors 'reply=( $(( 2 )) numeric )'
  100.    
  101. # insert all expansions for expand completer
  102. zstyle ':completion:*:expand:*' tag-order all-expansions
  103.  
  104. # formatting and messages
  105. zstyle ':completion:*' verbose yes
  106. zstyle ':completion:*:descriptions' format '%B%d%b'
  107. zstyle ':completion:*:messages' format '%d'
  108. zstyle ':completion:*:warnings' format 'No matches for: %d'
  109.  
  110. # zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'
  111. zstyle ':completion:*' group-name ''
  112.  
  113. # match uppercase from lowercase
  114. zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
  115.  
  116. # offer indexes before parameters in subscripts
  117. zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
  118.  
  119. ## add colors to processes for kill completion
  120. zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
  121.  
  122. ### Source plugins
  123. ##################
  124. source "$HOME/.config/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
  125. source "$HOME/.config/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh"
  126.  
  127. ### Prompt configuration
  128. ########################
  129. autoload -Uz vcs_info
  130. setopt prompt_subst
  131.  
  132. zstyle ':vcs_info:git:*' check-for-changes true
  133. zstyle ':vcs_info:git:*' stagedstr '!'
  134. zstyle ':vcs_info:git*+set-message:*' hooks git-st git-untracked git-modified
  135.  
  136. function +vi-git-st() {
  137.     local ahead behind
  138.     local -a gitstatus
  139.     ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null \
  140.         | wc -l)
  141.     (( $ahead )) && gitstatus+=( "+${ahead}" )
  142.     behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null \
  143.         | wc -l)
  144.     (( $behind )) && gitstatus+=( "-${behind}" )
  145.     hook_com[misc]+="${(j:/:)gitstatus}"
  146. }
  147.  
  148. function +vi-git-untracked() {
  149.     git status -s | grep '^??' >/dev/null && hook_com[staged]+='?'
  150. }
  151.  
  152. function +vi-git-modified() {
  153.     git status -s | grep "^\s\{1,\}M" >/dev/null && hook_com[staged]+='M'
  154. }
  155.  
  156. zstyle ':vcs_info:*' formats \
  157.     '%F{5}%r/%S%f %F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%c%m%f '
  158.  
  159. prompt() {
  160.     local usr workdir st errcode elapsed
  161.     usr="%(!.%F{9}%n%f.%F{11}%n%f)"
  162.     workdir="%(1V.${psvar[1]//\./}.%F{6}%3~%f)"
  163.     st="%(?.%F{2}>>%f.%F{9}>>%f)"
  164.     errcode="%(?..%F{9}%?%f)"
  165.     elapsed="%(2V. took %F{13}${psvar[2]}%f.)"
  166.     PROMPT="$usr in ${workdir}${elapsed} $st "
  167.     RPROMPT="$errcode"
  168. }
  169.  
  170. my_vcs_info() { vcs_info && psvar[1]=( "$vcs_info_msg_0_" ) }
  171. my_timer_start() { timer_start=$( date +%s ); }
  172. my_timer_show() {
  173.     local elapsed hours minutes seconds
  174.     psvar[2]=( "" )
  175.     [ -n $timer_start ] \
  176.         && elapsed=$(( $(date +%s) - ${timer_start:-$( date +%s )} )) \
  177.         || return 0
  178.     [ $elapsed -lt 3 ] && return 0
  179.     [ $elapsed -lt 60 ] && psvar[2]=( "${elapsed}s") && return 0
  180.     seconds=$(($elapsed%60))
  181.     minutes=$(($elapsed/60))
  182.     [ $elapsed -lt 3600 ] && psvar[2]=( "${minutes}m${seconds}s" ) && return 0
  183.     hours=$(($minutes/60))
  184.     minutes=$(($minutes%60))
  185.     psvar[2]=( "${hours}h${minutes}m${seconds}s" )
  186. }
  187.  
  188. preexec_functions+=( my_timer_start )
  189. precmd_functions+=( my_vcs_info )
  190. precmd_functions+=( my_timer_show )
  191. precmd_functions+=( prompt )
Add Comment
Please, Sign In to add comment