-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc
245 lines (215 loc) · 7.88 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# mbed-cli bash completion
# https://github.com/eddiezane/lunchy/issues/57
# for more details
autoload -U +X bashcompinit && bashcompinit
autoload -U +X compinit && compinit
# source /home/liparadise/.bash_completion.d/mbed
# End of mbed-cli bash completion
# NTUOSC ml environmental variables
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/bin/virtualenvwrapper.sh
# end of NTUOSC ml environmental variables
#
path=("$HOME/.cargo/bin" "/usr/local/bin" "$path[@]")
typeset -U PATH path
export PATH
# Path to your oh-my-zsh installation.
export ZSH="${HOME}/.oh-my-zsh"
export ZDOTDIR="${HOME}/.zsh"
# Path for golang
# export GOPATH=$HOME/go
DISABLE_AUTO_UPDATE="true"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="evil_apple"
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
)
source $ZSH/oh-my-zsh.sh
## edit line in vim
export VISUAL="nvim"
autoload edit-command-line
zle -N edit-command-line
alias nv="nvim"
alias nvc="nvim --clean +'set nu ai ic sc et sts=4 ts=4 hlsearch paste|colorscheme habamax'"
alias cp="cp -i"
alias mv="mv -i"
alias rm="rm -i"
alias lr="ls -tr"
alias ll="ls -alF"
alias tmux="tmux -u" # utf-8 support
alias kl="keychain -l"
alias ks="source ${HOME}/.keychain/${HOST}-sh"
alias tl="tmux ls"
alias ta="tmux a"
alias jkl="jupyter kernelspec list"
alias jku="jupyter kernelspec uninstall"
alias socker="sudo docker"
alias clangmake="CC=/usr/bin/clang CXX=/usr/bin/clang++ cmake"
alias rsavp="rsync -av --progress"
alias git-no-mode="git -c core.fileMode=false status"
alias git-push-new-branch="git push --set-upstream origin \$(git describe --all --exact-match | sed 's~heads/~~')"
# handy `git status` shortcut
function my_git_util() {
local dir
local action
dir=""
action=""
case "${1}" in
status) action="status -u";;
diff) action="diff";;
log) action="log";;
esac
[ -z "${action}" ] && echo "wrong usage" && return 1
[ -z "${debug}" ] || echo "argument is now '${#}: ${*}'"
case $# in
1)
{
dir="."
shift 1
};;
*)
{
[ -d "${2}" ] && dir="${2}"
shift 2
};;
esac
[ -z "${debug}" ] || echo "argument is now '${#}: ${*}'"
# The `dir` variable must be either empty or valid directory
# (except in the rare case where local `.` is no longer present,
# e.g. after `git checkout` or `rm -rf`;
# in that case we'd like to know what's going on anyway)
#
# `git rev-parse --show-toplevel` gives git root folder of that repo
# (note that it shows submodule root if submodule)
# finally show `git` output
#
# Note that we use `eval` to enable genuine shell argument passing (splitting),
# hence dangers that comes with `eval` applies.
# More on word splitting:
# https://unix.stackexchange.com/questions/419148
[ -z "${dir}" ] && echo "\"${dir}\" not defined" || \
printf "git ${action} for directory %s\n" "$(git -C "${dir}" rev-parse --show-toplevel)" && eval "git -C ${dir} ${action} ${*}"
}
alias gs="my_git_util status"
alias gd="my_git_util diff"
alias gl="my_git_util log"
function my_find_util {
local dir
local file_types
local search_phrase
dir=""
file_types=""
search_phrase=""
if [ $# -eq 1 ] && [ -n "${1}" ]; then
dir="."
search_phrase="${1}"
elif [ $# -eq 2 ] && [ -d "${1}" ] && [ -n "${2}" ]; then
dir="${1}"
search_phrase="${2}"
elif [ $# -eq 3 ] && [ -d "${1}" ]; then
dir="${1}"
file_types="-name \"${2}\""
search_phrase="${3}"
elif [ $# -gt 3 ] && [ -d "${1}" ]; then
dir="${1}"
# POSIX hack to get last argument
for __hack_get_last in "${@}"; do :; done
search_phrase="${__hack_get_last}"
# get all arguments except first and last
# note that the spaces remain in the variable
file_types="${*%"${search_phrase}"}"
file_types="${file_types#"${dir}"}"
# trim leading/trailing spaces
file_types="$(printf '%s' "${file_types}" | awk '{$1=$1;print}')"
# replace the space in between to '|'
file_types="$(printf '%s' "${file_types}" | sed -E 's/[[:space:]]+/|/g')"
echo "file_types is ${file_types}"
file_types="$(printf '%s' "${file_types}" | sed -E 's#([^|]+)#-name "\1"#g')"
echo "file_types is ${file_types}"
file_types="$(printf '%s' "${file_types}" | sed -E 's/\|/ -or /g')"
# finally add the parenthesis for `find`
file_types="\\( ${file_types} \\)"
fi
if [ -n "${dir}" ] && [ -n "${search_phrase}" ]; then
if [ -n "${MYSHELLDEBUG}" ]; then
echo "dir is ${dir}"
echo "file_types is ${file_types}"
echo "search_phrase is ${search_phrase}"
echo "<C-c> to cancel run"
sleep 5
fi
local cmd
cmd="find ${dir} -type f ${file_types} -print0 | xargs -0 -P7 grep -nH --color=always ${search_phrase}"
type wl-copy >/dev/null 2>&1 && printf '%s' "${cmd}" | wl-copy
type clip.exe >/dev/null 2>&1 && printf '%s' "${cmd}" | clip.exe
type xclip >/dev/null 2>&1 && printf '%s' "${cmd}" | xclip -sel c
echo 'Search command is in your clipboard, use e.g. "Shift + Insert"'
else
echo "unknown error"
exit 1
fi
}
alias google="my_find_util"
ks
function pgnd() {
cargo new ${1}
if [ -d ${1} ]; then
if [ -d ${1}/src ]; then
touch ${1}/src/lib.rs
fi
cd ${1}
fi
}
function CD(){
cd ${1}; cd $(pwd -P)
}
# function reboot_to_windows () {
# grub_windows_entry=$(sudo grep -i windows /boot/grub/grub.cfg | cut -d "'" -f 2)
# sudo grub-reboot "$grub_windows_entry"
# sudo sync; sudo sync; sudo systemctl reboot
# }
# https://stackoverflow.com/a/8811800/9933842
# liparadise_contains(string, substring)
#
# Returns 0 if the specified string contains the specified substring,
# otherwise returns 1.
function liparadise_contains() {
string="$1"
substring="$2"
if [ "${string#*"$substring"}" != "$string" ]; then
return 0 # $substring is in $string
else
return 1 # $substring is not in $string
fi
}
function liparadise_wm_type() {
loginctl show-session $(awk '/tty/ {print $1}' <(loginctl)) -p Type | awk -F= '{print $2}'
}
function copy() {
local binaries=""
grep -qi microsoft /proc/version && type 'clip.exe' >/dev/null && local binaries="${binaries}ms "
[ "$(liparadise_wm_type)" = "wayland" ] && type 'wl-copy' >/dev/null && local binaries="${binaries}wl "
xset q >/dev/null 2>&1 && type 'xclip' >/dev/null && local binaries="${binaries}x"
if [ $# -eq "1" ] && [ -f "${1}" ]; then
liparadise_contains "${binaries}" ms && clip.exe < "${1}"
liparadise_contains "${binaries}" wl && wl-copy < "${1}"
liparadise_contains "${binaries}" x && xclip -selection clipboard < "${1}"
return 0
elif [ $# -eq "2" ] && [ -f "${1}" ] && [ "${2}" -eq "${2}" ]; then
liparadise_contains "${binaries}" ms && sed -n "${2},${2}p" "${1}" | clip.exe
liparadise_contains "${binaries}" wl && sed -n "${2},${2}p" "${1}" | wl-copy
liparadise_contains "${binaries}" x && sed -n "${2},${2}p" "${1}" | xclip -sel c
return 0
elif [ $# -eq "3" ] && [ -f "${1}" ] && [ "${2}" -lt "${3}" ]; then
liparadise_contains "${binaries}" ms && sed -n "${2},${3}p" "${1}" | clip.exe
liparadise_contains "${binaries}" wl && sed -n "${2},${3}p" "${1}" | wl-copy
liparadise_contains "${binaries}" x && sed -n "${2},${3}p" "${1}" | xclip -sel c
return 0
fi
}