-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzshrc
95 lines (88 loc) · 2.79 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
# Non-zsh settings and env variables
source $HOME/.shellrc
# See .preztorc for most of the configuration
# If it isn't installed system wide, load user installation
[[ -d '/usr/lib/prezto' ]] || source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"
# Follow symlinks when cd'ing
setopt chase_links
# Allow comments
setopt interactive_comments
# Prompt
setopt PROMPT_SUBST
login_info() {
if [[ -n "$SSH_CONNECTION" ]]; then
echo '%n@%m:'
fi
}
dir_info() {
# Show pwd info in blue if writable, else in cyan
if [[ -w "$PWD" ]]; then
echo '%B%F{blue}%~%f%b'
else
echo '%B%F{cyan}%~%f%b'
fi
}
[[ -f /usr/share/git/git-prompt.sh ]] && source /usr/share/git/git-prompt.sh
GIT_PS1_SHOWCOLORHINTS=1
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWSTASHSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWUPSTREAM=(verbose)
GIT_PS1_STATESEPARATOR=''
git_info() {
# Call the prompt function form /usr/share/git/git-prompt.sh
type __git_ps1 2>&1 >/dev/null && __git_ps1 " (%s)"
}
virtualenv_info() {
# Show wether we're in a virtualenv by adding a "v" to the dir
if [[ -n "$VIRTUAL_ENV" ]]; then
echo ' %B%F{green}v%f%b'
fi
}
terraform_info() {
if [[ -d ".terraform/" ]]; then
echo ' (%F{magenta}'$(terraform workspace show)'%f)'
fi
}
battery_info() {
# Show when we're below 5% charge
local battery=/sys/class/power_supply/BAT0
local capacity="$(cat $battery/capacity)"
if [[ "$capacity" -le 5 && "$(cat $battery/status)" = 'Discharging' ]]; then
echo " %B%F{red}$capacity%%%f%b"
fi
}
job_info() {
# Show amount of background jobs if any
echo '%(1j.(%j job%(2j.s.)) .)'
}
prompt() {
# Show smiley face when all went well or suprised face on non-zero exit code
echo '%B%(!,#,%(?;%F{yellow}^.^;%F{red}o.0)%f)%b '
}
PROMPT='$prompt_newline$(login_info)$(dir_info)$(git_info)$(virtualenv_info)'\
'$(terraform_info)$prompt_newline$(job_info)$(prompt)'
# Optionally show error code in right hand side prompt
RPROMPT='%(?..%F{red}%?%f)$(battery_info)'
# Disable virtualenv prompt because we just included our own
export VIRTUAL_ENV_DISABLE_PROMPT=plzdont
# Global aliases
alias -g L="| ${PAGER:-less}"
alias -g H='| head'
alias -g T='| tail'
alias -g TF='| tail -f'
alias -g S='| sort'
alias -g F='| sort | uniq -c'
alias -g G='| rg -S'
alias -g C='| columns -t'
alias -g SUM='| awk '\''{ x += $0 } END { print x }'\'
alias -g sprunge='| curl -F "sprunge=<-" http://sprunge.us'
# Mappings
bindkey '^R' history-incremental-search-backward
bindkey -M viins jj vi-cmd-mode
# Add fzf keybindings (ctrl-t, ctrl-r and alt-c)
source /usr/share/fzf/key-bindings.zsh
# Add fzf '**' completion (files, directories, process ID's, SSH hostnames)
source /usr/share/fzf/completion.zsh
# Add git-extras completion
source /usr/share/doc/git-extras/git-extras-completion.zsh