-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc.local
285 lines (236 loc) · 6.81 KB
/
.zshrc.local
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#!/usr/bin/env zsh
########################
####### EXPORT #########
########################
export ZSH="$HOME/.zsh/"
export HISTORY_IGNORE="(ls|cd|pwd|exit|reboot|poweroff|history|cd -|cd ..|sudo poweroff -f|sudo reboot -f|code|code .|)"
export EDITOR="vim" # $EDITOR use Vim in terminal
export VISUAL="vim" # $VISUAL use Vim in GUI mode
export LANG=en_US.UTF-8
export PATH="$HOME/bin:$HOME/.cargo/bin:$HOME/.config/emacs/bin:$HOME/go/bin:$PATH"
#########################
######### PATH ##########
#########################
if [ -d "$HOME/.bin" ] ;
then PATH="$HOME/.bin:$PATH"
fi
if [ -d "$HOME/.local/bin" ] ;
then PATH="$HOME/.local/bin:$PATH"
fi
if [ -d "$HOME/Applications" ] ;
then PATH="$HOME/Applications:$PATH"
fi
if [ -d "$HOME/.cargo/bin" ]
then PATH="$HOME/.cargo/bin:$PATH"
fi
########################
###### SET VI MODE ######
#########################
# Comment this line out to enable default emacs-like bindings
bindkey -v
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
##########################
####### functions ########
##########################
SAVEIFS=$IFS
IFS=$(echo -en "")
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
echo " extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
else
for n in "$@"
do
if [ -f "$n" ] ; then
case "${n%,}" in
*.cbt|*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
tar xvf "$n" ;;
*.lzma) unlzma ./"$n" ;;
*.bz2) bunzip2 ./"$n" ;;
*.cbr|*.rar) unrar x -ad ./"$n" ;;
*.gz) gunzip ./"$n" ;;
*.cbz|*.epub|*.zip) unzip ./"$n" ;;
*.z) uncompress ./"$n" ;;
*.7z|*.arj|*.cab|*.cb7|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.pkg|*.rpm|*.udf|*.wim|*.xar)
7z x ./"$n" ;;
*.xz) unxz ./"$n" ;;
*.exe) cabextract ./"$n" ;;
*.cpio) cpio -id < ./"$n" ;;
*.cba|*.ace) unace x ./"$n" ;;
*)
echo "extract: '$n' - unknown archive method"
return 1
;;
esac
else
echo "'$n' - file does not exist"
return 1
fi
done
fi
}
mergeav() {
if [[ -z $1 || -z $2 ]]; then
echo "Usage: mergeav <videofile> <audiofile>"
fi
cp $1 $1.back
cp $2 $2.back
local ext="${1#*.}"
if ffmpeg -i $1 -i $2 -map 0:v -map 1:a -c:v copy -shortest "$(basename $1).new.$ext"; then
rm -v $1.back $2.back -f
else
echo "FAILED"
mv $1.back $1
mv $2.back $2
fi
}
# navigation
up () {
local d=""
local limit="$1"
# Default to limit of 1
if [ -z "$limit" ] || [ "$limit" -le 0 ]; then
limit=1
fi
for ((i=1;i<=limit;i++)); do
d="../$d"
done
# perform cd. Show error if cd fails
if ! cd "$d"; then
echo "Couldn't go up $limit dirs.";
fi
}
# aria2 download part to part
pdownload(){
while IFS= read -r line; do
printf '%s\n' "$line"
aria2c $line
done < $1
}
# cd and run code
cdcode (){
cd $1 && code .
}
venv(){
if [ -f .venv/bin/activate ]; then
. .venv/bin/activate
else
virtualenv .venv && . .venv/bin/activate
fi
}
edit(){
emacsclient -c -a 'emacs' $@ &> /dev/null &
}
# Created by fodev.org
fod(){
case $1 in
"--enable" | "-e")
export http_proxy=http://fodev.org:8118/
export https_proxy=https://fodev.org:8118/
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
export HTTP_PROXY=http://fodev.org:8118/
export HTTPS_PROXY=https://fodev.org:8118/
export NO_PROXY="localhost,127.0.0.1,localaddress,.localdomain.com"
echo "enable fod proxy !"
;;
"--disable" | "-d")
unset http_proxy
unset https_proxy
unset no_proxy
unset HTTP_PROXY
unset HTTPS_PROXY
unset NO_PROXY
echo "disable fod proxy !"
;;
*)
echo "Usage : fod [-e | --enable] [-d | --disable]"
echo "Example : "
echo " fod --enable for enable fod proxy "
echo " fod --disable for disable fod proxy "
;;
esac
}
mkrp() {
mkdir $1 && cd $1
git init
}
torrentdl(){
aria2c --continue=true -V --bt-save-metadata=true $@
}
###############
### ALIASES ###
###############
## root privileges
alias doas="doas --"
alias please="sudo -p '[please] Sir, Could You Please Enter Your password:'"
## vim
alias vi=vim
alias em="/usr/bin/emacs -nw"
alias emacs="emacsclient -c -a 'emacs'"
## doomemacs
alias doomsync="~/.config/emacs/bin/doom sync"
alias doomdoctor="~/.config/emacs/bin/doom doctor"
alias doomupgrade="~/.config/emacs/bin/doom upgrade"
alias doompurge="~/.config/emacs/bin/doom purge"
## add color to grep(s)
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
## confirm before overwriting something
alias cp="cp -i"
alias mv='mv -i'
alias rm='rm -i'
# alias "l" to exa with icons
alias l='exa -lah --git --icons'
## progress bar in cp/mv
alias cpg="cpg -g"
alias mvg="mvg -g"
## mtp-alias
alias sendphone='mtp-connect --sendfile'
## human-readable sizes
alias free='free -h'
alias df='df -h'
alias du='du -h'
## xdg
alias open='xdg-open'
## Terminals' command
if [ -f `which kitty` ]; then
## show img in terminal
alias icat="kitty +kitten icat"
## connect via ssh
alias issh="kitty +kitten ssh"
fi
# youtube-dl
alias yta-aac="youtube-dl --extract-audio --audio-format aac "
alias yta-best="youtube-dl --extract-audio --audio-format best "
alias yta-flac="youtube-dl --extract-audio --audio-format flac "
alias yta-m4a="youtube-dl --extract-audio --audio-format m4a "
alias yta-mp3="youtube-dl --extract-audio --audio-format mp3 "
alias yta-opus="youtube-dl --extract-audio --audio-format opus "
alias yta-vorbis="youtube-dl --extract-audio --audio-format vorbis "
alias yta-wav="youtube-dl --extract-audio --audio-format wav "
alias ytv-best="youtube-dl -f bestvideo+bestaudio "
# switch between shells
alias tobash="sudo chsh $USER -s /bin/bash && echo 'Now log out.'"
alias tozsh="sudo chsh $USER -s /bin/zsh && echo 'Now log out.'"
alias tofish="sudo chsh $USER -s /bin/fish && echo 'Now log out.'"
## use fzf plugin
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
## plugins
plugins=(git zsh-syntax-highlighting zsh-z)
for _plugin in $plugins; do
_path="${ZSH}plugin/${_plugin}/${_plugin}.zsh"
if [ -f $_path ]; then
source $_path
else
_path="${ZSH}plugin/${_plugin}/${_plugin}.plugin.zsh"
if [ -f $_path ]; then
source $_path
else
echo "[ZSH] plugin ${_plugin} not found."
fi
fi
done
export GPG_TTY=$(tty)