-
Notifications
You must be signed in to change notification settings - Fork 2
/
.zshrc2
202 lines (190 loc) · 6.53 KB
/
.zshrc2
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
# env for shell
export TERM="xterm-256color"
if (command -v locale >/dev/null) && ( locale -a | grep -qxE "C.UTF-8|C.utf8" ); then
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
else
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
fi
export DOTFILES=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
export PATH="$PATH:$DOTFILES/scripts"
export EDITOR='vim'
# env for apps
export PYTHONIOENCODING='UTF-8'
export GPG_TTY=$(tty)
export LESS_TERMCAP_md=$'\E[01;33m'
export VIRTUAL_ENV_DISABLE_PROMPT=1
# env for dfs
if [[ -f ~/.config/dotfiles/env ]]; then set -a; source ~/.config/dotfiles/env; set +a; fi
export DFS_OS_TYPE="$("$DOTFILES/tools/common.sh" get_os_type)"
# antigen
if [[ "$DFS_NO_WALL" == "1" ]]; then
ANTIGEN_URL="https://raw.githubusercontent.com/zsh-users/antigen/develop/bin/antigen.zsh"
ANTIGEN_OMZ_REPO_URL="https://github.com/ohmyzsh/ohmyzsh.git"
ANTIGEN_PLUGINS=(
"https://github.com/zdharma-continuum/fast-syntax-highlighting"
"https://github.com/zsh-users/zsh-completions"
"https://github.com/zsh-users/zsh-autosuggestions"
)
else
ANTIGEN_URL="https://gitee.com/dictxiong/antigen/raw/develop/bin/antigen.zsh"
ANTIGEN_OMZ_REPO_URL="https://gitee.com/dictxiong/ohmyzsh.git"
ANTIGEN_PLUGINS=(
"https://gitee.com/dictxiong/fast-syntax-highlighting"
"https://gitee.com/dictxiong/zsh-completions"
"https://gitee.com/dictxiong/zsh-autosuggestions"
)
fi
ANTIGEN="$HOME/antigen.zsh"
# Install antigen.zsh if not exist
if [ ! -f "$ANTIGEN" ]; then
echo "Installing antigen ..."
TMPFILE="/tmp/antigen.zsh"
if [ -x "$(which curl)" ]; then
curl -L "$ANTIGEN_URL" -o "$TMPFILE"
elif [ -x "$(which wget)" ]; then
wget "$ANTIGEN_URL" -O "$TMPFILE"
else
echo "ERROR: please install curl or wget before installation !!"
exit
fi
if [ ! $? -eq 0 ]; then
echo ""
echo "ERROR: downloading antigen.zsh ($ANTIGEN_URL) failed !!"
exit
fi;
echo "move $TMPFILE to $ANTIGEN"
mv "$TMPFILE" "$ANTIGEN"
fi
# config and enable antigen
source "$ANTIGEN"
# enable plugins
antigen use oh-my-zsh
ANTIGEN_PLUGINS+=(
"command-not-found"
"docker"
"extract"
"fzf"
"git"
"magic-enter"
"per-directory-history"
"pip"
"podman"
"python"
"ripgrep"
"rsync"
"systemd"
"timer"
"tmux"
"ufw"
"z"
)
for i in ${ANTIGEN_PLUGINS[*]}; do
if [[ -z $ANTIGEN_EXCLUDE || ! $i =~ $ANTIGEN_EXCLUDE ]]; then
antigen bundle $i
fi
done
# select theme
TMP_THEME=ys
if [[ -e /.dockerenv ]]; then
TMP_THEME=robbyrussell
echo "==========================="
echo "This is in docker container"
echo "==========================="
fi
antigen theme ${ZSH_THEME:-$TMP_THEME}
# apply
antigen apply
# end of antigen config
# beacon
if [[ -z "$DFS_INITED" && -z "$CI" ]]; then
if [[ "$EUID" == "0" ]]; then
"$DOTFILES/tools/common.sh" apost_beacon "sys.login.root" "$(who am i | sed -E 's/ +/ /g' | awk '$1=$1')" 2>/dev/null
else
"$DOTFILES/tools/common.sh" apost_beacon "sys.login.user" "$(who am i | sed -E 's/ +/ /g' | awk '$1=$1')" 2>/dev/null
fi
fi
# alias
alias "pls"='sudo $(fc -ln -1)'
alias "se"='sudo -sE'
alias "sl"='sudo zsh -l'
alias "cps"='rsync -avh --info=progress2'
alias "mvs"='rsync -avh --info=progress2 --remove-source-files'
if [[ "$DFS_OS_TYPE" == "linux" ]]; then alias "ping"='ping -n'; alias "ping6"='ping6 -n'; fi
if [[ "$DFS_OS_TYPE" == "msys" ]]; then alias "tmux"='script -qO /dev/null -c "tmux -u"'; fi
alias "pbd"='ping baidu.com'
alias "p114"='ping 114.114.114.114'
alias "p666"='ping6 2001:da8::666'
alias "cbd"='curl http://www.baidu.com'
alias "cbds"='curl https://www.baidu.com'
alias "gdebug"='git add -A; git commit --allow-empty -m "bug fix ($(date))"'
alias "ls"='ls --color=tty --time-style="+%y-%m-%d %H:%M"'
alias "l"='ls -lAGh'
alias "jc"='journalctl'
alias "jce"='jc -e'
alias "jceu"='jc -eu'
alias "jcf"='jc -f'
alias "jcfu"='jc -fu'
gbes() { git for-each-ref --sort=-committerdate refs/heads refs/remotes --format="%(authordate:format:%y-%m-%d.%a %H:%M %z)|%(color:red)%(objectname:short)|%(color:yellow)%(refname:short)%(color:reset)|%(color:reset)%(authorname): %(color:green)%(subject)" --color=always | column -ts"|" | less -FX }
sagt() { eval "$($DOTFILES/tools/sagent.sh $@)" }
# key bindings
bindkey "^b" beginning-of-line # ctrl+b
bindkey "\eOH" beginning-of-line
bindkey "\e[H" beginning-of-line # home; termius
bindkey "\e[1~" beginning-of-line
bindkey "^e" end-of-line # ctrl+e
bindkey "\eOF" end-of-line
bindkey "\e[F" end-of-line # end; termius
bindkey "\e[4~" end-of-line
bindkey "\ef" forward-word # alt+f
bindkey "\e[5C" forward-word
bindkey "\e\e[C" forward-word # alt+right_arrow; iterm2
bindkey "\e[1;5C" forward-word # alt+right_arrow; termius
bindkey "\eb" backward-word # alt+e
bindkey "\e[5D" backward-word
bindkey "\e\e[D" backward-word # alt+left_arrow; iterm2
bindkey "\e[1;5D" backward-word # alt+left_arrow; termius
bindkey "\ed" delete-char # alt+d
# mods
autoload zcalc
# dfs
dfs()
{
setopt local_options err_return pipe_fail
case $1 in
cd ) cd "$DOTFILES" ;;
update ) "$DOTFILES/update.sh" ;;
version ) (cd "$DOTFILES" && git rev-parse HEAD) ;;
vversion ) (cd "$DOTFILES" && git show) ;;
config )
mkdir -p ~/.config/dotfiles
$EDITOR ~/.config/dotfiles/env
;;
force-update ) (
cd "$DOTFILES"
git fetch --all
ref=$(git symbolic-ref --short HEAD 2> /dev/null) || ref=$(git rev-parse --short HEAD 2> /dev/null) || return 0
for i in $(git for-each-ref refs/heads --format='%(refname)') ; do git checkout ${i#refs/heads/} ; git pull --ff-only ; done
git checkout -c advice.detachedHead=false $ref)
;;
reset )
antigen reset 1> /dev/null
rm -rf $HOME/.antigen
"$DOTFILES/install.sh" -r
dfs update
"$DOTFILES/install.sh" -i
echo 'Done. Please open a new shell to see the changes.'
;;
log ) "$DOTFILES/tools/common.sh" "post_log" "INFO" "dfs" "$2" ;;
beacon ) "$DOTFILES/tools/common.sh" "post_beacon" "$2" "$3" ;;
* ) echo "unknown command \"$1\". available: update, force-update, version, reset, cd, log" ;;
esac
}
# motd
if [[ "$DFS_INITED" != "1" && -n "$DFS_UPDATE_CHANNEL" && "$DFS_UPDATE_CHANNEL" != "main" ]]; then
echo dotfiles not in the main channel. use with caution.
fi
# clean
unset i
export DFS_INITED=1