-
Notifications
You must be signed in to change notification settings - Fork 3
/
zshrc
131 lines (108 loc) · 3.21 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
# -*- mode: sh -*-
# zshrc: run for interactive shells
fpath=(~/.zsh/functions /usr/local/share/zsh-completions $fpath)
## emacs^[dd
# bindkey -v
## vim<C-S-k>
bindkey -e
# when i've ssh'd into something, stick with vi mode
[[ ! -z $SSH_CLIENT ]] && bindkey -v
## turn on expanded tabcomplete
autoload -U compinit
compinit
## and support some bash completion scripts too
autoload -U bashcompinit
bashcompinit
# `ls /foo/bar<C-w>` only kills 'bar'
autoload -U select-word-style
select-word-style bash
## allows $fg[white], $bg[red], $terminfo[bold]
autoload colors zsh/terminfo
colors
setopt autocd ## if i type '../somedir', just cd there.
setopt cdablevars ## 'cd foo' can be 'cd $foo' if 'foo' doesn't exist
setopt histignorespace ## omit ' command' from history
## rake foo[bar] without the hassle
# an alternative may be `alias rake='noglob rake'`, if nomatch ends
# up being frustrating
unsetopt nomatch
## history
export SAVEHIST=50000
export HISTSIZE=10000
export HISTFILE=~/.history.zsh
setopt histverify
setopt inc_append_history
setopt share_history
setopt hist_ignore_dups
setopt hist_ignore_all_dups
setopt hist_expire_dups_first
setopt hist_reduce_blanks
setopt hist_save_no_dups
setopt extended_glob
## prompt
# expand %m, %*; expand '$(echo hi)', '${foovar}'
setopt prompt_percent prompt_subst
# emacs shell == "dumb"
# disable zsh line editing and let emacs do it
[[ $TERM = "dumb" ]] && unsetopt zle
## generic shell profile setup
function sourcedir () {
if [ -d "$1" ]; then
for f in "$1"/*.sh; do source $f; done
fi
}
sourcedir ~/dotfiles/shell_profile
sourcedir ~/dotfiles/shell_profile/`uname -s`
sourcedir ~/dotfiles/private/shell_profile
sourcedir ~/dotfiles/private/shell_profile/`uname -s`
unfunction sourcedir
# simplistic git status in prompt
pd-git-prompt () {
local ref=$(git symbolic-ref HEAD 2>/dev/null)
if [ -z $ref ]; then return; fi
if [[ -n $(git status -s 2>/dev/null) ]]; then
local dirty=" δ"
else
local dirty=""
fi
echo " (${ref#refs/heads/}${dirty})"
}
# equally dumb aws/gcp/... contexts
pd-cloud-contexts () {
declare -a contexts
local gcp k8s
if [[ -n "$AWS_PROFILE" ]]; then
out=($out "aws/${AWS_PROFILE}")
fi
if [[ -f ~/.config/gcloud/active_config ]]; then
gcp="$(cat ~/.config/gcloud/active_config)"
if [[ -f ~/.config/gcloud/configurations/"config_${gcp}" ]]; then
out=($out "gcp/${gcp}")
fi
fi
if [[ -f ~/.kube/config ]]; then
k8s="$(grep '^current-context' ~/.kube/config | cut -d' ' -f2)"
if [[ -n "$k8s" ]]; then
if echo "$k8s" | grep -q '^gke_' >/dev/null 2>&1; then
k8s="$(echo "$k8s" | cut -d_ -f4-)"
fi
out+=("k8s/${k8s/-cluster/}")
fi
fi
[[ -n "$out" ]] && echo " [$out]"
}
# if this is over ssh, display the hostname to save my brain the effort
if [[ -n $SSH_CONNECTION ]]; then
export PS1='%~ @ %m » '
else
export PS1='%~$(pd-git-prompt)$(pd-cloud-contexts) » '
export RPROMPT='%(?.. %{$fg[red]%}[! %?]%{$fg[white]%})'
fi
# In iTerm, set the tab title
precmd () {
if [ -z "$INSIDE_EMACS" ]; then
local tab_label="$(print -P %3~)"
echo -ne "\e]2;${tab_label}\a" # set window title to full string
echo -ne "\e]1;${tab_label}\a" # set tab title to rightmost 24 characters
fi
}