-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc
208 lines (169 loc) · 5.54 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
207
208
# -*- mode: sh; sh-shell: zsh; -*-
HISTFILE=$HOME/.zhistory
HISTSIZE=4096
SAVEHIST=4096
setopt extended_history
setopt append_history
setopt share_history
setopt hist_ignore_dups
setopt auto_pushd
setopt pushd_ignore_dups
setopt pushdminus
if grep -qs Microsoft /proc/version; then
export SHELL=$(which zsh)
export DISPLAY=localhost:0.0
export TERM=xterm-256color
unsetopt BG_NICE
fi
umask 0002
export EDITOR=emacsclient
export VISUAL=emacsclient
export SUDO_EDITOR=$(which emacsclient)
export LANG=ja_JP.UTF-8
setopt auto_cd
setopt multios
setopt prompt_subst
[[ -n "$WINDOW" ]] && SCREEN_NO="%B$WINDOW%b " || SCREEN_NO=""
setopt transient_rprompt
setopt ignore_eof
alias fixcomp="compaudit 2>&1 | grep -v 'There are insecure directories:' | xargs chmod go-w"
alias tmux-pbcopy="tmux showb | pbcopy"
export SPACESHIP_BATTERY_SHOW=false
export SPACESHIP_DIR_TRUNC=0
export SPACESHIP_EXIT_CODE_SHOW=true
export SPACESHIP_NODE_SHOW=false
export SPACESHIP_DIR_TRUNC_REPO=false
ZNAP_DIR=$HOME/.znap
if [[ ! -f $ZNAP_DIR/zsh-snap/znap.zsh ]]; then
git clone --depth 1 -- https://github.com/marlonrichert/zsh-snap.git $ZNAP_DIR/zsh-snap
fi
zstyle ':znap:*' repos-dir $ZNAP_DIR
source $ZNAP_DIR/zsh-snap/znap.zsh
znap prompt denysdovhan/spaceship-prompt
znap source zsh-users/zsh-syntax-highlighting
znap source zsh-users/zsh-autosuggestions
znap source jreese/zsh-titles
znap source zpm-zsh/ls
znap source zshzoo/cd-ls
znap source ohmyzsh/ohmyzsh lib/{key-bindings,completion}
znap install zsh-users/zsh-completions
export FZF_DEFAULT_OPTS='--height 40% --reverse --border --bind ctrl-v:page-down,alt-v:page-up'
bindkey '^x^d' fzf-cd-widget
bindkey '^x^f' fzf-file-widget
fzf-z-widget() {
local ret=$(z | sort -rn | cut -c 12- | fzf +s --query "$*")
if [[ -z "$ret" ]]; then
zle redisplay
return 0
fi
BUFFER+="cd $ret"
zle accept-line
}
zle -N fzf-z-widget
bindkey '^x^r' fzf-z-widget
fco() {
local tags branches target
tags=$(
git tag | awk '{print "\x1b[31;1mtag\x1b[m\t" $1}') || return
branches=$(
git branch --all | grep -v HEAD |
sed "s/.* //" | sed "s#remotes/[^/]*/##" |
sort -u | awk '{print "\x1b[34;1mbranch\x1b[m\t" $1}') || return
target=$(
(echo "$tags"; echo "$branches") |
fzf --no-hscroll --ansi +m -d "\t" -n 2) || return
git checkout $(echo "$target" | awk '{print $2}')
}
# fd - cd to selected directory
fd() {
local dir
dir=$(find ${1:-.} -path '*/\.*' -prune \
-o -type d -print 2> /dev/null | fzf +m) &&
cd "$dir"
}
# fda - including hidden directories
fda() {
local dir
dir=$(find ${1:-.} -type d 2> /dev/null | fzf +m) && cd "$dir"
}
# fdr - cd to selected parent directory
fdr() {
local declare dirs=()
get_parent_dirs() {
if [[ -d "${1}" ]]; then dirs+=("$1"); else return; fi
if [[ "${1}" == '/' ]]; then
for _dir in "${dirs[@]}"; do echo $_dir; done
else
get_parent_dirs $(dirname "$1")
fi
}
local DIR=$(get_parent_dirs $(realpath "${1:-$PWD}") | fzf-tmux --tac)
cd "$DIR"
}
# cdf - cd into the directory of the selected file
cdf() {
local file
local dir
file=$(fzf +m -q "$1") && dir=$(dirname "$file") && cd "$dir"
}
# https://unix.stackexchange.com/a/159254
alias urlencode='python3 -c "import sys, urllib.parse as ul; print(ul.quote_plus(sys.stdin.read()))"'
alias urldecode='python3 -c "import sys, urllib.parse as ul; print(ul.unquote_plus(sys.stdin.read()))"'
alias history="history -E 0"
alias l='ls -lah'
alias ll='ls -lh'
unalias rg &>/dev/null || true
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
if [[ -f /usr/local/opt/asdf/asdf.sh ]]; then
. /usr/local/opt/asdf/etc/bash_completion.d/asdf.bash
fi
if [[ -f $HOME/.asdf/asdf.sh ]]; then
. $HOME/.asdf/completions/asdf.bash
fi
[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local || true
if [ -n "${ZPROF}" ] && (which zprof > /dev/null); then
zprof | less
fi
if [[ -f /usr/local/bin/terraform ]]; then
autoload -U +X bashcompinit && bashcompinit
complete -o nospace -C /usr/local/bin/terraform terraform
fi
# The next line updates PATH for the Google Cloud SDK.
if [ -f $HOME/google-cloud-sdk/path.zsh.inc ]; then . $HOME/google-cloud-sdk/path.zsh.inc; fi
# The next line enables shell command completion for gcloud.
if [ -f $HOME/google-cloud-sdk/completion.zsh.inc ]; then . $HOME/google-cloud-sdk/completion.zsh.inc; fi
if (command -v aws-vault > /dev/null); then
eval "$(aws-vault --completion-script-zsh)"
fi
if [[ "$INSIDE_EMACS" = 'vterm' ]]; then
alias clear='vterm_printf "51;Evterm-clear-scrollback";tput clear'
fi
vterm_printf(){
if [ -n "$TMUX" ] && ([ "${TERM%%-*}" = "tmux" ] || [ "${TERM%%-*}" = "screen" ] ); then
# Tell tmux to pass the escape sequences through
printf "\ePtmux;\e\e]%s\007\e\\" "$1"
elif [ "${TERM%%-*}" = "screen" ]; then
# GNU screen (screen, screen-256color, screen-256color-bce)
printf "\eP\e]%s\007\e\\" "$1"
else
printf "\e]%s\e\\" "$1"
fi
}
vterm_prompt_end() {
vterm_printf "51;A$(whoami)@$(hostname):$(pwd)";
}
setopt PROMPT_SUBST
PROMPT=$PROMPT'%{$(vterm_prompt_end)%}'
# https://github.com/doomemacs/doomemacs/issues/2578#issuecomment-593797300
if [[ "$TERM" == "dumb" ]]; then
unset zle_bracketed_paste
unset zle
PS1='$ '
return
fi
if (command -v zoxide > /dev/null); then
eval "$(zoxide init zsh --cmd cd)"
fi
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"