-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
189 lines (139 loc) · 4.97 KB
/
.zshrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
###############################################################################
## Autocomplete
###############################################################################
autoload -Uz compinit
compinit
# generate descriptions for auto completion
zstyle ':completion:*' auto-description 'specify: %d'
# allows navigation through options with arrow keys
zstyle ':completion:*' menu yes select
zstyle ':completion:*:*:cd:*' menu yes select
unsetopt LIST_AMBIGUOUS
setopt COMPLETE_IN_WORD
###############################################################################
## History
###############################################################################
HISTSIZE=1000000
SAVEHIST=1000000
HISTFILE="$HOME/.zsh_history"
setopt SHARE_HISTORY
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_SPACE
setopt EXTENDED_HISTORY
bindkey '^r' fzf-history-widget # [Ctrl-r] - Search backward incrementally
###############################################################################
## Options
###############################################################################
export TERM="xterm-256color"
# pipe to multiple outputs
setopt MULTIOS
# Spell check commands
setopt CORRECT
# 10 second wait on 'rm *'
setopt RM_STAR_WAIT
# use magic
setopt ZLE
setopt NO_HUP
setopt VI
# Editor
export EDITOR="vim"
setopt IGNORE_EOF
# type 'dir' instead of 'cd dir'
setopt AUTO_CD
# ctrl-w, alt-b (etc.) stop at chars like `/:` instead of just space
autoload -U select-word-style
select-word-style bash
###############################################################################
## Aliases & hashes
###############################################################################
# shell
alias ls='exa -al' # ls replaced with exa, which is faster and in colour
alias mkdir='mkdir -pv' # create parent dirs, visually
# always ssh with agent forwarding
alias ssh='ssh -A'
# system
alias ps='ps auxf' # process list in detail
# find, replace
alias hgrep='history | grep'
# searches by process name, excluding this command
alias psgrep='ps aux | grep -v grep | grep -i -e VSZ -e'
alias grep='grep --color'
# always whois without legal disclaimer
alias whois='whois -H'
# copy stdout to visual clipboard
alias clip='xclip -selection clipboard'
# screen brightness
alias linc='~/.config/i3/brightness.sh --inc'
alias ldec='~/.config/i3/brightness.sh --dec'
lit () { sudo bash -c "echo $1 > /sys/class/backlight/intel_backlight/brightness" }
# git aliases
git config --global alias.adog 'log --all --decorate --oneline --graph'
git config --global alias.last 'log -1 HEAD'
git config --global alias.undo 'reset --soft HEAD~'
# yubikey
alias copy_key="ssh-add -L | clip"
alias unlock_ykey="ssh-add -e /usr/lib/x86_64-linux-gnu/libykcs11.so; ssh-add -s /usr/lib/x86_64-linux-gnu/libykcs11.so"
# other
alias zshrc='vim ~/.zshrc'
alias zshsrc='source ~/.zshrc'
alias vimrc='vim ~/.vimrc'
alias i3conf='vim ~/.config/i3/config'
alias pvpn='sudo protonvpn'
alias pvpnr='pvpn d && pvpn c -f'
# type ~name to access directory
hash -d dl=/home/$(whoami)/Downloads
hash -d c=/home/$(whoami)/code
###############################################################################
## Shortcuts
###############################################################################
# Alt-S inserts 'sudo' at beginning of line
insert_sudo () { zle beginning-of-line; zle -U "sudo " }
zle -N insert-sudo insert_sudo
bindkey "^[s" insert-sudo
###############################################################################
## Other
###############################################################################
# Draw a Mandelbrot!
function mandelbrot {
local lines columns colour a b p q i pnew
((columns=COLUMNS-1, lines=LINES-1, colour=0))
for ((b=-1.5; b<=1.5; b+=3.0/lines)) do
for ((a=-2.0; a<=1; a+=3.0/columns)) do
for ((p=0.0, q=0.0, i=0; p*p+q*q < 4 && i < 32; i++)) do
((pnew=p*p-q*q+a, q=2*p*q+b, p=pnew))
done
((colour=(i/4)%8))
echo -n "\\e[4${colour}m "
done
echo
done
}
###############################################################################
## SSH
# http://mah.everybody.org/docs/ssh
###############################################################################
SSH_ENV="$HOME/.ssh/environment"
function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add;
}
# Source SSH settings, if applicable
if [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}" > /dev/null
ps -e | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_agent;
}
else
start_agent;
fi
###############################################################################
## Path
###############################################################################
export PATH="/home/share/appimg:$PATH"
## fzf
source ~/.zsh/fzf-tab/fzf-tab.plugin.zsh
source /usr/share/doc/fzf/examples/key-bindings.zsh