blob: cdda441367928240de27e84533a9b353d3412c2e (
plain) (
blame)
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
|
##########################################################
# Prompt
setprompt () {
setopt prompt_subst
###
# See if we can use colors.
autoload colors zsh/terminfo
if [[ "$terminfo[colors]" -ge 8 ]]; then
colors
fi
for color in red green yellow blue magenta cyan white; do
eval local ${color}='%{$fg[${(L)color}]%}'
eval local ${color}_bold='%{$terminfo[bold]$fg[${(L)color}]%}'
done
local nocolor="%{$terminfo[sgr0]%}"
# Base prompt.
pr_baseprompt="%(!.${red}%U%n%u.${green}%n)" # Username.. red underlining if uid 0 (root)
pr_baseprompt+="${magenta}@${green}%m" # "@<host>"
pr_baseprompt+="${yellow}:${green}%30<...<%~%<<%" # truncated path
pr_baseprompt+="(?.. ${red}%?)" # Exit code of previous command
pr_baseprompt+="${yellow}>${nocolor} " # Finally, add a yellow "> "
# Info for title bar/screen title
pr_titleinfo='%(!.[ROOT] | .)%l) %n@%m:%30<...<%~%<<'
pr_windowtitle=''
pr_wt_in=''
pr_wt_out=''
case ${TERM} in
xterm*|rxvt)
pr_wt_in=$'\e]0;'
pr_wt_out=$'\a'
;;
tmux*)
pr_wt_in=$'\e]2;'
pr_wt_out=$'\e\\'
;;
screen)
# We also set the screen hardstatus format here.. it's a oncer.
print -n "\e_screen \005S :\005 - \005t\e\\"
pr_wt_in=$'\ek'
pr_wt_out=$'\e\\'
;;
esac
if [[ -n "${pr_wt_in}" ]];then
pr_windowtitle="${pr_wt_in}${pr_titleinfo}${pr_wt_out}"
fi
# Finally, set prompts
PROMPT="%{${pr_windowtitle}%}${pr_baseprompt}"
RPROMPT="${green}< ${red}%!${nocolor}"
PS2="${yellow}%_ ${green}>${nocolor} "
# Create the prexec hook function to set the title to the current command
preexec () {
[[ -n "${pr_wt_in}" ]] && print -nPR "${pr_wt_in}%l) %n@%m: %40>...>${(V)1//\%/%%}%<<${pr_wt_out}";
}
}
setprompt
##########################################################
# Misc
#cdpath=(.. ~) # make cd search other directories
limit core 0 # no core dumps
umask 022 # for user group system
setopt nopromptcr # No cr before prompt.
#setopt extendedglob # Lots of cool extra wildcards
#setopt mailwarning # New mail?
setopt correct # Correct commands
#setopt nobanghist # No bang-history, thanks
# Note that the following comment makes me cringe now, but is left in for
# historical amusement value. (joeyh is funny)
setopt autolist automenu # Filename completion: the best of csh and 4dos!
setopt nobeep nolistbeep
setopt autocd # Exec directory to cd there
setopt noclobber noflowcontrol
setopt autoresume
#setopt print_exit_value
setopt list_packed
unsetopt bgnice
# History setup.
setopt share_history
setopt hist_ignore_dups
setopt hist_allow_clobber
setopt hist_reduce_blanks
# Make alt key function as meta key.
#[[ $TERM = "xterm" ]] && stty pass8 && bindkey -me
# ctrl-s will no longer freeze the terminal.
stty -ixon kill ^K
stty erase "^?"
eval `dircolors 2>/dev/null` # set up color-ls variables
watch=(notme) # watch for everybody but me
LOGCHECK=120 # check every 2 min for login/logout activity
# Turn on full-featured completion
autoload -U compinit
compinit
if [ -e ~/.ssh/known_hosts ]; then
# Use .ssh/known_hosts for hostnames.
hosts=(${${(f)"$(<~/.ssh/known_hosts)"//,/ }%%\ *})
zstyle ':completion:*:hosts' hosts $hosts
fi
##########################################################
# Aliases
alias whois='whois -h geektools.com'
alias df='df -h'
alias cls=clear
alias cscs='clear;printf "\033[3J"'
# Do we have GNU ls of a new enough version for color?
(ls --help 2>/dev/null |grep -- --color=) >/dev/null && \
alias ls='ls -b -CF --color=auto'
alias l=ls
alias dir='ls -lhga'
alias du='du -h'
alias f=finger
alias ftp=ncftp
alias md=mkdir
alias rd=rmdir
alias k=killall
alias mtr='mtr --curses'
#alias su='su -'
#if [ -e `which reportbug 2>/dev/null` ]; then
# alias bug='reportbug -b'
#fi
alias stardate='date "+%y%m.%d/%H%M"'
# I don't like the zsh builtin time command.
if [ -e /usr/bin/time ] ; then alias time=/usr/bin/time ; fi
# Use GPG2 in preference over GPG1
if [ -e /usr/bin/gpg2 ] ; then alias gpg=/usr/bin/gpg2 ; fi
# Xterm/rxvt resizing-fu
alias default='echo -ne "\033]50;fixed\007"'
alias hide='echo -ne "\033]50;nil2\007"'
alias tiny='echo -ne "\033]50;5x7\007"'
alias small='echo -ne "\033]50;6x10\007"'
alias medium='echo -ne "\033]50;7x13\007"'
alias large='echo -ne "\033]50;9x15\007"'
alias huge='echo -ne "\033]50;10x20\007"'
##########################################################
# Key bindings
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 "\eOA" up-line-or-beginning-search
bindkey "\eOB" down-line-or-beginning-search
bindkey "\e[A" history-search-backward
bindkey "\e[B" history-search-forward
bindkey '^K' kill-whole-line
bindkey -s '^L' "|less\n" # ctrl-L pipes to less
bindkey -s '^B' " &\n" # ctrl-B runs it in the background
bindkey "\e[1~" beginning-of-line # Home
bindkey "\e[H" beginning-of-line # Home (xterm)
[[ $TERM = "rxvt" ]] && bindkey "\e[7~" beginning-of-line
bindkey "\e[4~" end-of-line # End
bindkey "\e[F" end-of-line # End (xterm)
[[ $TERM = "rxvt" ]] && bindkey "\e[8~" end-of-line
bindkey "\e[2~" overwrite-mode # Ins
bindkey "\e[3~" delete-char # Delete
##########################################################
# Functions
# Return the size of a directory.
dirsize() {
pushd >/dev/null;
chdir $1;
du |tail --lines 1;
popd >/dev/null;
}
# Calculator
calc () { echo $* |bc -l }
# This fingers @host.
@ () { finger @$1 }
|