summaryrefslogtreecommitdiff
path: root/zshrc
blob: 3288fb7d1a25f7ddeec055246bf1236beb1ede64 (plain)
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
#! /bin/false

if [ -e /etc/zsh/zshenv ]; then
	. /etc/zsh/zshenv
fi

HOSTNAME="`hostname`"
SYSTEM="`uname -s`"
ARCH="`uname -m`"

case "$TERM" in
	linux)	# Linux console
		bindkey '\e[1~' beginning-of-line	# Home 
		bindkey '\e[4~' end-of-line		# End  
		bindkey '\e[3~' delete-char		# Del
		bindkey '\e[2~' overwrite-mode		# Insert  
		;;
	screen) # The textmode window manager
		# In Linux console
		bindkey '\e[1~' beginning-of-line	# Home
		bindkey '\e[4~' end-of-line		# End  
		bindkey '\e[3~' delete-char		# Del
		bindkey '\e[2~' overwrite-mode		# Insert  
		bindkey '\e[7~' beginning-of-line	# home
		bindkey '\e[8~' end-of-line		# end
		# In rxvt
		bindkey '\eOc' forward-word		# ctrl cursor right
		bindkey '\eOd' backward-word		# ctrl cursor left
		bindkey '\e[3~' backward-delete-char	# This should not be necessary!
		;;
	rxvt)
		bindkey '\e[7~' beginning-of-line	# home
		bindkey '\e[8~' end-of-line		# end
		bindkey '\eOc' forward-word		# ctrl cursor right
		bindkey '\eOd' backward-word		# ctrl cursor left
		bindkey '\e[3~' backward-delete-char	# This should not be necessary!
		bindkey '\e[2~' overwrite-mode		# Insert
		;;
	xterm*)
		bindkey '\e[H' beginning-of-line	# Home
		bindkey '\e[F'  end-of-line		# End
		bindkey '\e[3~' delete-char		# Del
		bindkey '\e[2~' overwrite-mode		# Insert
		bindkey "^[[5C"   forward-word          # ctrl cursor right
		bindkey "^[[5D"   backward-word         # ctrl cursor left
		
		;;
	sun)
		bindkey '\e[214z' beginning-of-line       # Home
		bindkey '\e[220z' end-of-line             # End
		bindkey '^J'      delete-char             # Del
		bindkey '^H'      backward-delete-char    # Backspace
		bindkey '\e[247z' overwrite-mode          # Insert
		;;
esac

#######################################################################
#######################################################################
# SETUP ENVIRONMENT AND OPTIONS
#######################################################################
#######################################################################

setopt \
	extendedglob \
	list_types \
	nocorrect \
	list_ambiguous \
	bash_auto_list \
	list_packed \
	interactive_comments \
	nohup \
	autocd \
	CHECK_JOBS \
	BG_NICE \
	APPEND_HISTORY \
	INC_APPEND_HISTORY \
	HIST_IGNORE_DUPS \
	EXTENDED_GLOB \
	HIST_FIND_NO_DUPS \
	HIST_IGNORE_SPACE \

# init colors:
setopt PROMPTSUBST
autoload colors zsh/terminfo
if [[ "$terminfo[colors]" -ge 8 ]]; then
	colors
fi
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
	eval PR_$color='%{$fg[${(L)color}]%}'
	(( count = $count + 1 ))
done
PR_BOLD="%{$terminfo[bold]%}"
PR_NO_COLOUR="%{$terminfo[sgr0]%}"


# in 'foo bar | baz' make a second ^W not eat 'bar |', but only '|'
# this has the disadvantage that in 'bar|baz' it eats all of it.
typeset WORDCHARS='|'$WORDCHARS

HISTFILE=~/.zsh_history
HISTSIZE=50000
SAVEHIST=50000
TIMEFMT="$fg[magenta]%J  %U user  %S sys  %P cpu  %*E total  %M kB max$terminfo[sgr0]"
REPORTTIME=5

watch=(notme)             # watch for everybody but me
LOGCHECK=300              # check every 5 min for login/logout activity
WATCHFMT='%n %a %l from %m at %t.'

[ -x /usr/bin/lesspipe ] && eval `lesspipe`


unset LANG
export DEBEMAIL="weasel@debian.org"

#######################################################################
#######################################################################
# SETUP PATHS
#######################################################################
#######################################################################

fpath=( "$HOME/.zshfunc" "$fpath[@]" )
export FPATH
# Only unique entries please.
typeset -U fpath


path=(
	"$HOME/bin"
	"$HOME/local/bin"
	/usr/lib/ccache
	/usr/local/bin
	/usr/bin
	/usr/local/CAME/bin
	/bin
	/usr/bin/X11
	/usr/games
	/sw/bin
	/usr/lib/nagios/plugins
	"$path[@]"
)
if [ "`id -u`" = "0" ] || ! [ -x /usr/bin/id ] ; then
	PATH="/usr/local/sbin:/usr/sbin:/sbin:${PATH}"
	path=(
		/usr/local/sbin
		/usr/sbin
		/sbin
		"$path[@]"
	)
fi
export PATH
# Only unique entries please.
typeset -U path
# Remove entries that don't exist on this system.  Just for sanity's
# sake more than anything.
path=( ${^path}(N-/) )


#MANPATH="/usr/share/man:/usr/local/share/man:/usr/local/man:$MANPATH"
#if [ -d $HOME/local/share/man ] ; then
#	MANPATH="${HOME}/local/share/man:${MANPATH}"
#fi


# FUNCTIONS
###########

# Now that FPATH is set correctly, do autoloaded functions.
# autoload all functions in $FPATH - that is, all files in
# each component of the array $fpath.  If there are none, feed the list
# it prints into /dev/null.
for paths in "$fpath[@]"
  do
    autoload -U "$paths"/*(N:t) >/dev/null
done
unset paths

# we want colorful listings
zmodload -i zsh/complist
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}

hosts=""
for f in "$HOME/.ssh/known_hosts" "$HOME/.ssh/known_hosts2" "/etc/ssh/ssh_known_hosts"; do
	if [ -e "$f" ]; then
		hosts=($hosts ${${${${(f)"$(<"$f")"}:#[0-9]*}%%\ *}%%,*})
	fi
done
if [ -n "$hosts" ]; then
	zstyle ':completion:*:hosts' hosts $hosts
fi

autoload -U compinit
compinit
compdef _ssh ssha=ssh

insert-comment() {
	BUFFER="#$BUFFER"
	zle accept-line
}
zle -N insert-comment
bindkey "^[#" insert-comment

#######################################################################
#######################################################################
# SETUP ALIASES
#######################################################################
#######################################################################

if [ "$SYSTEM" = "Linux" ] ; then
	eval `dircolors`
	LS_COLORS="$LS_COLORS""*.divx=01;35:*.pdf=01;35:*.ps=01;35:*.eps=01;35"

	alias ls='ls --color=auto -F'
	alias grep='grep --color'
	alias Grep='grep --color'
	alias grpe='grep --color'
fi
alias cp='cp -i'
alias mv='mv -i'
alias l='ls -l'

alias mmv='noglob mmv'

alias zinterdiff='interdiff -z'

alias 221='pstops "2:0L@.7(21cm,0)+1L@.7(21cm,14.85cm)"'
alias rot13='tr a-zA-Z n-za-mN-ZA-M'
alias 64216='perl -MMIME::Base64 -e "print unpack(\"H*\", decode_base64(<>)),\"\n\""'
alias 16264='perl -MMIME::Base64 -e "\$l=<>; chomp \$l; print encode_base64(pack(\"H*\", \$l)),\"\n\""'

alias vnc='xtightvncviewer -encodings "tight copyrect" -compresslevel 9 -quality 4'
alias hs-mplayer='mplayer -ao alsa:device=hw=1'
alias cal='cal -m'
alias defaultfixed='echo -n -e "\033]50;fixed\007"'
alias default='echo -n -e "\033]50;-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-15\007"'
alias hide='echo -n -e "\033]50;nil2\007"'
alias tiny='echo -n -e "\033]50;-misc-fixed-medium-r-normal--7-70-75-75-c-50-iso8859-15\007"'
alias small='echo -n -e "\033]50;-misc-fixed-medium-r-normal--10-100-75-75-c-60-iso8859-15\007"'
alias medium='echo -n -e "\033]50;-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-15\007"'
alias large='echo -n -e "\033]50;-misc-fixed-medium-r-normal--15-140-75-75-c-90-iso8859-15\007"'
alias huge='echo -n -e "\033]50;-misc-fixed-medium-r-normal--20-200-75-75-c-100-iso8859-15\007"'

! [[ -x /usr/bin/traceroute ]] && [[ -x /usr/sbin/traceroute ]] && alias traceroute=/usr/sbin/traceroute
! [[ -x /bin/ss ]] && [[ -x /sbin/ss ]] && alias ss=/sbin/ss

if [ -x /usr/bin/recode ]; then
	alias unix2dos='recode lat1..ibmpc'
	alias dos2unix='recode ibmpc..lat1'
fi

if [ -x /usr/bin/base64 ]; then
	alias base64-encode=base64
	alias base64-decode='base64 -d'
else
	alias base64-encode='perl -MMIME::Base64 -e "print encode_base64(<>)"'
	alias base64-decode='perl -MMIME::Base64 -e "print decode_base64(<>)"'
fi




case $TERM in
	xterm*|rxvt*)
		function update-title() {
			print -n "\033]0;$1\007"
		}
		function build-and-update-title() {
			local location cmd title
			location="$(print -P $1)"
			cmd="${2:-}"
			if [ -z "$cmd" ]; then
				title="$location"
			else
				title="$cmd [$location]"
				title=`echo $title | tr '\n' ' '`
			fi
			update-title "$title"
		}
		;;

	screen*)
		if [ -n "${TMUX:-}" ] && [ -x /usr/bin/tmux ] ; then
			function update-title() {
				print -n "\033]0;$1\007"
			}
			function build-and-update-title() {
				local location cmd title
				location="$(print -P $1)"
				cmd="${2:-}"
				if [ -z "$cmd" ]; then
					title="$location"
					tmux rename-window "$title"
				else
					tmux setw automatic-rename on > /dev/null
					title="$location:$cmd"
				fi
				update-title "$title"
			}
		elif [ -x /usr/bin/screen ] || [ -x /usr/local/bin/screen ]; then
			function update-title() {
				screen -X title "<$1>"
			}
			function build-and-update-title() {
				local location cmd title
				location="$(print -P "%~")"
				cmd="${2:-}"
				if [ -z "$cmd" ]; then
					title="$location"
				else
					title="$location:$cmd"
				fi
				update-title "$title"
			}
		else
			function build-and-update-title() { }
		fi
		;;
	*)
		function build-and-update-title() { }
		;;
esac

function precmd() {
	vcs_info
	build-and-update-title "$TITLE"
};
function preexec() {
	build-and-update-title "$TITLE" "$1"
};

# gather version control information for inclusion in a prompt
# we will only be using one variable, so let the code know now.
autoload -Uz vcs_info && vcs_info
zstyle ':vcs_info:*' max-exports 1
zstyle ':vcs_info:*' disable cdv darcs mtn tla hg
zstyle ':vcs_info:*' use-prompt-escapes
zstyle ':vcs_info:*' use_simple


function init-prompt() {
	if [ -e /etc/debian_chroot ]; then
		debian_chroot=$(cat /etc/debian_chroot)
	fi

	# change vcs_info formats for the prompt
	if [[ "$TERM" == dumb ]] ; then
		zstyle ':vcs_info:*' actionformats "(%s%)-[%b|%a] "
		zstyle ':vcs_info:*' formats       "(%s%)-[%b] "
	else
# these are the same, just with a lot of colours:
		zstyle ':vcs_info:*' actionformats "${PR_YELLOW}[${PR_CYAN}%s${PR_YELLOW}|${PR_GREEN}%b${PR_YELLOW}|${PR_RED}%a${PR_YELLOW}]${PR_NO_COLOUR} "
		zstyle ':vcs_info:*' formats       "${PR_YELLOW}[${PR_CYAN}%s${PR_YELLOW}|${PR_GREEN}%b${PR_YELLOW}]${PR_NO_COLOUR} "
		zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b${PR_RED}:${YELLOW}%r"
	fi

	local exitcodeprompt
	exitcodeprompt='%0(?..${PR_RED}e%?${PR_NO_COLOUR}:)'
	if [ "`id -u`" = "0" -o ! -x /usr/bin/id ] ; then
		export PROMPT="${exitcodeprompt}"'${debian_chroot:+[$debian_chroot] }${VCS_INFO_message_0_}%n@%m:%~# '
		export TITLE="%n@%m: %~"
	else
		export PROMPT="${exitcodeprompt}"'${debian_chroot:+[$debian_chroot] }${VCS_INFO_message_0_}%n@%m:%~$ '
		export TITLE="%n@%m: %~"
	fi
}

safe-restore-ssh-agent-socket
init-prompt

[ -x /usr/bin/ddate ] && /usr/bin/ddate && echo
if [ -x /usr/games/fortune ]; then
	FORTUNE_PATH=""
	[ -d /usr/share/games/fortunes ] && FORTUNE_PATH="$FORTUNE_PATH /usr/share/games/fortunes"
	[ -d /usr/share/games/fortunes/off ] && FORTUNE_PATH="$FORTUNE_PATH /usr/share/games/fortunes/off"
	[ -d $HOME/.fortunes/ ] && FORTUNE_PATH="$FORTUNE_PATH $HOME/.fortunes/"
	fortune `echo $FORTUNE_PATH`
	echo
fi
[ -f COMMANDMENTS ] && cat COMMANDMENTS
[ -e $HOME/.zshrc-local ] && . $HOME/.zshrc-local
[ -e $HOME/.pal ] && [ -e /usr/bin/pal ] && pal -r 5-10
true