forked from jameslikeslinux/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc.erb
157 lines (132 loc) · 4.05 KB
/
.zshrc.erb
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
# Check for newer local version of zsh
autoload -U is-at-least
if ! is-at-least 5.2; then
for zsh in $HOME/local/bin/zsh; do
[[ -x $zsh ]] && exec $zsh
done
fi
# /etc/zsh/zprofile overwrites stuff set in .zshenv
# This is kind of a hack, but not that big of a deal
[[ -e /etc/zsh/zprofile ]] && source $HOME/.zshenv
# My only FreeBSD system, pfSense, doesn't really support unicode
if [[ $OSTYPE == freebsd* ]]; then
export TERM="${TERM%-powerline}"
fi
<% require 'colorscheme'
cs = ColorScheme.dark
xterm_escapes = cs.terminal.map do |c|
"\\e]4;#{c.ansi};#{c.x11}\\a"
end.join
xterm_escapes += "\\e]10;#{cs.foreground.x11}\\a"
xterm_escapes += "\\e]11;#{cs.background.x11}\\a"
xterm_escapes += "\\e]12;#{cs.cursor.x11}\\a"
linux_escapes = cs.console.map do |c|
'\e]P%x%s' % [c.ansi, c.hex]
end.join -%>
if [[ $TERM == *256color* && $TERM != tmux* ]]; then
# Configure color palette on modern terminals
print -Pn '<%= xterm_escapes %>'
elif [[ $TERM == 'linux' && -o login && ! $SSH_CONNECTION ]]; then
# Set Linux console color palette. See console(4).
print -Pn '<%= linux_escapes %>'
clear
fi
# Run tmux if it's not running. I don't exec 't' because if tmux is
# unavailable, then it will return a non-zero exit code and zsh will
# continue as a fallback; and when tmux does run and exits cleanly, I
# still want ~/.zlogout evaluated.
if [[ ! $TMUX ]]; then
t 2>/dev/null && exit
fi
# XXX: Rename histfile
if [[ -f ~/.histfile.$HOST && ! -f ~/.history.$HOST ]]; then
mv -f ~/.histfile.$HOST ~/.history.$HOST
elif [[ -f ~/.histfile.$HOST ]]; then
rm -f ~/.histfile.$HOST
fi
# History settings
HISTFILE=~/.history.$HOST
HISTSIZE=10000
SAVEHIST=10000
setopt inc_append_history
if [[ ! -e $HISTFILE ]]; then
touch $HISTFILE
chmod 600 $HISTFILE
fi
if [[ ! -w $HISTFILE ]]; then
echo
echo "HISTFILE is not writable..."
echo "Run \"s chown $USER:$(id -gn) $HISTFILE\" to fix."
echo
fi
# Restore default redirect behavior
setopt clobber
# Enable vi keybindings
bindkey -v
# Make mode switches faster
export KEYTIMEOUT=1
# Enable history commands from emacs mode
# (just too useful)
bindkey '^P' up-history
bindkey '^N' down-history
bindkey '^R' history-incremental-pattern-search-backward
bindkey '^S' history-incremental-pattern-search-forward
stty -ixon # make ^S available to shell
# Show user name at prompt if not one of my usual ones
zstyle ':prompt:mine' hide-users '(james|jlee|jtl|root)'
# Figure out if I'm running as a priviliged user
if [[ $EUID == 0 ]]; then
zstyle ':prompt:mine' root true
fi
if [[ $OS == 'Windows_NT' ]] && id -Gnz | tr '\0' '\n' | grep -q '^Administrators$'; then
zstyle ':prompt:mine' root true
fi
# Figure out if I'm running with Glue admin rights
if [[ -x $(whence klist) ]] && klist 2>&1 | grep jtl/admin > /dev/null; then
zstyle ':prompt:mine' admin true
fi
# Fallback to flat appearance if using a stupid terminal
if [[ $TERM != *powerline* ]]; then
zstyle ':prompt:mine' flat true
fi
# Enable my command prompt
autoload -U promptinit && promptinit
prompt mine
# Enable command autocompletion
autoload -U compinit && compinit -u
# Color list autocompletion
if [[ -x $(whence dircolors) ]]; then
eval $(dircolors)
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
fi
# Aliases
ls --help 2>&1 | grep -- '--color' > /dev/null && alias ls='ls --color'
alias vi="$EDITOR"
unalias cp 2>/dev/null
alias mv='mv -f'
alias rm='rm -f'
alias r='eval "$(t show-environment -s)" && TERM="${${(s/ /)$(t show-options -s default-terminal)}[2]//\"/}" && exec $SHELL'
alias bigsnaps='zfs list -t snapshot -s used'
unalias suafs 2>/dev/null
unalias a 2>/dev/null
compdef a=sudo
compdef s=sudo
compdef t=tmux
compdef glue=ssh
alias j='ssh -J stowe.umd.edu'
compdef j=ssh
# Easy way to switch to project
p() {
cd "${HOME}/projects/${1}" && ls
}
compdef "_files -W ${HOME}/projects" p
# Set standard umask
if [[ $OS == 'Windows_NT' ]]; then
umask 002
else
umask 022
fi
# Glue polutes my shell
# (for some reason these have to go here, not .zshenv)
unset LESS LESSOPEN
# vim:ft=zsh