summary refs log tree commit diff stats
path: root/tag-zsh/config/zsh/zshrc
blob: da63e6470829a5668625d208a2f0446a6fa6da49 (plain)
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
# -*- mode: sh; -*-
source $ZPLUG_HOME/init.zsh

zplug "zsh-users/zsh-completions"
zplug "mafredri/zsh-async", use:async.zsh, if:"[[ $TERM != \"dumb\" ]]"
zplug "sindresorhus/pure", on:"mafredri/zsh-async", as:plugin, use:pure.zsh, if:"[[ $TERM != \"dumb\" ]]"
zplug "Tarrasch/zsh-autoenv", as:plugin
zplug "clvv/fasd", hook-build:"PREFIX=$HOME make install"
zplug "alanpearce/zsh-directory-history", at:"dirlog-as-zsh-function", as:command, use:"dirhist"
zplug "alanpearce/zsh-directory-history", at:"dirlog-as-zsh-function", as:plugin
zplug "caarlos0/zsh-open-pr", as:plugin
if [[ -n $commands[nix-env] ]]
then
	zplug "spwhitt/nix-zsh-completions", as:plugin
	fpath=($fpath $ZPLUG_REPOS/spwhitt/nix-zsh-completions)
fi

zplug "gerges/oh-my-zsh-jira-plus", as:plugin, if:"[[ ${(SN)HOST%spotcap} ]]"
zplug "lukechilds/zsh-better-npm-completion", if:"[[ -n $commands[npm] ]]", nice:10
zplug "hlissner/zsh-autopair", nice:10

WORDCHARS=${${WORDCHARS//[-.]}//[\/]}

if [[ ${path[(I)$HOME/bin ]} ]]
then
	path+=($HOME/bin)
fi

ls='\ls'
gnu_ls_options="-v --group-directories-first --color=auto"
gnu_ls_isodate="--time-style=long-iso"
bsd_ls_options="-p"
bsd_ls_isodate="-D '%F %k:%M'"

case $OSTYPE in
	darwin*)
		if [[ -n $commands[gls] ]]
		then
			ls='\gls'
			ls_options=$gnu_ls_options
			ls_isodate=$gnu_ls_isodate
		else
			ls_options=$bsd_ls_options
			ls_isodate=$bsd_ls_isodate
		fi
		;;
	freebsd*)
		ls_options=$bsd_ls_options
		ls_isodate=$bsd_ls_isodate
		;;
	linux-gnu)
		ls_options=$gnu_ls_options
		ls_isodate=$gnu_ls_isodate
		;;
esac
alias l="${ls} ${ls_options} -Bp"
alias l1="${ls} ${ls_options} -1"
alias ls="${ls} ${ls_options} -hF"
alias la="${ls} ${ls_options} -hA"
alias ll="${ls} ${ls_options} ${ls_isodate} -hl"
alias lal="ll -A"
alias lla="lal"
alias llr="ll -t"

zmodload zsh/terminfo

bindkey '\e[3~' delete-char

bindkey '\C-hd' describe-key-briefly

backward-argument () {
	local WORDCHARS="\!\`~#@$%^&*()-_=+[{]}\|;:,<.>/?\'\""
	zle backward-word
}

forward-argument () {
	local WORDCHARS="\!\`~#@$%^&*()-_=+[{]}\|;:,<.>/?\'\""
	zle forward-word
}

kill-argument () {
	local WORDCHARS="\!\`~#@$%^&*()-_=+[{]}\|;:,<.>/?\'\""
	zle backward-argument
	zle kill-word
}

zle -N backward-argument
zle -N forward-argument
zle -N kill-argument
bindkey '\e^b' backward-argument
bindkey '\e^f' forward-argument
bindkey '\e^k' kill-argument

zle -C hist-complete complete-word _generic
zstyle ':completion:hist-complete:*' completer _history
bindkey '\e	' hist-complete

zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' '+m:{A-Z}={a-z}'
zstyle ':completion:*' completer _expand _complete _match

if [[ -z $SSH_AUTH_SOCK && $commands[ssh-agent] ]]
then
	eval $(ssh-agent)
fi

if zplug check Tarrasch/zsh-autoenv
then
	AUTOENV_FILE_ENTER=.envrc
	AUTOENV_HANDLE_LEAVE=0
	AUTOENV_LOOK_UPWARDS=1
fi

if zplug check sindresorhus/pure
then
	PURE_GIT_PULL=0
fi

if zplug check gerges/oh-my-zsh-jira-plus
then
	JIRA_RAPID_BOARD=true
fi

# Then, source plugins and add commands to $PATH
zplug load

# General configuration
setopt auto_cd 					# Change directories without `cd`

if zplug check zsh-users/zsh-completions
then
	autoload -U compinit && compinit
fi

if [[ $TERM == "dumb" ]]
then
	PROMPT="> "
else
	if zplug check sindresorhus/pure
	then
		autoload -Uz promptinit && promptinit
		prompt pure &> /dev/null
	else
		autoload -Uz vcs_info

		zstyle ':vcs_info:*' enable git
		zstyle ':vcs_info:*' use-simple true
		# only export two msg variables from vcs_info
		zstyle ':vcs_info:*' max-exports 2
		# vcs_info_msg_0_ = ' %b' (for branch)
		# vcs_info_msg_1_ = 'x%R' git top level (%R), x-prefix prevents creation of a named path (AUTO_NAME_DIRS)
		zstyle ':vcs_info:git*' formats ' %b' 'x%R'
		zstyle ':vcs_info:git*' actionformats ' %b|%a' 'x%R'

		# show username@host if logged in through SSH
		[[ "$SSH_CONNECTION" != '' ]] && prompt_pure_username=' %F{242}%n@%m%f'

		# show username@host if root, with username in white
		[[ $UID -eq 0 ]] && prompt_pure_username=' %F{white}%n%f%F{242}@%m%f'

		setopt prompt_subst
		setopt prompt_cr
		PROMPT='%F{blue}%~%f%F{242}${vcs_info_msg_0_}%f${prompt_pure_username}
%(?.%F{magenta}.%F{red})>%f '
	fi
fi

if zplug check clvv/fasd
then
	if [[ -n $commands[fasd] ]]
	then
		_FASD_DATA="$HOME/.cache/zsh/fasd-data"
		source =fasd

		fasd_cache="$HOME/.fasd-init-zsh"
		if [ "$(command -v fasd)" -nt "$fasd_cache" -o ! -s "$fasd_cache" ]; then
			fasd --init posix-alias zsh-hook zsh-ccomp zsh-ccomp-install >| "$fasd_cache"
		fi
		source "$fasd_cache"
		unset fasd_cache
	else
		echo "no fasd"
	fi
fi

if zplug check alanpearce/zsh-directory-history
then
	unsetopt flow_control 			# Let me use ^S and ^Q
	bindkey "$terminfo[kcuu1]" directory-history-search-backward
	bindkey "$terminfo[kcud1]" directory-history-search-forward

	bindkey -M emacs '^R' history-substring-search-up
	bindkey -M emacs '^S' history-substring-search-down
fi