-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzsh
158 lines (116 loc) · 4.33 KB
/
zsh
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
# source ~/.profile
# History management settings.
setopt hist_ignore_all_dups
setopt hist_ignore_space
HISTSIZE=9999
# When I type a directory path, just cd to it.
setopt auto_cd
# Show time taken for the command to finish, if it takes longer than this many seconds.
REPORTTIME=6
# Make personal scripts folder, available in the PATH.
export PATH=~/bin:~/.local/bin:"$PATH"
# A super-fast, zero-distractions, no-nonsense prompt string.
PS1="
%F{red}%~%f> "
# Set EDITOR to be used for things like editing the command with <C-x><C-e> or for authoring git commit messages.
export EDITOR=vim
# Load asdf, also adds the shims folder to head of the PATH.
source "$(brew --prefix asdf)"/asdf.sh
# Load FZF scripts.
for f in "$(brew --prefix)/opt/fzf/shell"/*.zsh; do
source "$f"
done
if [[ -d ~/labs/antigen ]]; then
source ~/labs/antigen/antigen.zsh
# Fix paste taking too long: <https://github.com/ohmyzsh/ohmyzsh/issues/6338#issuecomment-491504348>.
export DISABLE_MAGIC_FUNCTIONS=true
antigen use oh-my-zsh
if [[ -d ~/labs/zsh-vim-mode ]]; then
# Vim like bindings plugin. Need to run after theme, so mode indicator
# can be set, if the theme didn't already set it.
# antigen-bundle sharat87/zsh-vim-mode
ZSH_VIM_MODE_NORMAL_MAP=^k
antigen bundle ~/labs/zsh-vim-mode --no-local-clone
fi
for p in man aws docker docker-compose kubectl helm fzf mvn httpie python node; do
antigen bundle "$p"
done
# More plugins: https://github.com/unixorn/awesome-zsh-plugins#plugins
# This has to be the last plugin.
antigen bundle zsh-users/zsh-syntax-highlighting
antigen apply
else
echo "Antigen not found. Not loading any plugins." >&2
fi
if type brew &>/dev/null; then
__brew_prefix="$(brew --prefix)"
FPATH="$__brew_prefix/share/zsh-completions:$FPATH"
autoload -Uz compinit
compinit
if [[ -f "$__brew_prefix/share/zsh-autosuggestions/zsh-autosuggestions.zsh" ]]; then
source "$__brew_prefix/share/zsh-autosuggestions/zsh-autosuggestions.zsh"
else
echo 'zsh-autosuggestions not found. Run `brew install zsh-autosuggestions`.' >&2
fi
unset __brew_prefix
fi
# ZSH notification for long commands.
# Source: <https://github.com/kevinywlui/zlong_alert.zsh/blob/master/zlong_alert.zsh>
# Use zsh/datetime for $EPOCHSECONDS
zmodload zsh/datetime || return
# Be sure we can actually set hooks
autoload -Uz add-zsh-hook || return
# Set commands to ignore if needed
zlong_ignore_cmds='vim ssh mo mongo man watch crontab pgcli tmux'
# Set as true to ignore commands starting with a space
zlong_ignorespace=true
# Need to set an initial timestamps otherwise, we'll be comparing an empty
# string with an integer.
zlong_timestamp=$EPOCHSECONDS
# Define the alerting function, do the text processing here
zlong_alert_func() {
local cmd=$1
local secs=$2
local ftime=$(printf '%dh:%dm:%ds\n' $(($secs / 3600)) $(($secs % 3600 / 60)) $(($secs % 60)))
# osascript -e "display notification \"Time taken: $ftime\" with title \"Completed $cmd\""
echo -n "Finished in $ftime.\a"
}
zlong_alert_pre() {
zlong_last_cmd=$1
if [[ $zlong_ignorespace == 'true' && ${zlong_last_cmd:0:1} == [[:space:]] ]]; then
# set internal variables to nothing ignoring this command
zlong_last_cmd=''
zlong_timestamp=0
else
zlong_timestamp=$EPOCHSECONDS
fi
}
zlong_alert_post() {
local duration=$(($EPOCHSECONDS - $zlong_timestamp))
local lasted_long=$(($duration - ${REPORTTIME:-15}))
local cmd_head=$(echo $zlong_last_cmd | awk '{printf $1}')
if [[ $lasted_long -gt 0 && ! -z $zlong_last_cmd && ! $zlong_ignore_cmds =~ $cmd_head ]]; then
zlong_alert_func $zlong_last_cmd duration
fi
zlong_last_cmd=''
}
add-zsh-hook preexec zlong_alert_pre
add-zsh-hook precmd zlong_alert_post
# Custom keybindings. These should come in last so they override any shit from external scripts
# loaded above.
# Use <C-u> to delete to start of line.
bindkey \^U backward-kill-line
bindkey \^A beginning-of-line
bindkey \^E end-of-line
# For tmux in alacritty, the TERM is being set to `screen`, instead of `screen-256color`.
if [[ $TERM == screen ]]; then
TERM=$TERM-256color
fi
# Automatically list directory contents on `cd`.
auto-ls () { ls -FG; }
chpwd_functions=( auto-ls $chpwd_functions )
source ~/lawn/shell/utils.sh
# >>>> Vagrant command completion (start)
fpath=(/opt/vagrant/embedded/gems/2.2.19/gems/vagrant-2.2.19/contrib/zsh $fpath)
compinit
# <<<< Vagrant command completion (end)