-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc
158 lines (130 loc) · 3.87 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
if [ -f /opt/homebrew/share/antigen/antigen.zsh ]; then
source /opt/homebrew/share/antigen/antigen.zsh
else
source /usr/local/share/antigen/antigen.zsh
fi
antigen use oh-my-zsh
antigen bundle autojump
antigen bundle zsh-users/zsh-syntax-highlighting
antigen apply
# completion
autoload -U compinit
compinit
autoload bashcompinit
bashcompinit
compdef g='git'
# make completion
# https://github.com/zsh-users/zsh-completions/issues/541#issuecomment-384223016
zstyle ':completion:*:make:*:targets' call-command true
zstyle ':completion:*:make:*' tag-order targets
# Load environment
source ~/.dotfiles/env
# history search
bindkey '\C-p' history-beginning-search-backward
bindkey '\C-n' history-beginning-search-forward
bindkey '\e[A' history-beginning-search-backward
bindkey '\e[B' history-beginning-search-forward
# edit current command line with $EDITOR
autoload -z edit-command-line
zle -N edit-command-line
bindkey "^X^E" edit-command-line
# history
setopt histignoredups
export HISTSIZE=10000
# helper functions
function truncate_string {
max=$1
ellipsis=$(if [ ! -z $2 ]; then echo $2; else echo "…"; fi)
read string
len=$(echo "${#string}")
if [ $len -gt $max ]; then
print $string[1,$(($max - 1))]$ellipsis
else
print $string
fi
}
# aixterm color escape sequences: bright but *not* bold, work also when the
# option "Draw bold text in bright colors" in iTerm2 is unchecked.
typeset -A fg_bright
fg_bright[black]="[90m"
fg_bright[red]="[91m"
fg_bright[green]="[92m"
fg_bright[yellow]="[93m"
fg_bright[blue]="[94m"
fg_bright[magenta]="[95m"
fg_bright[cyan]="[96m"
fg_bright[white]="[97m"
# prompt
__PROMPT_VCS_DELIMITER_COLOR="$fg_bright[black]"
__PROMPT_VCS_DIRTY_COLOR="$fg[red]"
__PROMPT_VCS_BRANCH_COLOR="$fg[green]"
__PROMPT_VCS_HASH_COLOR="$fg[yellow]"
__PROMPT_EXIT_CODE_STR="%(?..%{$fg[red]%}↯%?%{$reset_color%} )"
__PROMPT_DELIMITER_COLOR="$fg_bright[black]"
__PROMPT_TIME_COLOR="$fg_bright[black]"
__PROMPT_PWD_COLOR="$fg[blue]"
function __accept_line_and_enable_warning {
__PROMPT_EXIT_CODE=$__PROMPT_EXIT_CODE_STR
zle accept-line
}
zle -N __accept_line_and_enable_warning
bindkey '^M' __accept_line_and_enable_warning
function __find_git_root {
git rev-parse --show-toplevel > /dev/null 2>&1
}
function __git_dirty {
test -n "`git status --porcelain`"
}
function __git_branch {
git rev-parse --abbrev-ref HEAD 2>/dev/null
}
function __git_abbrev_branch {
__git_branch | truncate_string 20 "⋯"
}
function __git_hash {
git log -1 --format="%h" 2>/dev/null || print '(none)'
}
function __git_prompt {
if __find_git_root; then
local dirty_str=''
if __git_dirty; then
dirty_str='●'
fi
print "%{$__PROMPT_VCS_DIRTY_COLOR%}${dirty_str}%{$reset_color%}"\
"%{$__PROMPT_VCS_BRANCH_COLOR%}$(__git_abbrev_branch)%{$reset_color%}"\
"%{$__PROMPT_VCS_DELIMITER_COLOR%}@%{$reset_color%}"\
"%{$__PROMPT_VCS_HASH_COLOR%}$(__git_hash)%{$reset_color%} "
fi
}
function __abbrev_pwd {
setopt extendedglob
local pwd="${PWD/#$HOME/~}"
if [[ "$pwd" == (#m)[/~] ]]; then
print $MATCH
else
print "${${${(@j:/:M)${(@s:/:)pwd}##.#?}:h}%/}/${pwd:t}"
fi
}
PROMPT=\
"%{$__PROMPT_TIME_COLOR%}"'%D{%H:%M} '\
'${__PROMPT_EXIT_CODE}$(__git_prompt)'\
"%{$__PROMPT_DELIMITER_COLOR%}"'${__PROMPT_BG}'\
"%{$__PROMPT_PWD_COLOR%}"'$(__abbrev_pwd)'"%{$reset_color%}
%{$__PROMPT_DELIMITER_COLOR%}%#%{$reset_color%} "
# Travis
[ -f ~/.travis/travis.sh ] && source ~/.travis/travis.sh
# ASDF version manager
source $HOME/.asdf/completions/asdf.bash
# direnv
eval "$(direnv hook zsh)"
# local configuration
if [ -f ~/.zshrc.local ]; then
source ~/.zshrc.local
fi
# added by travis gem
[ -f /Users/patrickoscity/.travis/travis.sh ] && source /Users/patrickoscity/.travis/travis.sh
# Load Angular CLI autocompletion.
if [ -x "$(command -v ng)" ]; then
source <(ng completion script)
fi
source /Users/pat/.docker/init-zsh.sh || true # Added by Docker Desktop