summaryrefslogtreecommitdiff
path: root/.zshrc
blob: b0ec7198d1368099716811340114d606717ccdf5 (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
##########################################################
# Prompt

function () {

    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.
    local pr_baseprompt
    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
    local pr_titleinfo='%(!.[ROOT] | .)%l) %n@%m:%30<...<%~%<<'
    local 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}%(!.[ROOT] | .)%l) %n@%m: %40>...>${(V)1//\%/%%}%<<${pr_wt_out}";
    }

}


##########################################################
# 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.
    function () {
        local hosts=(${${(f)"$(<~/.ssh/known_hosts)"//,/ }%%\ *})
        zstyle ':completion:*:hosts' hosts $hosts
    }
fi

##########################################################
# Aliases

alias whois='whois -h geektools.com'
alias df='df -h'
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 ip='ip --color'
alias ipb='ip --color --brief'
alias dir='ls -lhga'
alias du='du -h'
alias ftp=ncftp
alias mtr='mtr --curses'

alias fixssh='eval $(tmux showenv -s SSH_AUTH_SOCK)'

# 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