summaryrefslogtreecommitdiffstats
path: root/dotfiles/zshrc
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2020-12-03 16:45:06 +0100
committerMinijackson <minijackson@riseup.net>2020-12-03 16:45:06 +0100
commit3f0e83cb4816e637d8c916fb77217e1c5824dbe5 (patch)
tree65b48ffe6e82459cde97b8ee61a597402ba2617b /dotfiles/zshrc
downloadnixos-config-reborn-3f0e83cb4816e637d8c916fb77217e1c5824dbe5.tar.gz
nixos-config-reborn-3f0e83cb4816e637d8c916fb77217e1c5824dbe5.zip
initial commit: most of previous configuration reworked
Diffstat (limited to 'dotfiles/zshrc')
-rw-r--r--dotfiles/zshrc242
1 files changed, 242 insertions, 0 deletions
diff --git a/dotfiles/zshrc b/dotfiles/zshrc
new file mode 100644
index 0000000..1263eeb
--- /dev/null
+++ b/dotfiles/zshrc
@@ -0,0 +1,242 @@
1# Some variables are defined in ../commandline.nix
2
3# For users using home-manager
4if [ -f "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" ]; then
5 . "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"
6fi
7
8# Grml Zsh configuration {{{
9# ==========================
10
11# With prompt specific sequences
12local dominated="%{${dominant_escape_code}%}"
13local dimmed="%{${dim_fg_escape_code}%}"
14
15# Use the dominant color in the prompt
16# In the username item for non-root, in the host item for root
17if [ "$EUID" -ne 0 ]; then
18 zstyle ':prompt:grml:left:items:user' pre "${dominated}%B"
19else
20 zstyle ':prompt:grml:left:items:host' pre "${dominated}"
21 zstyle ':prompt:grml:left:items:host' post "%f"
22fi
23
24# Change the style of VCS prompt info
25zstyle ':vcs_info:*' check-for-changes true
26zstyle ':vcs_info:*' stagedstr "s"
27zstyle ':vcs_info:*' unstagedstr "u"
28zstyle ':vcs_info:*' formats "${dimmed}(%f%s${dimmed})-[${dominated}%b${dimmed}]-{%f%c%u${dimmed}}%f " "zsh: %r"
29zstyle ':vcs_info:*' actionformats "${dimmed}(%f%s${dimmed})-[${dominated}%b${dimmed}|%F{yellow}%a${dimmed}]-{%f%c%u${dimmed}}%f " "zsh: %r"
30
31# }}}
32
33# Completion system {{{
34# =====================
35
36# Change completion messages
37zstyle ':completion:*:corrections' format "${dominated}%BFTFY: %b${dominated}(errors: %e)%f"
38zstyle ':completion:*:descriptions' format "${dominated} -- So you want a %B%d%b${dominated}? --%f"
39zstyle ':completion:*:messages' format "${dominated}You got mail: %f%d"
40zstyle ':completion:*:warnings' format "%F{red}I'm sorry Dave, but I cannot allow you to find%f %d"
41
42# Always activate selection in completion
43zstyle ':completion:*' menu select
44
45# Case insensitive completion and substring completion
46zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
47
48# Increase the number of errors based on the length of the typed word. But make
49# sure to cap (at 7) the max-errors to avoid hanging.
50zstyle -e ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3>7?7:($#PREFIX+$#SUFFIX)/3))numeric)'
51
52# Tmux Completion {{{
53# -------------------
54
55# From: https://blog.plenz.com/2012-01/zsh-complete-words-from-tmux-pane.html
56# And: https://gist.github.com/blueyed/6856354
57
58_tmux_pane_words() {
59 local expl
60 local -a w
61 if [[ -z "$TMUX_PANE" ]]; then
62 _message "not running inside tmux!"
63 return 1
64 fi
65
66 # Based on vim-tmuxcomplete's splitwords function.
67 # https://github.com/wellle/tmux-complete.vim/blob/master/sh/tmuxcomplete
68 _tmux_capture_pane() {
69 tmux capture-pane -J -p -S -100 $@ |
70 # Remove "^C".
71 sed 's/\^C\S*/ /g' |
72 # copy lines and split words
73 sed -e 'p;s/[^a-zA-Z0-9_]/ /g' |
74 # split on spaces
75 tr -s '[:space:]' '\n' |
76 # remove surrounding non-word characters
77 =grep -o "\w.*\w"
78 }
79 # Capture current pane first.
80 w=( ${(u)=$(_tmux_capture_pane)} )
81 echo $w > /tmp/w1
82 local i
83 for i in $(tmux list-panes -F '#D'); do
84 # Skip current pane (handled before).
85 [[ "$TMUX_PANE" = "$i" ]] && continue
86 w+=( ${(u)=$(_tmux_capture_pane -t $i)} )
87 done
88 _wanted values expl 'word from current tmux pane' compadd -a w
89}
90
91zle -C tmux-pane-words-prefix complete-word _generic
92zle -C tmux-pane-words-anywhere complete-word _generic
93
94zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' completer _tmux_pane_words
95zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' ignore-line current
96# Display the menu on first execution of the hotkey.
97zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' menu yes select
98zstyle ':completion:tmux-pane-words-anywhere:*' matcher-list 'b:=* m:{A-Za-z}={a-zA-Z}'
99
100# }}}
101
102# }}}
103
104# Bindkeys {{{
105# ============
106
107bindkey -v
108
109bindkey '^X^T' tmux-pane-words-prefix
110
111bindkey '^[[A' history-substring-search-up
112bindkey '^[[B' history-substring-search-down
113bindkey '^[OA' history-substring-search-up
114bindkey '^[OB' history-substring-search-down
115
116# }}}
117
118# Aliases {{{
119# ===========
120
121# Some aliases taken from the Prezo zsh configuration framework:
122# https://github.com/sorin-ionescu/prezto
123
124# Git {{{
125# -------
126
127alias g='git'
128
129# Branch (b)
130alias gb='git branch'
131
132# Commit (c)
133alias gc='git commit --verbose'
134alias gca='git commit --verbose --all'
135alias gcf='git commit --amend --reuse-message HEAD'
136alias gcs='git show'
137
138alias gco='git checkout'
139alias gcO='git checkout --patch'
140
141# Fetch (f)
142alias gf='git fetch'
143alias gfm='git pull'
144alias gfc='git clone'
145alias gfcr='git clone --recurse-submodules'
146
147# Index (i)
148alias gia='git add'
149alias giA='git add --patch'
150alias gid='git diff --cached'
151alias giD='git diff --cached --word-diff'
152
153# Log (l)
154logMediumFormat='%C(bold)Commit:%C(reset) %C(green)%H%C(red)%d%n%C(bold)Author:%C(reset) %C(cyan)%an <%ae>%n%C(bold)Date:%C(reset) %C(blue)%ai (%ar)%C(reset)%n%+B'
155logBriefFormat='%C(green)%h%C(reset) %s%n%C(blue)(%ar by %an)%C(red)%d%C(reset)%n'
156logOnelineFormat='%C(green)%h%C(reset) %s%C(red)%d%C(reset)%n'
157
158alias gl='git log --topo-order --pretty=format:"${logMediumFormat}"'
159alias gls='git log --topo-order --stat --pretty=format:"${logMediumFormat}"'
160alias gld='git log --topo-order --stat --patch --full-diff --pretty=format:"${logMediumFormat}"'
161alias glg='git log --topo-order --all --graph --pretty=format:"${logOnelineFormat}"'
162alias glo='git log --topo-order --pretty=format:"${logOnelineFormat}"'
163alias glb='git log --topo-order --pretty=format:"${logBriefFormat}"'
164alias glc='git shortlog --summary --numbered'
165
166# Merge (m)
167alias gm='git merge'
168alias gmt='git mergetool'
169
170# Push (p)
171alias gp='git push'
172alias gpf='git push --force-with-lease'
173alias gpt='git push --tags'
174
175# Rebase (r)
176alias gr='git rebase'
177
178# Stash (s)
179alias gs='git stash'
180
181# Working Copy (w)
182alias gws='git status --ignore-submodules=none'
183alias gwd='git diff'
184alias gwD='git diff --word-diff'
185
186# }}}
187
188# Prevents some mistakes
189alias cp='cp -i'
190alias mv='mv -i'
191alias rm='rm -i'
192
193# }}}
194
195# Helpful functions {{{
196# =====================
197
198function ssht
199{
200 /usr/bin/env ssh -t "$@" "tmux new-session -A -s 'ssh-$HOST'"
201}
202
203compdef ssht=ssh
204
205# }}}
206
207# Abbreviations {{{
208# =================
209
210# Abbreviation system provided by the grml config
211# More info here:
212# http://www.zshwiki.org/home/examples/zleiab
213
214abk=(
215 'P' '|& ${(z)PAGER}'
216 'L' '|& ${(z)PAGER}'
217
218 'HL' ' --help |& ${(z)PAGER}'
219
220 'G' '|& rg'
221 'FG' '|& rg -F'
222
223 'H' '| head'
224 'T' '| tail'
225 'C' '| wc -l'
226)
227
228# }}}
229
230# GPG / SSH agents {{{
231# ====================
232
233#function _gpg-agent-update-tty
234#{
235# gpg-connect-agent UPDATESTARTUPTTY /bye >/dev/null
236#}
237#
238#add-zsh-hook preexec _gpg-agent-update-tty
239
240# }}}
241
242# vim: fdm=marker