This repository has been archived by the owner on Oct 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc
302 lines (234 loc) · 6.96 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#!/usr/bin/env zsh
export DOTFILES=~/dot
source ${DOTFILES}/zsh/suggestions.zsh
source ${DOTFILES}/zsh/highlight.zsh
source ${DOTFILES}/zlerc # terminal cursor keybindings
source ${DOTFILES}/env # tokens
export HISTFILE=~/.hist/zsh
HISTSIZE=10000
SAVEHIST=10000
zstyle ':completion:*' menu select
zstyle ':completion:*' completer _complete
zstyle ':completion:*' matcher-list '' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' '+l:|=* r:|=*'
autoload -U compinit && compinit
zmodload -i zsh/complist
unsetopt menu_complete
unsetopt flowcontrol
setopt prompt_subst
setopt always_to_end
setopt append_history
setopt auto_menu
setopt complete_in_word
setopt extended_history
setopt hist_expire_dups_first
setopt hist_ignore_dups
setopt hist_ignore_space
setopt hist_verify
setopt inc_append_history
setopt interactivecomments
setopt share_history
bindkey -e
bindkey '^a' beginning-of-line
bindkey '^e' end-of-line
# move into directory by typing its name w/o `cd`
setopt autocd autopushd
vim_prompt() {
if [ ! -z $VIMRUNTIME ]; then
echo ":%F{green}sh ";
fi
}
# List directory contents on entry
fn_cd() {
if [ $# -eq 1 ]; then cd $1 && ls;
else cd && ls;
fi
}
# to test new prompts, use:
# print -P '%B%F{red}co%F{green}lo%F{blue}rs%f%b'
# for 0-255 xterm color scale reference:
# https://upload.wikimedia.org/wikipedia/commons/1/15/Xterm_256color_chart.svg
# Add a custom alias for restarting sshd
sshdr() {
if [[ $(uname -s) == 'Linux' ]]; then
sudo systemctl restart ssh
elif [[ $(uname -s) == 'Darwin' ]]; then
sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist
fi
}
# A. Traver
myip() {
local public="$(curl -s https://checkip.amazonaws.com)"
local private
if [[ $(uname -s) == 'Darwin' ]]; then
private="$(ipconfig getifaddr en0)"
elif [[ $(uname -s) == 'Linux' ]]; then
private="$(hostname -I | awk '{print $1}')"
else
echo "Error: unknown operating system" >&2
return 1
fi
echo "Public IP: ${public}"
echo "Private IP: ${private}"
return 0
}
# Set vi as the default editor
VISUAL="vim"
EDITOR="vim"
PAGER="less"
# Call the function to set the path, without adding new variables to the shell
# setpath
# Make a directory to store history for various consoles
mkdir -p ~/.hist
# Configure history file locations
export LESSHISTFILE=~/.hist/less
export INPUTRC=${DOTFILES}/inputrc
export HUB_CONFIG=${DOTFILES}/hub/config
export XDG_CONFIG_HOME=${DOTFILES}
export HOME=~
export PRACTICE_CPP_LEETCODE=~/projects/practice/cpp/leetcode
export NOTES_DIR=~/Nextcloud/notes/
export CS350_DOCKER_PROJECT=~/projects/cs350/project-4-cdurham_lee344/xv6-public/
export CP_PRACTICE=~/projects/practice/cp_problems
export ITP439=~/projects/uscc-camerondurham
eval "$(hub alias -s)"
# Disable <C-q> & <C-s>
stty -ixon
# Export environment variables
# Enable support for GPG encryption of echo command
export GPG_TTY=$(tty)
# Configure environments that can be CD'd into at all times
export CDPATH=.:$HOME:~/site:$HOME/projects:$HOME/dot:$HOME/Nextcloud/notes:$HOME/projects/practice:
# Add my shitty little run script to the path despite it being brittle & lazy
export PATH="/Users/camerondurham/projects/cs350-docker/run.sh:$PATH"
# Add anaconda to path
export PATH="/usr/local/anaconda3/bin:$PATH"
# Add ruby to path
export PATH="/Users/camerondurham/.gem/ruby/2.6.0/bin:$PATH"
# Add gopath to path
export PATH="$HOME/go/bin:$PATH"
# Add rust to system path
export PATH="$HOME/.cargo/bin:$PATH"
# Add Rust completion engine RACER to path
RUST_SRC_PATH=/usr/local/src/rust/src
# Add LLVM first in path
export PATH="/usr/local/opt/llvm/bin:$PATH"
# To use the bundled libc++ please add the following LDFLAGS:
LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
# Tell compilers how to find llvm
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"
export GOPATH=~/go
export GNUPGHOME=~/.gpg
# Colorize man pages via termcap capabilities
# `https://linux.die.net/man/5/termcap`
# md : start bold-mode (bold & red)
export LESS_TERMCAP_md=$(printf "\x1b[1;31m")
# mh : start faded-mode
export LESS_TERMCAP_mh=$(printf "\x1b[2m")
# mb : start blinking-mode (blinking & yellow)
export LESS_TERMCAP_mb=$(printf "\x1b[5;33m")
# so : start standout-mode
export LESS_TERMCAP_so=$(printf "\x1b[7;44;33m")
# se : end standout-mode
export LESS_TERMCAP_se=$(printf "\x1b[0m")
# us : start italic-mode
export LESS_TERMCAP_us=$(printf "\x1b[1;3;32m")
# ue : end italic-mode
export LESS_TERMCAP_ue=$(printf "\x1b[0m")
# me : disable all modes (md, mb, mr, so, us)
export LESS_TERMCAP_me=$(printf "\x1b[0m")
# Colorize BSD ls
CLICOLOR=1
LSCOLORS='ExGxFxdxCxDxDxHBhDhCgC'
# Launch the GPG agent, unless one is already running
gpg-agent --daemon &>/dev/null
# Identifies the path of a UNIX-domain socket
# Used to communicate with the SSH agent
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
# Colorize directory listings
ls() {
if [[ $(uname -s) == 'Darwin' ]]; then
if [[ -x /usr/local/opt/coreutils/libexec/gnubin/ls ]]; then
/usr/local/opt/coreutils/libexec/gnubin/ls --color=auto "$@"
else
/bin/ls "$@"
fi
elif [[ $(uname -s) == 'Linux' ]]; then
/bin/ls --color=auto "$@"
else
ls
fi
}
# Toggle Vim session (or last suspended process) with Ctrl-Z
function fg-bg () {
if [[ $BUFFER -eq 0 ]]; then
fg
else
zle push-input
fi
}
zle -N fg-bg
bindkey '^Z' fg-bg
# Create new notes in vim:
# zet a new note -> ~/Dropbox/notes/<TIMESTAMP>-a-new-note.md
zet() {
nvim "+Zet $*"
}
# Edit new leetcode:
# lc 0982 some little problem -> ~/projects/practice/cpp/leetcode/0982_some_little_problem.cpp
lc() {
nvim "+LC $*"
}
# Edit new competitive programming problem
ccp() {
nvim "+CCP $*"
}
# Add dynamic git aliases shamelessly copied from thoughtbot
# No arguments: `git status`
# With arguments: acts like `git`
g() {
if [[ $# > 0 ]]; then
git $@
else
git status
fi
}
export NOTES=$HOME/Nextcloud/notes
# get filename for today's notes
# open in other editors with `code $(ttf)`
ttf() {
local datefmt
datefmt=$(date +"%Y-%m-%d")
local notespath
notespath=${NOTES:-$backup_notes_path}
local filename
filename="TODO_$datefmt.md"
filepath="$notespath/$filename"
nvim "$filepath"
echo "$filepath"
}
# todo today
tt() {
local filepath
filepath=$(ttf)
vim "$filepath"
}
export SNIP=$NOTES/useful-snippets.md
# snippets
ss() {
if [[ ! -z "$NOTES" ]] && [[ ! -z "$SNIP" ]]; then
nvim "$SNIP"
echo "edited snippets: $SNIP"
else
echo "NOTES envvar not set, cannot edit snippets!"
fi
}
# Complete go like git
compdef g=git
# source aliases after function definitions
[ -f "${DOTFILES}/aliasrc" ] && source "${DOTFILES}/aliasrc" # aliases
export PATH="/usr/local/share/python/:$PATH"
export PATH="/usr/local/opt/python@3.8/bin:$PATH"
export PATH="/usr/local/opt/sqlite/bin:$PATH"
export PATH="$PATH:/Users/camerondurham/ch-darwin-amd64"