-
Notifications
You must be signed in to change notification settings - Fork 0
/
_zshrc
executable file
·114 lines (96 loc) · 3.85 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
#!/bin/zsh -f
source "$HOME/.zprofile"
if [ "$TMUX" = "" ]; then
if tmux list-sessions 2>/dev/null | grep -q '(attached)'; then
echo "Not in tmux, and there's already an attached session, so creating a new one"
tmux new-session
else
echo "Not in tmux, and there are no attached sessions, so creating the main one or attaching to it"
tmux new-session -A -s main
fi
fi
if [ "$SYSTEM_COLOR_THEME" = "Dark" ]; then
ln -sf "$HOME/.config/alacritty/dark.toml" "$HOME/.config/alacritty/active_theme.toml"
else
ln -sf "$HOME/.config/alacritty/light.toml" "$HOME/.config/alacritty/active_theme.toml"
fi
# word-splitting characters, notably leaving out -_^
WORDCHARS=' :*?[]~=&;!#$%(){}<>/.'
autoload -Uz select-word-style
select-word-style normal
zstyle ':zle:*' word-style unspecified
# zsh syntax highlighting; make -/-- options dimmer
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets regexp)
typeset -A ZSH_HIGHLIGHT_REGEXP
ZSH_HIGHLIGHT_REGEXP+=(' -{1,2}[a-zA-Z0-9_-]*' fg=244)
source "$(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
# run-help is alias'd to man by default; change it so we can get zsh builtins
[ "$(type -w run-help)" = 'run-help: alias' ] && unalias run-help
autoload run-help
HELPDIR="/usr/share/zsh/${ZSH_VERSION}/help"
# activate venv_manager, and prevent venvs from modifying prompt
source "$HOME/code/venv_manager/venv_manager.plugin.zsh"
export VIRTUAL_ENV_DISABLE_PROMPT=1
autoload -Uz add-zsh-hook
add-zsh-hook chpwd venv_manager_switch_venv
# completions, and case-insensitive at that
autoload -U compinit
# https://gist.github.com/ctechols/ca1035271ad134841284#gistcomment-2767420
if [[ -n ${ZDOTDIR}/.zcompdump(#qN.mh+24) ]]; then
compinit;
else
compinit -C;
fi;
# case-insensitive completions
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
autoload -U +X bashcompinit && bashcompinit # for `complete`
complete -C "$(which aws_completer)" aws
# tools and hooks - atuin, direnv, ls colors
eval "$(atuin init zsh)"
eval "$(direnv hook zsh)"
source ~/.lscolors
# source other files
source "$HOME/.aliases"
[[ -f "$HOME/.zshlocal" ]] && source "$HOME/.zshlocal"
# rest of the file is theming zsh prompt
function _get_aws_profile_prompt {
if [[ "$AWS_PROFILE" == "" ]]; then
return
fi
# the cut is to get the suffix without the "namespace"/company name, to help shorten display
echo " | %F{yellow} $(echo "$AWS_PROFILE" | cut -d- -f2-)%F{reset}"
}
function _get_k8s_context_prompt {
if [[ ! -f ~/.kube/config ]]; then
return
fi
local k8s_context=$(sed -n "s/^current-context: \(.*\)$/\1/p" ~/.kube/config)
if [[ "$k8s_context" == "" ]]; then
return
fi
# the cut is to just get the environment, so we can shorten the display
echo " | %F{blue} $(echo "$k8s_context" | cut -d- -f1)%F{reset}"
}
function _get_venv_prompt {
echo "$VIRTUAL_ENV_PROMPT" | perl -ne "s/\(?([a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])\)?( *)?/ | %F{#336c9d} \1%F{reset}/g; print"
}
function _get_git_prompt {
local ref
ref="$(git symbolic-ref --quiet HEAD 2> /dev/null)"
if [[ $? != 0 ]]; then
return
fi
# TODO: make this more generic. Right now, the `cut` is to help shorten the branch name since
# I automatically add the datetime as prefix
echo "${ref#refs/heads/}" | cut -d- -f2- | perl -ne "s/(..*)/ | %F{#3fb951} \1%F{reset}/g; print"
}
function _get_pwd_prompt {
echo "%F{#9E923C}%~%F{reset}"
}
setopt PROMPT_SUBST
# to make RPROMPT go away after no longer active. keeps things clean, and allows easier copy-paste
# since RPROMPT won't be included, but it can be useful to know what RPROMPT context a command ran in
setopt transient_rprompt
PROMPT='
%F{#39ff14}%D{%H:%M:%S %Z} %F{reset} '
RPROMPT='$(_get_pwd_prompt)$(_get_git_prompt)$(_get_venv_prompt)$(_get_aws_profile_prompt)$(_get_k8s_context_prompt)%F{reset}'