diff options
author | Minijackson <minijackson@riseup.net> | 2020-12-03 16:45:06 +0100 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2020-12-03 16:45:06 +0100 |
commit | 3f0e83cb4816e637d8c916fb77217e1c5824dbe5 (patch) | |
tree | 65b48ffe6e82459cde97b8ee61a597402ba2617b /dotfiles/zshrc | |
download | nixos-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/zshrc | 242 |
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 | ||
4 | if [ -f "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" ]; then | ||
5 | . "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" | ||
6 | fi | ||
7 | |||
8 | # Grml Zsh configuration {{{ | ||
9 | # ========================== | ||
10 | |||
11 | # With prompt specific sequences | ||
12 | local dominated="%{${dominant_escape_code}%}" | ||
13 | local 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 | ||
17 | if [ "$EUID" -ne 0 ]; then | ||
18 | zstyle ':prompt:grml:left:items:user' pre "${dominated}%B" | ||
19 | else | ||
20 | zstyle ':prompt:grml:left:items:host' pre "${dominated}" | ||
21 | zstyle ':prompt:grml:left:items:host' post "%f" | ||
22 | fi | ||
23 | |||
24 | # Change the style of VCS prompt info | ||
25 | zstyle ':vcs_info:*' check-for-changes true | ||
26 | zstyle ':vcs_info:*' stagedstr "s" | ||
27 | zstyle ':vcs_info:*' unstagedstr "u" | ||
28 | zstyle ':vcs_info:*' formats "${dimmed}(%f%s${dimmed})-[${dominated}%b${dimmed}]-{%f%c%u${dimmed}}%f " "zsh: %r" | ||
29 | zstyle ':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 | ||
37 | zstyle ':completion:*:corrections' format "${dominated}%BFTFY: %b${dominated}(errors: %e)%f" | ||
38 | zstyle ':completion:*:descriptions' format "${dominated} -- So you want a %B%d%b${dominated}? --%f" | ||
39 | zstyle ':completion:*:messages' format "${dominated}You got mail: %f%d" | ||
40 | zstyle ':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 | ||
43 | zstyle ':completion:*' menu select | ||
44 | |||
45 | # Case insensitive completion and substring completion | ||
46 | zstyle ':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. | ||
50 | zstyle -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 | |||
91 | zle -C tmux-pane-words-prefix complete-word _generic | ||
92 | zle -C tmux-pane-words-anywhere complete-word _generic | ||
93 | |||
94 | zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' completer _tmux_pane_words | ||
95 | zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' ignore-line current | ||
96 | # Display the menu on first execution of the hotkey. | ||
97 | zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' menu yes select | ||
98 | zstyle ':completion:tmux-pane-words-anywhere:*' matcher-list 'b:=* m:{A-Za-z}={a-zA-Z}' | ||
99 | |||
100 | # }}} | ||
101 | |||
102 | # }}} | ||
103 | |||
104 | # Bindkeys {{{ | ||
105 | # ============ | ||
106 | |||
107 | bindkey -v | ||
108 | |||
109 | bindkey '^X^T' tmux-pane-words-prefix | ||
110 | |||
111 | bindkey '^[[A' history-substring-search-up | ||
112 | bindkey '^[[B' history-substring-search-down | ||
113 | bindkey '^[OA' history-substring-search-up | ||
114 | bindkey '^[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 | |||
127 | alias g='git' | ||
128 | |||
129 | # Branch (b) | ||
130 | alias gb='git branch' | ||
131 | |||
132 | # Commit (c) | ||
133 | alias gc='git commit --verbose' | ||
134 | alias gca='git commit --verbose --all' | ||
135 | alias gcf='git commit --amend --reuse-message HEAD' | ||
136 | alias gcs='git show' | ||
137 | |||
138 | alias gco='git checkout' | ||
139 | alias gcO='git checkout --patch' | ||
140 | |||
141 | # Fetch (f) | ||
142 | alias gf='git fetch' | ||
143 | alias gfm='git pull' | ||
144 | alias gfc='git clone' | ||
145 | alias gfcr='git clone --recurse-submodules' | ||
146 | |||
147 | # Index (i) | ||
148 | alias gia='git add' | ||
149 | alias giA='git add --patch' | ||
150 | alias gid='git diff --cached' | ||
151 | alias giD='git diff --cached --word-diff' | ||
152 | |||
153 | # Log (l) | ||
154 | logMediumFormat='%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' | ||
155 | logBriefFormat='%C(green)%h%C(reset) %s%n%C(blue)(%ar by %an)%C(red)%d%C(reset)%n' | ||
156 | logOnelineFormat='%C(green)%h%C(reset) %s%C(red)%d%C(reset)%n' | ||
157 | |||
158 | alias gl='git log --topo-order --pretty=format:"${logMediumFormat}"' | ||
159 | alias gls='git log --topo-order --stat --pretty=format:"${logMediumFormat}"' | ||
160 | alias gld='git log --topo-order --stat --patch --full-diff --pretty=format:"${logMediumFormat}"' | ||
161 | alias glg='git log --topo-order --all --graph --pretty=format:"${logOnelineFormat}"' | ||
162 | alias glo='git log --topo-order --pretty=format:"${logOnelineFormat}"' | ||
163 | alias glb='git log --topo-order --pretty=format:"${logBriefFormat}"' | ||
164 | alias glc='git shortlog --summary --numbered' | ||
165 | |||
166 | # Merge (m) | ||
167 | alias gm='git merge' | ||
168 | alias gmt='git mergetool' | ||
169 | |||
170 | # Push (p) | ||
171 | alias gp='git push' | ||
172 | alias gpf='git push --force-with-lease' | ||
173 | alias gpt='git push --tags' | ||
174 | |||
175 | # Rebase (r) | ||
176 | alias gr='git rebase' | ||
177 | |||
178 | # Stash (s) | ||
179 | alias gs='git stash' | ||
180 | |||
181 | # Working Copy (w) | ||
182 | alias gws='git status --ignore-submodules=none' | ||
183 | alias gwd='git diff' | ||
184 | alias gwD='git diff --word-diff' | ||
185 | |||
186 | # }}} | ||
187 | |||
188 | # Prevents some mistakes | ||
189 | alias cp='cp -i' | ||
190 | alias mv='mv -i' | ||
191 | alias rm='rm -i' | ||
192 | |||
193 | # }}} | ||
194 | |||
195 | # Helpful functions {{{ | ||
196 | # ===================== | ||
197 | |||
198 | function ssht | ||
199 | { | ||
200 | /usr/bin/env ssh -t "$@" "tmux new-session -A -s 'ssh-$HOST'" | ||
201 | } | ||
202 | |||
203 | compdef 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 | |||
214 | abk=( | ||
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 | ||