.zshrc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. # STTY
  2. # ====
  3. # Disable start/stop signals (therefore allows to use ^s in keybindings).
  4. stty -ixon
  5. # Loads
  6. # =====
  7. autoload -U colors && colors
  8. autoload -U deer
  9. autoload edit-command-line
  10. autoload -Uz vcs_info
  11. # Options
  12. # =======
  13. # Use more interactive 'menu' style tab completion. :D
  14. zstyle ':completion:*' menu select
  15. # Used in $RPROMPT for showing current git branch, see prompt section.
  16. zstyle ':vcs_info:*' enable git
  17. zstyle ':vcs_info:git*' formats "%b"
  18. cdpath=(~)
  19. setopt autocd extendedglob no_beep prompt_subst
  20. # Disables annoying GTK authentication popup for example when doing `git push'.
  21. unset SSH_ASKPASS
  22. # Escape key delay to go into normal mode on the cli is 0.1s instead of default
  23. # 0.4s.
  24. KEYTIMEOUT=1
  25. # History
  26. # -------
  27. # Lines of history to keep in memory.
  28. HISTSIZE=2000
  29. # Should come out to approximately 1GB max file size.. I think.
  30. SAVEHIST=20000000
  31. # Immediately append to $HISTFILE, instead of when the shell exits.
  32. setopt inc_append_history
  33. # If a new command line being added to the history list duplicates an older
  34. # one, remove the older one from the history list, even if it is not the
  35. # previous event.
  36. setopt hist_ignore_all_dups
  37. # Do not add command lines that begin with at least one space to the history
  38. # list.
  39. setopt hist_ignore_space
  40. # Do not save duplicate entries into $HISTFILE.
  41. setopt hist_save_no_dups
  42. # Functions
  43. # =========
  44. # Send 'urgent' bell to terminal. Useful to append at the end of commands that
  45. # are expected to take a long time to finish so that you can be notified when
  46. # they're done.
  47. bell () {
  48. echo -e "\a"
  49. }
  50. ping-google () {
  51. local dest='8.8.8.8'
  52. [[ -z "$1" ]] && ping "$dest" || ping -c "$1" "$dest"
  53. }
  54. ping-test () {
  55. ping-google 3
  56. while [[ $? -eq 1 ]]; do ping-google 3 && bell; done
  57. }
  58. # Enter directory.
  59. ed () {
  60. mkdir -p "$1"
  61. cd ./"$1"
  62. }
  63. # Exit directory.
  64. ex () {
  65. cd ..
  66. rmdir "$OLDPWD" >/dev/null
  67. }
  68. tw () {
  69. { fd -e tex -d 1; fd -e png; fd -e jpg; } \
  70. | entr -s 'latexmk -lualatex \
  71. && (mv -u .aux/*.pdf . >/dev/null 2>&1 || true) \
  72. && (ln -s $(readlink -f *.pdf) .aux/. >/dev/null 2>&1 || true)'
  73. }
  74. # Zle
  75. # ---
  76. # Helper function for setting cursor shape.
  77. set-cursor-shape () {
  78. if [[ $TERM != "linux" ]]; then
  79. case "$1" in
  80. blinking_block)
  81. echo -e -n "\x1b[\x30 q"
  82. ;;
  83. steady_block)
  84. echo -e -n "\x1b[\x32 q"
  85. ;;
  86. blinking_underline)
  87. echo -e -n "\x1b[\x33 q"
  88. ;;
  89. steady_underline)
  90. echo -e -n "\x1b[\x34 q"
  91. ;;
  92. blinking_bar)
  93. echo -e -n "\x1b[\x35 q"
  94. ;;
  95. steady_bar)
  96. echo -e -n "\x1b[\x36 q"
  97. ;;
  98. esac
  99. fi
  100. }
  101. zle-keymap-select () {
  102. if [[ $KEYMAP == 'vicmd' ]]; then
  103. set-cursor-shape steady_block
  104. else
  105. set-cursor-shape steady_bar
  106. fi
  107. }
  108. zle-line-init () {
  109. zle -K viins
  110. set-cursor-shape steady_bar
  111. }
  112. # This helper function is used simply to reset the command line, so that any
  113. # current directory prompt indicators can be updated after each cd command.
  114. zle-cd () {
  115. cd "$1"
  116. zle kill-whole-line
  117. zle accept-line
  118. }
  119. go-home () {
  120. zle-cd ~
  121. }
  122. go-back () {
  123. zle-cd "$OLDPWD"
  124. }
  125. go-up () {
  126. zle-cd ..
  127. }
  128. # For opening a new terminal emulator in the current directory.
  129. run-term-em () {
  130. # `&!' is a convenient shortcut for `& disown'.
  131. [[ $TERM != "linux" ]] && ${TERMINAL} >/dev/null 2>&1 &!
  132. }
  133. zle -N edit-command-line
  134. zle -N deer
  135. zle -N zle-keymap-select
  136. zle -N zle-line-init
  137. zle -N go-home
  138. zle -N go-back
  139. zle -N go-up
  140. zle -N run-term-em
  141. # Key Bindings
  142. # ============
  143. bindkey -M vicmd '^g' deer
  144. bindkey -M viins '^g' deer
  145. bindkey -M vicmd 'v' edit-command-line
  146. bindkey -M vicmd '^j' go-back
  147. bindkey -M viins '^j' go-back
  148. bindkey -M vicmd '^h' go-home
  149. bindkey -M viins '^h' go-home
  150. bindkey -M vicmd '^k' go-up
  151. bindkey -M viins '^k' go-up
  152. bindkey -M vicmd '^s' history-incremental-search-backward
  153. bindkey -M viins '^s' history-incremental-search-backward
  154. bindkey -M vicmd '/' history-incremental-search-backward
  155. bindkey -M vicmd '^f' history-incremental-search-forward
  156. bindkey -M viins '^f' history-incremental-search-forward
  157. bindkey -M vicmd '?' history-incremental-search-forward
  158. bindkey -M viins '^u' reverse-menu-complete
  159. bindkey -M vicmd '^o' run-term-em
  160. bindkey -M viins '^o' run-term-em
  161. bindkey -M vicmd 'H' vi-beginning-of-line
  162. bindkey -M vicmd 'L' vi-end-of-line
  163. # Aliases
  164. # =======
  165. alias ab='acpi -b'
  166. alias am='alsamixer'
  167. alias bl='bell'
  168. alias c='cat'
  169. alias cp='cp -v'
  170. alias cpr='cp -r'
  171. alias e='emacsclient -a "" -c'
  172. alias f='file'
  173. alias g='git'
  174. alias ga='git add'
  175. alias gall='git add -A'
  176. alias gap='git add -p'
  177. alias gch='git checkout'
  178. alias gcm='git commit'
  179. alias gcmm='git commit --edit -m \
  180. "$(git log --format=%B --reverse HEAD..HEAD@{1})"'
  181. alias gd='git diff'
  182. alias gdc='git diff --check'
  183. alias gds='git diff --staged'
  184. alias gdsc='git diff --staged --check'
  185. alias gg='git grep'
  186. alias ggi='git grep -i'
  187. alias gl='git log'
  188. alias gld='git log -p'
  189. alias gpi='grep -i'
  190. alias gpsh='git push'
  191. alias grs='git reset'
  192. alias gs='git status'
  193. alias gsh='git show'
  194. alias gshd='git show HEAD'
  195. alias info='info --vi-keys'
  196. alias kill-emacs-daemon='emacsclient -e "(kill-emacs)"'
  197. alias l='less -R'
  198. alias ls='ls -p --color'
  199. alias l1='ls -1'
  200. alias la='ls -A'
  201. alias la1='ls -A1'
  202. alias lah='ls -lAh'
  203. alias lh='ls -lh'
  204. alias ll='ls -lh * | less -R'
  205. alias m='mpv --loop=inf'
  206. alias ma='mpv --loop=inf --no-video'
  207. alias md='mkdir -pv'
  208. alias mi='mediainfo'
  209. alias mv='mv -v'
  210. alias nixpaste="curl -F 'text=<-' http://nixpaste.lbr.uno"
  211. alias pn='ping-google 3'
  212. alias rm='rm -vI'
  213. alias rmdir='rmdir -v'
  214. alias sd='sudo shutdown now'
  215. alias se='sudoedit'
  216. # I basically only use stow to manage dotfiles.
  217. alias stow='stow -t ~ --no-folding'
  218. alias tar-extract='tar -xzvf'
  219. # The single quotes in the search patterns ensure that the line itself is not
  220. # listed in the search results.
  221. alias todo='git grep -I -A 2 -e T''ODO: -e F''IXME:'
  222. alias v='vim'
  223. alias vc='vim ~/.vimrc'
  224. alias vn='vim ~/dots/nixos/config.nix'
  225. alias vs='vim ~/dots/sxhkd/.config/sxhkd/sxhkdrc'
  226. alias vz='vim ~/.zshrc'
  227. alias z='zathura --fork'
  228. alias zz='. ~/.zshrc'
  229. # Prompt
  230. # ======
  231. precmd () {
  232. vcs_info
  233. }
  234. local rsc="%{$reset_color%}"
  235. PROMPT="$rsc %B%(?.%{$fg[green]%}.%{$fg[red]%})➜$rsc%b "
  236. RPROMPT='$rsc${BGJOBS}%(1j.%j.) $rsc%{$fg[magenta]%}${vcs_info_msg_0_} \
  237. $rsc%B%{$fg[blue]%}%~%b$rsc'
  238. # Theming
  239. # =======
  240. # Disable underlines.
  241. ZSH_HIGHLIGHT_STYLES[precommand]='fg=green'
  242. ZSH_HIGHLIGHT_STYLES[path]=none
  243. ZSH_HIGHLIGHT_STYLES[path_prefix]=none
  244. ZSH_HIGHLIGHT_STYLES[path_approx]='fg=yellow'