-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
211 lines (191 loc) · 6.32 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
autoload -Uz compinit && compinit
uname=`uname`
# set up SPEAKER, BROWSER and TERM for HPUX
if test $uname = "HP-UX" ; then
export SPEAKER=external
export BROWSER=/usr/local/bin/netscape
if test $TERM = "xterm" ; then
export TERM=dtterm
fi
# If the linux box set DISPLAY to "unix:0.0" unset it!
elif test $uname = "Linux" ; then
if test -n "$DISPLAY" -a "$DISPLAY" = "unix:0.0" ; then
unset DISPLAY
fi
# set up MOZILLA_HOME for AIX
elif test $uname = "AIX" ; then
export MOZILLA_HOME=/usr/netscape
elif test $uname = "SunOS" ; then
export XKEYSYMDB='/usr/dt/appconfig/netscape/XKeysymD'
fi
# Set up INITIALS for use with Tom's .vimrc
if test -n `which ldapsearch` ; then
export INITIALS=`ldapsearch -Z -x \(uid=${USER}\) initials 2>/dev/null | grep ^initials: | cut -f2 -d" "`
fi
if test -z "${INITIALS}" ; then
export INITIALS="${USER}"
fi
if test $uname = "FreeBSD" -o $uname = "Darwin" ; then
shorthostname=`hostname -s`
else
shorthostname=`echo ${HOST} | sed 's/\([^.]*\).*/\1/'`
fi
# set up REMOTEHOST based on SSH_CLIENT if REMOTEHOST not already set!
if test -n "$SSH_CLIENT" -a -z "$REMOTEHOST" ; then
export REMOTEHOST="`echo ${SSH_CLIENT} | cut -f1 -d' '`"
fi
# ssh-agent setup
if test $uname != "Darwin" ; then
sshagentfile=$HOME/.ssh.zsh.`hostname`
if test -f $sshagentfile ; then
. $sshagentfile
uid=`id -u ${USER}`
testpid=`pgrep -u $uid ssh-agent | grep $SSH_AGENT_PID`
if test -n "$testpid" && test `echo $SSH_AGENT_PID` = `echo $testpid` ; then
echo "Using ssh-agent with PID: $SSH_AGENT_PID"
else
echo "Starting new ssh-agent, old one was stopped"
rm -f $sshagentfile
ssh-agent -s > $sshagentfile
. $sshagentfile
fi
unset uid
unset testpid
else
ssh-agent -s > $sshagentfile
. $sshagentfile
fi
unset sshagentfile
fi
# Command prompt
autoload -Uz vcs_info
function precmd_vcs_info() {
vcs_info
if test -n "${VIRTUAL_ENV}" ; then
PROMPT_PREFIX="%F{green}%B(`basename ${VIRTUAL_ENV}`) %b%f"
else
PROMPT_PREFIX=""
fi
}
precmd_functions+=( precmd_vcs_info )
setopt prompt_subst
if test "${USER}" = "franc" ; then
PROMPT=\$PROMPT_PREFIX$'%~ '\$vcs_info_msg_0_$'
Yes, master?'
else
PROMPT=\$PROMPT_PREFIX$' '\$vcs_info_msg_0_$' [%m:%~]%#'
fi
zstyle ':vcs_info:*' stagedstr ' [Staged Changes]'
zstyle ':vcs_info:*' unstagedstr ' [Unstaged Changes]'
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' check-for-staged-changes true
zstyle ':vcs_info:*' formats '%F{yellow}(%s)-[%b]%F{white}'
zstyle ':vcs_info:git:*' formats '%F{yellow}[%b]%c%u%F{white}'
zstyle ':vcs_info:hg:*' formats '%F{yellow}(%s)-[%b]%c%u%F{white}'
function precmd() {
print -Pn "\e]2;${USER}@${shorthostname} %~\a"
}
function zle-line-init zle-keymap-select {
VIMPROMPT="%F{yellow}%B[% NORMAL]% %b%f "
PROMPT_RIGHT="${${KEYMAP/vicmd/$VIMPROMPT}/(main|viins)/}"
if test "${USER}" = "franc" ; then
PROMPT=\$PROMPT_RIGHT\$PROMPT_PREFIX$'%~ '\$vcs_info_msg_0_$'
Yes, master?'
else
PROMPT=\$PROMPT_PREFIX$' '\$vcs_info_msg_0_$' [%m:%~]%#'
fi
zle reset-prompt
}
zle -N zle-line-init
zle -N zle-keymap-select
# Aliases
if alias ls>/dev/null ; then
# Clear any alias for ls!
unalias ls
fi
lsversion=`ls --version 2>/dev/null | grep GNU`
if test -n "${lsversion}"; then
alias ls='ls --color=never'
fi
alias vi=vim
if test $uname = "Darwin" ; then
alias ldd="otool -L"
else
# Work around bug in xterms on macos via ssh
if test -n "$SSH_CLIENT" ; then
alias vi="vim -u /home/franc/.vimrc"
fi
fi
alias h=history
alias j="jobs -l"
#alias larger "echo ']50;#+'"
#alias smaller "echo ']50;#-'"
#alias normal "echo ']50;#'"
#alias extralarge 'larger ; larger ; larger ; larger'
#alias pushtophone "obexapp -a 00:07:e0:f1:83:8f -c -C OPUSH"
# STTY
stty intr ^C
stty kill
#stty erase
# Improved 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 "[A" up-line-or-beginning-search
bindkey "[B" down-line-or-beginning-search
bindkey -M vicmd "k" up-line-or-beginning-search
bindkey -M vicmd "j" down-line-or-beginning-search
# Set options
setopt AUTO_PUSHD PUSHD_IGNORE_DUPS PUSHD_SILENT
setopt CSH_JUNKIE_HISTORY CSH_NULL_GLOB
setopt CLOBBER
HISTFILE=~/.zsh_history
HISTSIZE=1000
SAVEHIST=$HISTSIZE
setopt APPEND_HISTORY INC_APPEND_HISTORY HIST_IGNORE_DUPS
# if CLOBBER is set, this one makes no sense
#setopt HIST_ALLOW_CLOBBER
setopt HIST_REDUCE_BLANKS HIST_NO_STORE HIST_BEEP HIST_FCNTL_LOCK
# This next option isn't set for now, as it's unlikely I'll need it
#setopt HIST_LEX_WORDS
#
setopt AUTO_LIST LIST_AMBIGUOUS BAD_PATTERN
#setopt listmaxrows=3
setopt EQUALS NO_GLOB_DOTS MARK_DIRS
# RE_MATCH_PCRE isn't available on macos, and might not be useful to me,
# so don't enable it for now
#setopt RE_MATCH_PCRE
# Disable start/stop characters!
setopt NO_FLOW_CONTROL IGNORE_EOF NO_BG_NICE
# Make sure we have ssh keys!
if ! test -f ~/.ssh/id_ed25519 ; then
echo "Creating ED25519 SSH key"
hostname=`hostname`
ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519 -C "${USER}@${hostname}-ed25519"
fi
if ! test -f ~/.ssh/id_rsa ; then
echo "Creating RSA SSH key"
hostname=`hostname`
ssh-keygen -o -a 100 -b 4096 -t rsa -f ~/.ssh/id_rsa -C "${USER}@${hostname}-rsa"
fi
# TODO: Set for your environment!
BACKUPDIR=""
if test $uname = "Darwin" ; then
BACKUPDIR=""
fi
if ! test -f ~/.ssh/authorized_keys && test -r ${BACKUPDIR}/${USER}.ssh/authorized_keys; then
echo "Copied a new authorized_keys file from ${BACKUPDIR}/${USER}/.ssh/authorized_keys"
cp ${BACKUPDIR}/${USER}.ssh/authorized_keys ~/.ssh
fi
if test -f ~/.ssh/authorized_keys -a -f ${BACKUPDIR}/${USER}.ssh/authorized_keys -a ${BACKUPDIR}/${USER}.ssh/authorized_keys -nt ~/.ssh/authorized_keys ; then
echo "Updated authorized_keys from ${BACKUPDIR}/${USER}/.ssh/authorized_keys"
mv ~/.ssh/authorized_keys ~/.ssh/authorized_keys.old.`date +"%s"`
cp ${BACKUPDIR}/${USER}.ssh/authorized_keys ~/.ssh
fi
# Make sure we have a .forward file
if ! test -s ~/.forward -o -L ~/.forward ; then
rm -f ~/.forward
# TODO: Set for your environment!
echo "${USER}@MAILHOST" > ~/.forward
fi