-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_zshrc.tmpl
More file actions
171 lines (144 loc) · 4.94 KB
/
Copy pathdot_zshrc.tmpl
File metadata and controls
171 lines (144 loc) · 4.94 KB
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
# Set up the prompt
autoload -Uz promptinit
promptinit
#prompt adam1
# Use emacs keybindings even if our EDITOR is set to vi
bindkey -e
# History file configuration from ohmyzsh
# Keep 50000 lines of history within the shell and save it to ~/.zsh_history
[ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history"
[ "$HISTSIZE" -lt 50000 ] && HISTSIZE=50000
[ "$SAVEHIST" -lt 10000 ] && SAVEHIST=10000
# History command configuration
setopt extended_history # record timestamp of command in HISTFILE
setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE
setopt hist_ignore_dups # ignore duplicated commands history list
setopt hist_ignore_space # ignore commands that start with space
setopt hist_verify # show command with history expansion to user before running it
setopt share_history # share command history data
# Use modern completion system
autoload -Uz compinit
compinit
zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# enable zoxide https://github.com/ajeetdsouza/zoxide
eval "$(zoxide init zsh)"
# enable zmv
# e.g.: zmv -n 'abc(*)/file.txt' 'file-${1}.txt'
autoload -Uz zmv
alias zcp='zmv -C'
alias zln='zmv -L'
# avoid mistakes
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# rsync client over ssh
alias ssh-rsync='rsync -e ssh -Pachivz'
# convert timestamps to localtime
function tsatlocal() {
if [[ $# > 0 ]]; then
date -Iseconds -d "$1"
else
xargs -r -I{} date -Iseconds -d "{}"
fi
}
# convert timestamps to UTC
function tsatutc() {
if [[ $# > 0 ]]; then
date -Iseconds -u -d "$1"
else
xargs -r -I{} date -Iseconds -u -d "{}"
fi
}
# convert timestamps to timezone
function tsattz() {
if [[ $# > 0 ]]; then
env TZ=$2 date -Iseconds -d "$1"
else
awk '{system("env TZ=" $2 " date -Iseconds -d " $1)}'
fi
}
# convert seconds since epoch to timestamp
function unixasts() {
if [[ $# > 0 ]]; then
date -Iseconds -d "@$1"
else
xargs -r -I{} date -d "@{}"
fi
}
# convert timestamp to seconds since epoch
function tsasunix() {
if [[ $# > 0 ]]; then
date -d "$1" +"%s"
else
xargs -r -I{} date -d "{}" +"%s"
fi
}
# add utf-8 COMBINING LONG STROKE OVERLAY (U+0336)
function utf8lstroke() {
if [[ $# > 0 ]]; then
sed 's/\(.\)/\1\xcc\xb6/g' <<<"$1"
else
sed 's/\(.\)/\1\xcc\xb6/g'
fi
}
# op-env envfile command...
function op-env() {
op run --env-file="$HOME/.config/op/$1" -- "${@:2}"
}
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
{{ if (eq .chezmoi.osRelease.id "fedora") -}}
if [ -x /usr/bin/cowsay -a -x /usr/bin/fortune ]; then
fortune -a | cowsay -n -f $(find /usr/share/cowsay -name '*.cow' -printf '%f\n' | shuf -n1)
{{ else -}}
if [ -x /usr/games/cowsay -a -x /usr/games/fortune ]; then
fortune -a | cowsay -n -f $(ls -1 /usr/share/cowsay/cows/ | shuf -n1)
{{ end -}}
fi
# enable zsh-syntax-highlighting and zsh-autosuggestions
for extension in source zsh-autosuggestions zsh-syntax-highlighting ; do
for base in /usr /usr/local ; do
if [ -f $base/share/$extension/$extension.zsh ]; then
source $base/share/$extension/$extension.zsh
break
fi
done
done
unset base
unset extension
autoload -U colors && colors
# https://git-scm.com/book/en/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-Zsh
# https://github.com/zsh-users/zsh/blob/master/Misc/vcs_info-examples
# https://scriptingosx.com/2019/07/moving-to-zsh-06-customizing-the-zsh-prompt/
autoload -Uz vcs_info
precmd_vcs_info() { vcs_info }
precmd_functions+=( precmd_vcs_info )
setopt prompt_subst
PROMPT='%(?.%F{green}√.%F{red}?%?)%f %B%F{240}%1~%f%b %# '
RPROMPT=\$vcs_info_msg_0_
zstyle ':vcs_info:git:*' formats '%F{240}(%b)%r%f'
zstyle ':vcs_info:*' enable git
# Local Variables:
# mode: sh
# eval: (sh-set-shell "zsh")
# End: