summaryrefslogtreecommitdiff
path: root/.zshrc
blob: d24fd071a9dceea3b39966ccfee45792b2600ee3 (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
196
197
198
199
200
201
202
##########################################################
# 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}";
    }

}


##########################################################
# Options

# Changing Directories
setopt autocd			# Exec directory to cd there

# Prompting
setopt nopromptcr		# No cr before prompt.

# Completion
setopt autolist			# Automatically show choices for completion
setopt automenu			# Filename completion: the best of csh and 4dos!
setopt nolistbeep		# Don't beep on ambiguous completion
setopt list_packed		# Make completion lists smaller

# Expansion and globbing
#setopt extendedglob		# Lots of cool extra wildcards

# History
setopt share_history		# Continually read and write from history file
setopt hist_ignore_dups		# Do not add duplicate contiguous commands to history
setopt hist_allow_clobber	# Add '|' to output redirections in history
setopt hist_reduce_blanks	# Remove extra blanks from history entries
#setopt nobanghist		# No bang-history, thanks

# Input/Output
setopt noclobber		# Require '!' after redirections to overwrite files
setopt noflowcontrol		# Disable ^S/^Q in editor
setopt correct			# Spell check commands
setopt nomailwarning		# Alert on new mail
#setopt print_exit_value	# Print non-zero exit values

# Job control
setopt autoresume		# Resume existing jobs with bare command
setopt nobgnice			# Don't nice bg jobs

# Zle (ZSH Line Editor)
setopt nobeep			# No beep on error


##########################################################
# Misc

limit core 0		# no core dumps
umask 022       	# default umask
#cdpath=(.. ~)		# make cd search other directories

# Keep more than 1000 history items
HISTSIZE=999999
SAVEHIST=$HISTSIZE

# 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 sysu='systemctl --user'

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