-
Notifications
You must be signed in to change notification settings - Fork 0
/
_zshrc
72 lines (62 loc) · 1.86 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
[[ -f /opt/dev/sh/chruby/chruby.sh ]] && type chruby >/dev/null 2>&1 || chruby () { source /opt/dev/sh/chruby/chruby.sh; chruby "$@"; }
[[ -x /opt/homebrew/bin/brew ]] && eval $(/opt/homebrew/bin/brew shellenv)
[ -f /opt/dev/dev.sh ] && source /opt/dev/dev.sh
bindkey -v
alias ll=ls -la
autoload -Uz vcs_info
bindkey -v
bindkey '^R' history-incremental-search-backward
# Taken from https://gist.github.com/romkatv/2a107ef9314f0d5f76563725b42f7cab
function prompt-length() {
emulate -L zsh
local -i COLUMNS=${2:-COLUMNS}
local -i x y=${#1} m
if (( y )); then
while (( ${${(%):-$1%$y(l.1.0)}[-1]} )); do
x=y
(( y *= 2 ))
done
while (( y > x + 1 )); do
(( m = x + (y - x) / 2 ))
(( ${${(%):-$1%$m(l.x.y)}[-1]} = m ))
done
fi
typeset -g REPLY=$x
}
# Usage: fill-line LEFT RIGHT
#
# Sets REPLY to LEFT<spaces>RIGHT with enough spaces in
# the middle to fill a terminal line.
function fill-line() {
emulate -L zsh
prompt-length $1
local -i left_len=REPLY
prompt-length $2 9999
local -i right_len=REPLY
local -i pad_len=$((COLUMNS - left_len - right_len - ${ZLE_RPROMPT_INDENT:-1}))
if (( pad_len < 1 )); then
# Not enough space for the right part. Drop it.
typeset -g REPLY=$1
else
local pad=${(pl.$pad_len.. .)} # pad_len spaces
typeset -g REPLY=${1}${pad}${2}
fi
}
function set-prompt() {
emulate -L zsh
local top_left='%F{blue}%~%f'
local top_right="%F{yellow}%T%f"
local bottom_left="%m ${vcs_info_msg_0_}%B%F{%(?.green.red)}$%f%b "
local bottom_right=''
local REPLY
fill-line "$top_left" "$top_right"
PROMPT=$REPLY$'\n'$bottom_left
RPROMPT=$bottom_right
}
setopt PROMPT_SUBST
zstyle ':vcs_info:git:*' formats '[%b]'
precmd() { vcs_info }
setopt no_prompt_{bang,subst} prompt_{cr,percent,sp}
autoload -Uz add-zsh-hook
add-zsh-hook precmd set-prompt
alias update="dev stop && dev up && dev start"