-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
247 lines (207 loc) · 6.02 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
#!/usr/bin/zsh
#
# Jason Blevins <jblevins@xbeta.org>
# Carrboro, November 16, 2008
### Basic ZSH Configuration
# history
HISTFILE=~/.zsh_history
HISTSIZE=5000
SAVEHIST=1000
unsetopt SHARE_HISTORY
unsetopt INC_APPEND_HISTORY
setopt APPEND_HISTORY # Append commands to history when a shell exits
setopt HIST_SAVE_NO_DUPS
# Emacs keybindings (-v for vi)
bindkey -e
# settings
setopt autocd # cd by typing directory name
setopt hist_ignore_dups # ignore repeated commands
setopt nobeep # stop yelling at me
# set common environment variables
export EDITOR="$HOME/bin/EDITOR" # default editor
# tab completion
autoload -U compinit
compinit -d $ZCOMPDUMP
# zmv
autoload zmv
# colorful completion listings
zmodload -i zsh/complist
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# Special characters that are to be considered part of words.
# Default: WORDCHARS="*?_-.[]~=&;!#$%^(){}<>/"
WORDCHARS="*?[]~&;!%^(){}<>"
### Git
alias ga='git add'
alias gap='git add --patch'
alias gb='git branch -a'
alias gc='git commit -v'
alias gcm='git commit -m'
alias gca='git commit -v --amend'
alias gcan='git commit -v --amend --no-edit'
alias gcb='git checkout -b'
alias gcm='git checkout master'
alias gcn='git checkout next'
alias gd='git diff'
alias gdc='git diff --cached'
alias gdw='git diff --word-diff'
alias gitx='open -a GitX .'
alias gpl='git plog'
alias grl='git rlog'
alias gst='git status'
alias gm='git merge'
alias gri='git rebase -i'
alias grim='git rebase -i master'
alias gsts='git stash show --patch'
alias gstp='git stash pop'
alias gstd='git stash drop'
alias gli='git ls-files . --ignored --exclude-standard --others'
### Useful Commands and Aliases
if ls -F --color=auto >&/dev/null; then
if whence dircolors >/dev/null; then
eval "$(dircolors -b)"
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
alias ls="ls --color=auto -F"
else
export CLICOLOR=1
zstyle ':completion:*:default' list-colors ''
alias ls="ls -F"
fi
else
alias ls="ls -F"
fi
alias grep='grep --color=auto'
alias less='less -R'
alias make='make -j'
if whence lsd >/dev/null; then
alias l='lsd -alh --git'
alias ll='lsd -alh --git'
alias lh='lsd -alh --git'
alias lr='lsd -talhr --git'
alias lsd='lsd -alhd --git */'
alias k='lsd -alh --git'
else
alias l='ls -l'
alias ll='ls -l'
alias lh='ls -alh'
alias lr='ls -talr'
alias lsd='ls -d */'
alias k='ls -alh'
fi
alias bc='bc -l'
alias ee="emacs -nw"
alias ec="emacsclient"
alias acs='apt-cache search'
alias acsn='apt-cache search --names-only'
alias mutt="cd ~/inbox; mutt"
alias sdr="screen -d -R"
alias tma="tmux attach -t default || tmux new -s default"
alias latexmk="latexmk -g -synctex=1 -pdf -pvc"
# Protect OS X tags
# http://brettterpstra.com/2014/07/03/mavericks-tags-and-coreutils-a-warning/
alias mv=/bin/mv
alias cp=/bin/cp
# SSH shortcuts
alias ss1="ssh ap-jb01"
alias ssm="ssh blevins-mac"
alias ssg="ssh gauss"
alias ssl="ssh leibniz"
# duf: human readable, sorted disk usage
# http://www.earthinfo.org/linux-disk-usage-sorted-by-size-and-human-readable/
alias duf='du -sk * | sort -nr | perl -ne '\''($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}'\'
# dnf: human readable, sorted file counts
alias dnf='find . -maxdepth 1 -type d | sed -e "s/^.\///" | while read -r dir; do num=$(find "$dir" -type f | wc -l); printf "%d\t%s\n" "$num" "$dir"; done | sort -nr'
# Clean up after latex
alias latexclean='for ext in aux log bbl brf blg toc dvi fls fdb_latexmk synctex.gz out nav snm fff ttt vrb; do rm -f *.$ext; done'
# Suffix Aliases
alias -s c=vim
alias -s f90=vim
alias -s txt=vim
alias -s tex=vim
alias -s text=vim
alias -s html=elinks
alias -s com=elinks
alias -s net=elinks
alias -s org=elinks
### Prompt
autoload -U colors
colors
setopt prompt_subst
# Configuration
DEFAULT_USER='jblevins'
# Context: user@hostname
prompt_context() {
local user=`whoami`
local context="%m"
if [[ $UID -ne 0 && "$user" != "$DEFAULT_USER" ]]; then
context="$user@$context"
fi
echo -n "$context"
}
# Git branch and status
prompt_git() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
branch="${ref/refs\/heads\//}$dirty"
echo -n "%{$fg[yellow]%} :$branch"
# if [[ -n $(git status -s 2> /dev/null) ]]; then
# echo -n "%{$fg[red]%} :$branch"
# else
# echo -n "%{$fg[yellow]%} :$branch"
# fi
}
# Prompt symbol
prompt_symbol() {
if [[ $UID -ne 0 ]]; then
echo -n "%"
else
echo -n "#"
fi
}
PROMPT='%{$fg[green]%}$(prompt_context) %{$fg[blue]%}%~$(prompt_git) %{$reset_color%}%$(prompt_symbol) '
# Fix for TRAMP
[[ $TERM == "dumb" ]] && unsetopt zle && PS1='$ '
# Set the xterm title
if [[ $TERM == "xterm" ]]; then
print -Pn "\e]2;$USER@$HOST\a"
fi
### SSH
# SSH Agent (http://www.cygwin.com/ml/cygwin/2001-06/msg00537.html)
SSH_ENV="$HOME/.ssh-agent.$HOST"
function start_agent {
echo -n "Initializing SSH agent..."
ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo " OK"
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add --apple-use-keychain;
}
# Source SSH settings
if [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}" > /dev/null
ps -x | grep ${SSH_AGENT_PID} | grep ssh-agent > /dev/null || {
start_agent;
}
else
start_agent;
fi
### Per-Directory ZSH configuration
function chpwd() {
if [ -r $PWD/.zsh_config ]; then
source $PWD/.zsh_config
fi
}
# zsh-autosuggestions
source ~/.zsh/zsh-autosuggestions.zsh
export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=1'
# Archival
compress_and_delete () { tar zcvf "$1.tar.gz" "$1" && rm -rf "$1" }
# History search
autoload -U up-line-or-beginning-search
autoload -U down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey "^P" up-line-or-beginning-search
bindkey "^N" down-line-or-beginning-search
bindkey "\e[A" up-line-or-beginning-search
bindkey "\e[B" down-line-or-beginning-search
# Added by LM Studio CLI (lms)
export PATH="$PATH:/Users/jblevins/.cache/lm-studio/bin"