zshrc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. #!/usr/bin/env zsh
  2. [[ -d $HOME/.emacs.d/bin ]] && export PATH=$HOME/.emacs.d/bin:$PATH
  3. [[ -d $HOME/.bin ]] && export PATH=$HOME/.bin:$PATH
  4. if [ -d $HOME/perl5 ]; then
  5. PATH="$HOME/perl5/bin${PATH:+:${PATH}}"; export PATH;
  6. PERL5LIB="$HOME/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB;
  7. PERL_LOCAL_LIB_ROOT="$HOME/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT;
  8. PERL_MB_OPT="--install_base \"$HOME/perl5\""; export PERL_MB_OPT;
  9. PERL_MM_OPT="INSTALL_BASE=$HOME/perl5"; export PERL_MM_OPT;
  10. fi
  11. source <(antibody init)
  12. export PYENV_ROOT="${HOME}/.pyenv/"
  13. export ZSH="${HOME}/.cache/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-robbyrussell-SLASH-oh-my-zsh/"
  14. antibody bundle robbyrussell/oh-my-zsh
  15. antibody bundle robbyrussell/oh-my-zsh path:plugins/command-not-found
  16. antibody bundle robbyrussell/oh-my-zsh path:plugins/copydir
  17. antibody bundle robbyrussell/oh-my-zsh path:plugins/copyfile
  18. antibody bundle robbyrussell/oh-my-zsh path:plugins/cp
  19. antibody bundle robbyrussell/oh-my-zsh path:plugins/docker
  20. antibody bundle robbyrussell/oh-my-zsh path:plugins/docker-compose
  21. antibody bundle robbyrussell/oh-my-zsh path:plugins/extract
  22. antibody bundle robbyrussell/oh-my-zsh path:plugins/git
  23. antibody bundle robbyrussell/oh-my-zsh path:plugins/git-flow-avh
  24. antibody bundle robbyrussell/oh-my-zsh path:plugins/git-prompt
  25. antibody bundle robbyrussell/oh-my-zsh path:plugins/history
  26. antibody bundle robbyrussell/oh-my-zsh path:plugins/pass
  27. antibody bundle robbyrussell/oh-my-zsh path:plugins/python
  28. antibody bundle robbyrussell/oh-my-zsh path:plugins/pyenv
  29. antibody bundle robbyrussell/oh-my-zsh path:plugins/shrink-path
  30. antibody bundle robbyrussell/oh-my-zsh path:plugins/sudo
  31. [[ $INSIDE_EMACS != *"term"* ]] && antibody bundle zsh-users/zsh-autosuggestions
  32. antibody bundle zsh-users/zsh-syntax-highlighting
  33. antibody bundle zsh-users/zsh-completions
  34. antibody bundle zsh-users/zsh-history-substring-search
  35. antibody bundle zimfw/zimfw path:modules/history
  36. antibody bundle mafredri/zsh-async
  37. # Enable highlighters
  38. ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor root line)
  39. # Override highlighter colors
  40. typeset -gA ZSH_HIGHLIGHT_STYLES
  41. ZSH_HIGHLIGHT_STYLES[default]=bold
  42. ZSH_HIGHLIGHT_STYLES[line]=bold
  43. # autoload -U zutil
  44. # autoload -U compinit
  45. # autoload -U complist
  46. #-----------------------------
  47. # Prompt
  48. #-----------------------------
  49. VIRTUAL_ENV_DISABLE_PROMPT=1
  50. function virtualenv_status() {
  51. [[ -z "$VIRTUAL_ENV" ]] && return ""
  52. basename " %{${fg_bold[white]}%}`basename \"$VIRTUAL_ENV\"`%{${reset_color}%}"
  53. }
  54. function git_status(){
  55. [[ ! -d ".git/" ]] && return ""
  56. echo -e " $(git_super_status)"
  57. }
  58. ZSH_THEME_GIT_PROMPT_PREFIX=""
  59. ZSH_THEME_GIT_PROMPT_SUFFIX=""
  60. ZSH_THEME_GIT_PROMPT_SEPARATOR=" "
  61. # section for dir
  62. function prompt_dir() {
  63. echo '%B%F{black}$(shrink_path -f)%f%b'
  64. }
  65. # section for git branch
  66. function prompt_git() {
  67. echo '$(git_status)'
  68. }
  69. # section for git branch
  70. function prompt_venv() {
  71. echo '$(virtualenv_status)'
  72. }
  73. # refresh prompt with new data
  74. prompt_refresh() {
  75. PROMPT="$prompt_data[prompt_venv] %(!,%B%F{red}#%f%b,%B%F{blue}>%f%b) "
  76. RPROMPT="$prompt_data[prompt_dir]$prompt_data[prompt_git]"
  77. # Redraw the prompt.
  78. zle reset-prompt
  79. }
  80. prompt_callback() {
  81. local job=$1 code=$2 output=$3 exec_time=$4
  82. prompt_data[$job]=$output
  83. prompt_refresh
  84. }
  85. async_init
  86. # cache variable
  87. typeset -Ag prompt_async
  88. typeset -Ag prompt_data
  89. # Start async worker
  90. async_start_worker prompt_async -n
  91. # Register callback function for the workers completed jobs
  92. async_register_callback prompt_async prompt_callback
  93. # start async jobs before cmd
  94. prompt_precmd() {
  95. async_job prompt_async prompt_dir
  96. async_job prompt_async prompt_venv $PWD # required
  97. async_job prompt_async prompt_git $PWD # required
  98. }
  99. # Setup
  100. zmodload zsh/zle
  101. autoload -Uz add-zsh-hook
  102. add-zsh-hook precmd prompt_precmd
  103. PROMPT=' %(!,%B%F{red}#%f%b,%B%F{blue}>%f%b) '
  104. # PROMPT='$(virtualenv_status) %(!,%B%F{red}#%f%b,%B%F{blue}>%f%b) '
  105. # RPROMPT='%B%F{black}$(shrink_path -f)%f%b$(git_status)'
  106. # Color command correction prompt
  107. SPROMPT="$fg[cyan]Correct $fg[red]%R$reset_color $fg[magenta]to $fg[green]%r?$reset_color ($fg[white]Si :: No :: Abortar :: Editar$fg[white])"
  108. #-----------------------------
  109. # colors
  110. #-----------------------------
  111. LS_COLORS='rs=0:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:';
  112. #------------------------------
  113. # Keybindings
  114. #------------------------------
  115. bindkey -e
  116. typeset -g -A key
  117. #bindkey '\e[3~' delete-char
  118. bindkey '\e[1~' beginning-of-line
  119. bindkey '\e[4~' end-of-line
  120. #bindkey '\e[2~' overwrite-mode
  121. bindkey '^?' backward-delete-char
  122. bindkey '^[[1~' beginning-of-line
  123. bindkey '^[[5~' up-line-or-history
  124. bindkey '^[[3~' delete-char
  125. bindkey '^[[4~' end-of-line
  126. bindkey '^[[6~' down-line-or-history
  127. bindkey '^[[A' up-line-or-search
  128. bindkey '^[[D' backward-char
  129. bindkey '^[[B' down-line-or-search
  130. bindkey '^[[C' forward-char
  131. # for rxvt
  132. bindkey "\e[8~" end-of-line
  133. bindkey "\e[7~" beginning-of-line
  134. # for gnome-terminal
  135. bindkey "\eOH" beginning-of-line
  136. bindkey "\eOF" end-of-line
  137. bindkey -M emacs '^P' history-substring-search-up
  138. bindkey -M emacs '^N' history-substring-search-down
  139. #------------------------------
  140. # Window title
  141. #------------------------------
  142. case $TERM in
  143. termite|*xterm*|rxvt|rxvt-unicode|rxvt-256color|rxvt-unicode-256color|(dt|k|E)term)
  144. precmd () {
  145. print -Pn "\e]0;%n: %~ \a"
  146. }
  147. preexec () { print -Pn "\e]0;$1\a" }
  148. ;;
  149. screen|screen-256color)
  150. precmd () {
  151. print -Pn "\e]0;%n: %~ \a"
  152. }
  153. preexec () {
  154. print -Pn "\e]0;$1\a"
  155. }
  156. ;;
  157. esac
  158. # Quick find
  159. f() {
  160. echo "find . -iname \"*$1*\""
  161. find . -iname "*$1*"
  162. }
  163. # Show my public IP
  164. mypip() {
  165. curl -s ipinfo.io/ip
  166. }
  167. #export PAGER="eless"
  168. #export LESS="-iMSx4 -XFR"
  169. # if which lesspipe.sh >/dev/null 2>&1; then
  170. # export LESSOPEN="| lesspipe.sh %s"
  171. # fi
  172. alias lv="eless"
  173. # term-projectile support
  174. function environment_variable_exists {
  175. eval "value=\"\${$1+x}\""
  176. [ ! -z $value ]
  177. }
  178. function emacs_ansi_term_support {
  179. echo -e "\033AnSiTu" "$LOGNAME" # $LOGNAME is more portable than using whoami.
  180. echo -e "\033AnSiTc" "$(pwd)"
  181. [[ $(uname) = "SunOS" ]] && hostname_options="" || hostname_options="-f"
  182. }
  183. if environment_variable_exists INSIDE_EMACS; then
  184. [[ $INSIDE_EMACS == *"term"* ]] && add-zsh-hook precmd emacs_ansi_term_support
  185. fi
  186. # Watch other user login/out
  187. watch=notme
  188. export LOGCHECK=60
  189. # Enable color support of ls
  190. if [[ "$TERM" != "dumb" ]]; then
  191. if [[ -x `which dircolors` ]]; then
  192. eval `dircolors -b`
  193. alias 'ls=ls --color=auto'
  194. fi
  195. fi
  196. if [[ "$TERM" == "dumb" ]]; then
  197. unsetopt zle
  198. unsetopt prompt_cr
  199. unsetopt prompt_subst
  200. if whence -w precmd >/dev/null; then
  201. unfunction precmd
  202. fi
  203. if whence -w preexec >/dev/null; then
  204. unfunction preexec
  205. fi
  206. PS1='$ '
  207. fi
  208. #------------------------------
  209. # ShellFuncs
  210. #------------------------------
  211. # -- coloured manuals
  212. # man() {
  213. # env \
  214. # LESS_TERMCAP_mb=$(printf "\e[1;31m") \
  215. # LESS_TERMCAP_md=$(printf "\e[1;31m") \
  216. # LESS_TERMCAP_me=$(printf "\e[0m") \
  217. # LESS_TERMCAP_se=$(printf "\e[0m") \
  218. # LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
  219. # LESS_TERMCAP_ue=$(printf "\e[0m") \
  220. # LESS_TERMCAP_us=$(printf "\e[1;32m") \
  221. # man "$@"
  222. # }
  223. #------------------------------
  224. # Calc: https://github.com/arzzen/calc.plugin.zsh
  225. #------------------------------
  226. autoload -U zcalc
  227. function __calc_plugin {
  228. zcalc -e "$*"
  229. }
  230. aliases[calc]='noglob __calc_plugin'
  231. aliases[=]='noglob __calc_plugin'
  232. #------------------------------
  233. # Alias
  234. #------------------------------
  235. # Dotfiles management
  236. alias dt="dotdrop -c ~/.dotdrop.yml"
  237. # Short command aliases
  238. alias ssh="TERM=xterm ssh"
  239. alias mydf="df -hPT | column -t"
  240. alias cl="clear"
  241. alias 'ems=emacsclient -t '
  242. alias 'emsg=emacsclient -c '
  243. alias ls=exa
  244. alias 'j=jobs -l'
  245. alias 's=ls | grep'
  246. alias 'tf=tail -f'
  247. alias 'grep=grep --colour'
  248. alias '..=cd ..'
  249. alias '../..=cd ../..'
  250. alias 'home=cd ~/'
  251. alias 'dir=dir --color=auto'
  252. # Play safe!
  253. alias 'rm=safe-rm'
  254. # advcpmv
  255. alias 'mv=amv -g'
  256. alias 'cp=acp -g'
  257. # For convenience
  258. alias 'mkdir=mkdir -p'
  259. alias 'dus=du -ms * | sort -n'
  260. # Typing errors...
  261. alias 'cd..=cd ..'
  262. # Running 'b.ps' runs 'q b.ps'
  263. alias -s ps=q
  264. alias -s html=q
  265. # Global aliases (expand whatever their position)
  266. # e.g. find . E L
  267. alias -g L='| eless'
  268. alias -g H='| head'
  269. alias -g S='| sort'
  270. alias -g T='| tail'
  271. alias -g N='> /dev/null'
  272. alias -g E='2> /dev/null'
  273. # Python
  274. alias 'pyb=python setup.py build'
  275. alias 'pyd=python setup.py develop'
  276. alias 'pyi=python setup.py install'
  277. # Ripgrep
  278. alias 'rg=rg -uuu'
  279. # do a du -hs on each dir on current path
  280. alias lsdir="for dir in *;do;if [ -d \$dir ];then;du -hsL \$dir;fi;done"
  281. #------------------------------
  282. # Completion
  283. #------------------------------
  284. # case-insensitive (uppercase from lowercase) completion
  285. zstyle ':completion:*' completer _oldlist _expand _complete _match _ignored _approximate
  286. zstyle ':completion:*' completions 0
  287. zstyle ':completion:*' format 'Completing %d'
  288. zstyle ':completion:*' glob 0
  289. zstyle ':completion:*' group-name ''
  290. zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
  291. zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
  292. zstyle ':completion:*' matcher-list '+m:{a-z}={A-Z} r:|[._-]=** r:|=**' '' '' '+m:{a-z}={A-Z} r:|[._-]=** r:|=**'
  293. zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
  294. zstyle ':completion:*' max-errors 1 numeric
  295. zstyle ':completion:*' menu select=2
  296. zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
  297. zstyle ':completion:*' substitute 0
  298. zstyle ":completion:*:commands" rehash 1
  299. zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS'
  300. zstyle ':completion:*:(rm|kill|diff):*' ignore-line yes
  301. zstyle ':completion:*:*:kill:*' menu yes select
  302. zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b) #([0-9]#)*=36=31"
  303. zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
  304. zstyle ':completion:*:cd:*' ignored-patterns '(*/)#lost+found' '(*/)#CVS'
  305. zstyle ':completion:*:descriptions' format '%U%F{yellow}%d%f%u'
  306. zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
  307. zstyle ':completion:*:kill:*' force-list always
  308. zstyle ':completion:*:processes' command 'ps -au$USER'
  309. zstyle ':completion:*:*:*:users' ignored-patterns \
  310. adm apache bin daemon games gdm halt ident junkbust lp mail mailnull \
  311. named news nfsnobody nobody nscd ntp operator pcap postgres radvd \
  312. rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs backup bind \
  313. dictd gnats identd irc man messagebus postfix proxy sys www-data \
  314. avahi Debian-exim hplip list cupsys haldaemon ntpd proftpd statd
  315. zstyle ':completion:*:*:mpv:*' file-patterns '*.(#i)(flv|mp4|webm|mkv|wmv|mov|avi|mp3|ogg|wma|flac|wav|aiff|m4a|m4b|m4v|gif|ifo)(-.) *(-/):directories' '*:all-files'
  316. zstyle :compinstall filename "$HOME/.zshrc"
  317. zstyle -d users
  318. #------------------------------
  319. # History
  320. #------------------------------
  321. # Zsh settings for history
  322. export HISTIGNORE="&:ls:[bf]g:exit:reset:clear:cd:cd ..:cd.."
  323. export HISTSIZE=25000
  324. export HISTFILE=~/.zhistory
  325. export SAVEHIST=25000
  326. setopt APPEND_HISTORY
  327. setopt BANG_HIST
  328. setopt EXTENDED_HISTORY
  329. setopt HIST_IGNORE_ALL_DUPS
  330. setopt HIST_IGNORE_DUPS
  331. setopt HIST_IGNORE_SPACE
  332. setopt HIST_REDUCE_BLANKS
  333. setopt HIST_SAVE_NO_DUPS
  334. setopt HIST_VERIFY
  335. setopt INC_APPEND_HISTORY
  336. setopt SHARE_HISTORY
  337. #------------------------------
  338. # Options
  339. #------------------------------
  340. setopt CORRECT
  341. setopt ALWAYS_TO_END
  342. setopt NOTIFY
  343. setopt NOBEEP
  344. setopt AUTOLIST
  345. setopt AUTOCD
  346. setopt PRINT_EIGHT_BIT
  347. #------------------------------
  348. # Activation
  349. #------------------------------
  350. [[ -n ${ZDOTDIR}/.zcompdump(#qN.mh+24) ]] && compinit || compinit -C