-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc
207 lines (175 loc) · 6.17 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# NOTE: make sure this is set before oh-my-zsh is loaded
# If omitted, or empty, HISTSIZE is assumed to be 1 which makes for an unergonomic history experience
export HISTSIZE=1000000
export SAVEHIST=1000000
export FZF_DEFAULT_OPTS="--reverse --height=20% --multi"
export FZF_CTRL_T_OPTS="--preview 'cat {}'"
if type rg &> /dev/null; then
export FZF_DEFAULT_COMMAND='rg --files'
fi
# vi bindings
bindkey -v
set -o vi
# automatically link any plugins named in to OMZ
for plugin in zsh_codex zsh-autocomplete ; do
if [[ ! -h ~/.oh-my-zsh/custom/plugins/$plugin ]] ; then
ln -sfn ~/code/dotfiles/zsh/plugins/$plugin ~/.oh-my-zsh/custom/plugins/$plugin
fi
done
# NOTE: plugins need to load before OMZ
plugins=(
git
macos
ruby
golang
colored-man-pages
kubectl
fzf # https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/fzf
#zsh-autocomplete
)
if [[ -r ~/.oh-my-zsh ]] ; then
export ZSH="$HOME/.oh-my-zsh"
source $ZSH/oh-my-zsh.sh
else
# setup oh-my-zsh if missing
echo -n "oh-my-zsh is not setup yet. do you want to install it? y/n " >&2
read install
if [[ $install == y ]] ; then
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" <&-
# the installer is bossy and overwrites our local config, so ensure
echo -n "linking .zshrc to ~/code/dotfiles/zshrc"
ln -sfn ~/code/dotfiles/zshrc ~/.zshrc
source ~/.zshrc
fi
fi
for f in zsh/themes/byxorna.zsh-theme ; do
if [[ -r ~/code/dotfiles/$f ]] ; then
source $HOME/code/dotfiles/$f
fi
done
## vi bindings
#bindkey -v
#set -o vi
## reverse history search
# disabled 20210414 when enabling fzf
#bindkey "^R" history-incremental-search-backward
# NOTE: fzf plugin enables the following controls:
# - ctrl-r: replace reverse history search
# - ctrl-t: find files, insert file at cursor
# - alt-c: ??
umask 0022
if [[ $(uname) == Darwin ]] ; then
[[ -r ~/.profile-osx ]] && source ~/.profile-osx
[[ -r ~/.bashrc-ddog ]] && source ~/.bashrc-ddog
md5sum(){
/sbin/md5 "$@"
}
fi
# Appends every command to the history file once it is executed
setopt inc_append_history
# up arrow for backwards history search
# https://unix.stackexchange.com/questions/324623/how-to-make-oh-my-zsh-history-behavior-similar-to-bashs
bindkey "$terminfo[kcuu1]" up-history
bindkey "$terminfo[kcud1]" down-history
# ctrl-x triggers codex ai completion on cursor, prefixes with zsh shebang
bindkey '^X' create_completion
[[ -f ~/.aliases ]] && source ~/.aliases
# hook up ctrl-p on the line to launch vim's ctrlp
# make sure this runs after aliases are configured, so we use nvim if present
# https://www.reddit.com/r/zsh/comments/2uyo2a/launch_vims_ctrlp_from_zsh/
ctrlp() {
</dev/tty vim -c CtrlP
}
# Disabled because we have fzf ctrl-t+ctrl-r
#zle -N ctrlp
#bindkey "^p" ctrlp
webkit-timestamp-ago() {
# https://timothycomeau.com/writing/chrome-history
# processes a strange chrome timestamp into a relative
# string that shows like 2d or 58s or 24m
tnow="$(date +%s)"
x="$(( ${1} / 1000000 - 11644473600))"
dur=$((tnow - x))
if [[ $dur -lt 60 ]] ; then
echo "${dur}s"
elif [[ $dur -lt 3600 ]] ; then
echo "$((dur/60))m"
elif [[ $dur -lt 86400 ]] ; then
echo "$((dur/3600)))h"
else
echo "$((dur/86400))d"
fi
}
collect-browser-history(){
sep='{::}'
cols=$(( COLUMNS / 3 ))
# collect all history entries from all browsers, spit em out to stdout
# in a sorted order, so recent is last
tnow="$(date +%s)"
find ~/Library/Application\ Support/Google/Chrome/ -type f -name History | while read h
do
#echo "loading history from $h" >&2
# sqlite is annoying and gives IO errors unless we copy it for single access
#"select last_visit_time, substr(title, 1, $cols), url from urls"
#datetime(time/1e6-11644473600,'unixepoch','localtime')
cp $h /tmp/h
sqlite3 -readonly -separator {::} /tmp/h \
"select last_visit_time, substr(title, 1, $cols), url from urls"
done | sort -rn| awk -F $sep '
{
tnow='"$(date +%s)"'
# record our URL, and skip if we have seen it before
!urls[$3]++;
raw_timestamp=$1 ;
as_unix=(raw_timestamp / 1000000 - 11644473600) ;
last_access="?"
elapsed_seconds=tnow - as_unix
if (elapsed_seconds < 60)
last_access=int(elapsed_seconds) "s";
else if (elapsed_seconds < 3600)
last_access=int(elapsed_seconds/60) "m";
else if (elapsed_seconds < 86400)
last_access=int(elapsed_seconds/3600) "h";
else
last_access=int(elapsed_seconds/86400) "d";
if (urls[$3] == 1)
printf "%-'$cols's [%s] \x1b[36m%s\x1b[m\n", $2, last_access, $3 ;
}'
}
# look thru browser history with fzf with ctrl-h
browser-history(){
collect-browser-history | fzf --ansi --multi | sed 's#.*\(https*://\)#\1#' | xargs open
}
zle -N browser-history
bindkey "^h" browser-history
# ctrl-b will open bookmarks in fzf
_bookmarks-fzf () {
echo
bookmarks-fzf
zle redisplay
}
zle -N _bookmarks-fzf
bindkey "^b" _bookmarks-fzf
[[ -f ~/.rvm/scripts/rvm ]] && . ~/.rvm/scripts/rvm
# clobber the default gopath setup by gvm
export GOPATH=~/code/go
# NOTE(gabe): ssh-agent and tmux attachment lives in .profile now
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
# emulate bash's help command
function help(){
bash -c "help $@"
}
if [ -e ~/.nix-profile/etc/profile.d/nix.sh ]; then . ~/.nix-profile/etc/profile.d/nix.sh; fi # added by Nix installer
export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"
################################################################################
# This block was injected automatically by letsgo (DO NOT REMOVE!)
################################################################################
if [[ -x /Users/gabeconradi/.letsgo/bin/letsgo ]]
then
source /Users/gabeconradi/.letsgo/config/shell/zsh/setup.completion.zsh
fi
################################################################################
# -- This block was injected automatically by letsgo (DO NOT REMOVE!)
################################################################################