-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc
164 lines (146 loc) · 5.68 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
# Set up colors
if [ ! -n "$SSH_CLIENT" ] && [ ! -n "$SSH_TTY" ]; then
BASE16_SHELL="$HOME/.kkrc/base16-colors.dark.sh"
[[ -s $BASE16_SHELL ]] && source $BASE16_SHELL
fi
# OS-dependent stuff
case "$OSTYPE" in
linux-gnu)
# Colored ls
alias ls="ls --color"
# ls with extended attributes
alias lx="lsattr"
;;
FreeBSD)
;&
darwin*)
# ls with extended attributes
alias lx="l -@eO"
# Colored ls on OS X
export CLICOLOR=1
;;
esac
# BSD colors
export LSCOLORS=ExFxCxDxBxegedabagacad
# Linux colors -- set always because of zsh's list-colors
export LS_COLORS="di=1;34:ln=1;35:so=1;32:pi=1;33:ex=1;31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43"
# Needed for a colored prompt
autoload -Uz colors && colors
# Function to toggle zsh's RPROMPT.
function rp () {
if [[ "$RPROMPT" == "" || "$1" == "on" ]]; then
# Set up the right-side prompt to display the current working directory
export RPROMPT="%{$fg_bold[yellow]%}%~%{$reset_color%}"
# B&W: export RPROMPT='%~'
# Set up the left-side prompt to display "username@machine [background job count]# ", and if root, username be red
export PROMPT="%{%(#~$fg[red]~$fg[blue])%}%n%{$reset_color%}@%{$fg[green]%}%m %{$fg_no_bold[cyan]%}[%j]%{$reset_color%}%% "
# B&W: export PROMPT='%n@%m [%j]%# '
else
# No RPROMPT, set up the left-side prompt to contain the directory
export RPROMPT=''
export PROMPT="%{%(#~$fg[red]~$fg[blue])%}%n%{$reset_color%}@%{$fg[green]%}%m %{$fg_bold[yellow]%}%~%{$reset_color%} %{$fg_no_bold[cyan]%}[%j]%{$reset_color%}%% "
# B&W: export PROMPT='%n@%m %~ [%j]%# '
fi
}
# Initialize (to off)
rp on; rp
# Set up some necessary environment variables
export EDITOR=vim
export LC_ALL="en_US.UTF-8"
# Keep some history...
export HISTSIZE=1000
# ...but only in memory...
export SAVEHIST=0
export HISTFILE=/dev/null
# ... and actually display that history when asked. (With ISO timestamp and duration!)
alias history="fc -liD 0"
# And `h` as a super-short alias to `history`
alias h=history
# Autocomplete
autoload -Uz compinit && compinit
zmodload -i zsh/complist
bindkey -M menuselect '^[[Z' reverse-menu-complete # Shift-tab in complist
zstyle ':completion:*' auto-description 'Specify: %d'
zstyle ':completion:*' completer _expand _complete _ignored _correct _approximate
zstyle ':completion:*' file-sort modification
zstyle ':completion:*' format 'Completing: %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s'
zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]} m:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*' prompt 'Errors: %e'
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' menu select=2
zstyle ':completion:*' verbose yes
# Bash completion emulation
autoload -Uz bashcompinit && bashcompinit
# Zsh options
setopt auto_pushd pushd_ignore_dups no_nomatch hup notify hist_ignore_dups hash_list_all completealiases always_to_end complete_in_word correct no_list_ambiguous hist_ignore_space
# So aliases like "sc" get autocompleted
unsetopt complete_aliases
# I must have VI keys
bindkey -v
# But still, CTRL-R as history search in bash nice
bindkey '^R' history-incremental-search-backward
# Fix Debian's idiotic idea that "up" key in history should jump to beginning of line (while "k" to the EOL, just to be more confusing)
[[ -z "$terminfo[kcuu1]" ]] || bindkey -M viins "$terminfo[kcuu1]" up-line-or-history
[[ -z "$terminfo[kcud1]" ]] || bindkey -M viins "$terminfo[kcud1]" down-line-or-history
[[ "$terminfo[kcuu1]" == ""* ]] && bindkey -M viins "${terminfo[kcuu1]/O/[}" up-line-or-history
[[ "$terminfo[kcud1]" == ""* ]] && bindkey -M viins "${terminfo[kcud1]/O/[}" down-line-or-history
# CTRL-K and CTRL-J as history-search with the already typed part of the line.
# Both in command and insert mode.
bindkey -M viins '^k' up-line-or-search
bindkey -M viins '^j' down-line-or-search
bindkey -M vicmd '^k' up-line-or-search
bindkey -M vicmd '^j' down-line-or-search
# Same for cursor keys ctrl-up and ctrl-down, both command and insert mode.
bindkey -M viins '^[[1;5A' up-line-or-search
bindkey -M viins '^[[1;5B' down-line-or-search
bindkey -M vicmd '^[[1;5A' up-line-or-search
bindkey -M vicmd '^[[1;5B' down-line-or-search
# Set up some handy aliases
alias s="screen -xR"
alias l="ls -lrt"
alias la="ls -lrtA"
alias ll="ls -lhFrt"
alias sc="systemctl"
alias jc="journalctl"
alias scs="systemctl status"
alias sc0="systemctl stop"
alias sc1="systemctl start"
alias scr="systemctl restart"
alias gl="git log --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(cyan)<%an>%Creset' --abbrev-commit --date=relative --all --date-order"
alias gs="git status -sb";
alias grep="grep --color"
alias json="python -mjson.tool"
alias kargs="xargs -n 1 -P `getconf _NPROCESSORS_ONLN` -I{}"
alias tmux="tmux -2"
# hl - highlight command
source ~/.kkrc/hl
# Automatically set TMUX window title on SSH
ssh() {
# Store current window name
local SAVED=$(tmux display-message -p '#W')
local ARGS=($@)
local NAME="ssh"
local I
# Try to find the server name
for I in ${ARGS} ; do
[[ $I == "--" ]] && break
NAME="$I"
done
# Set window name
tmux rename-window "${NAME}" >/dev/null 2>/dev/null
# Do it
command ssh "$@"
# Restore window name
#tmux rename-window "$SAVED" >/dev/null 2>/dev/null
# To switch back to auto-renaming after disconnection:
#tmux set-window-option automatic-rename "on" >/dev/null 2>/dev/null
}
# Display screens if any
screen -ls | grep -v "Socket"
# Autostart kropbox?
# ~/.kkrc/other/kropbox.sh
# Local commands
if [ -e ~/.zshrc.local ]; then . ~/.zshrc.local; fi