-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
443 lines (380 loc) · 10.8 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
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# always use tmux
#if [[ ! $TERM =~ screen ]]; then
#exec tmux
#fi
# Path to your oh-my-zsh installation.
export ZSH=/home/steven/.oh-my-zsh
# don't let zsh rename tmux windows
#export DISABLE_AUTO_TITLE="true"
# themes in ~/.oh-my-zsh/themes/
ZSH_THEME="agnoster"
#af-magic
HIST_STAMPS="mm/dd/yyyy"
# plugins in ~/.oh-my-zsh/plugins/
plugins=(git vi-mode)
export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl"
source $ZSH/oh-my-zsh.sh
# virtualenv
export WORKON_HOME=$HOME/.virtualenvs
source /usr/bin/virtualenvwrapper.sh
unsetopt AUTO_CD
export PATH=$PATH:/home/steven/bin:/home/steven/Android/Sdk/platform-tools
export VISUAL="nvim"
export EDITOR="nvim"
export ANDROID_HOME=/home/steven/Android/Sdk
# zsh vi-mode editor
export VISUAL="nvim"
export MPD_HOST="/tmp/mpd.sock"
# edit
alias vim="nvim"
alias evimrc="vim ~/dotfiles/init.vim"
alias ewm="vim ~/dotfiles/awesome/rc.lua"
alias etmux="vim ~/dotfiles/.tmux.conf"
alias emp="vim ~/dotfiles/.ncmpcpp/config"
alias empd="vim ~/dotfiles/.mpd/mpd.conf"
alias erc="nvim ~/.zshrc"
alias src="source ~/.zshrc"
# to dirs
alias towm="cd ~/.config/awesome"
alias torepos="cd ~/GitRepos"
alias tosat="torepos; cd SFUSat"
alias todots="cd ~/dotfiles"
alias todb="cd ~/Dropbox"
alias todl="cd ~/Downloads"
# git
# mnemonic: git log history
alias glh="echo \"usage eg: glh -L49,62:SFUsat/sfu_task_main.c\";git log --topo-order --graph -u"
alias gl="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
# execute
alias xwifi="systemctl start netctl-auto@wlp1s0"
alias xwifikill="sudo ip link set wlp1s0 down"
alias xwifiup="sudo ip link set wlp1s0 up"
alias xdb="dropbox &|"
alias mp3dl="cd $HOME/Music && youtube-dl --extract-audio -f bestaudio --audio-format mp3 --no-playlist"
alias xsd="sudo mount -t auto /dev/sdb1 /mnt/sd"
alias xusb="sudo mount /dev/sdb1 /mnt/usb"
alias xunmountsd="sync; sudo umount /mnt/sd"
alias xunmountusb="sync; sudo umount /mnt/usb"
alias xtags="ctags -R --exclude=.git .; du -sh tags"
alias xstudio="~/Downloads/android-studio/bin/studio.sh >> /dev/null 2>&1 &|"
# TI
alias xhalcogen="wine ~/ti/Hercules/HALCoGen/v04.06.00/HALCOGEN.exe"
alias xccs="~/ti/ccsv7/eclipse/ccstudio"
alias xuniflash="sudo /opt/ti/uniflash_4.1/node-webkit/nw"
# program re-aliases
# ipython in venv
alias ipy="python -c 'import IPython; IPython.terminal.ipapp.launch_new_instance()'"
# always show statusbar, scale to 1000px horiz, vi keys
alias qiv="qiv -I -w 1000 --vikeys"
alias pam="~/bin/pulse-mixer.py"
# system alias
# list hidden, human size, sort ctime, reverse
alias l="ls -lahtcr"
alias pkgs="grep -n 'pacman -S .*' /var/log/pacman.log"
alias wtf="ping 8.8.8.8"
# get more usb info (bus, port, etc)
alias xlsusb='sudo cat /sys/kernel/debug/usb/devices | grep -E "^([TSPD]:.*|)$"'
# sleep screen
alias xsleep="xset dpms force standby"
alias xbat="cat /sys/class/power_supply/BAT1/{status,capacity}"
# stop ghostscript from coming up when I mistype gst (git status alias)
alias gs=""
# monitor
alias xmonoff="xrandr --output LVDS1 --off --output HDMI1 --primary --mode 1920x1080"
alias xmonon="xrandr --output LVDS1 --primary --auto --output HDMI1 --off"
alias xhdmi="xrandr --output HDMI1 --primary --mode 1920x1080 --output LVDS1 --auto --below HDMI1"
alias xhdmidup="xrandr --output HDMI1 --primary --mode 1920x1080 --same-as LVDS1"
alias xhdmioff="xrandr --output HDMI1 --off --output LVDS1 --primary --auto"
enable2mon() {
echo "Dual Screen on"
xrandr --output HDMI1 --primary --mode 1920x1080
xrandr --output LVDS1 --off
xrandr --output LVDS1 --auto --below HDMI1
}
##### notes
### set eastern timezone
# $ sudo timedatectl set-timezone Canada/Eastern
### clipboard stuff
# CLIPBOARD output: xsel -bo
# PRIMARY input: xsel -i
### xclip cat image to clipboard with proper types
# $ cat 3.4fig3.png | xclip -selection clipboard -t image/png
### updating YCM
## navigate to ~/.config/nvim/plugged/YCM
# $ ./install.py --clang-completer -tern-completer
## if vim complains about not finding python3...
# $ sudo pip install --upgrade neovim
### get args from prev command
# $ !line :column
# $ !* all args, !:0 command name, !:2 second arg, !:$ last arg
### bluetooth excursion
# $ systemctl start bluetooth.service
## block/unblock bluetooth (power saving measure)
# $ rfkill <block|unblock> bluetooth
# $ bluetoothctl
## $ power on
## $ agent on
## $ connect <bluetooth mac>
## $ exit
# $ pacmd set-card-profile <bluez_index> a2dp_sink
### netcat things
## server
# $ netcat -l -p 4444 localhost
## client
# $ netcat localhost 4444
### pa stuff
# $ pulseaudio --kill
# $ pamixer
# $ pactl
# $ pacmd
## sinks http://unix.stackexchange.com/questions/65246/change-pulseaudio-input-output-from-shell
# $ pactl list short sink-inputs
# $ pactl move-sink-input <ID> <SINK>
## reset alsa when fubar
# $ alsactl restore
### cpulimit
# $ cpulimit -l <percent 1..100> -p <pid>
### tar lol
## make archive
# $ tar -zcvf out.tar.gz ./dir
## extract archive
# $ tar -zxvf out.tar.gz -C ./out
### sd format
## fat32
# get disk
# $ lsblk
# partition it, enter 0xb for W95 FAT32
# $ sudo fdisk /dev/sdb
# format it
# $ sudo mkdosfs -F 32 /dev/sdb1
# use it
# $ sudo mount -t auto /dev/sdb1 /mnt/sd
### move random 2500 files in curr directory to dest dir
# $ find . -type f | shuf -n 2500 | xargs -I '{}' mv {} ~/dest
### send gui notification
# $ notify-send hi
### mount android filesystem over network
## mount
# install and setup "sshelper app"
# $ mkdir ~/mnt/axon
# $ sshfs ANDROID_IP:/storage/emulated/0 ~/mnt/axon -p 2222
## unmount
# $ umount ~/mnt/axon
### transmission
# $ transmission-daemon --auth --username steven --password 2552 --port 9091 --allowed "127.0.0.1"
# screenshot to clipboard
xscn() {
sleep 1; maim -s | xclip -selection clipboard -t image/png
}
# screenshot to file
xscnf() {
sleep 1; maim -s > $1
}
# screenshot to temp
xscnt() {
xclip -selection clipboard -t image/png -o > /tmp/screenshot.png
}
# fast bluetooth speaker, anker
xbt () {
echo -e 'power on\nconnect C9:50:76:9E:51:4D\nquit' | bluetoothctl
}
xnobt () {
echo -e 'disconnect C9:50:76:9E:51:4D\nquit' | bluetoothctl
}
# replace in out
replace() {
ag -l $1 | xargs perl -pi.bak -e "s/$1/$2/g"
}
# throw away stdout and stderr, and disown
pdf() {
zathura $1 &> /dev/null &|
}
# control print service
ccups() {
systemctl $1 org.cups.cupsd.service
}
# tonas USER PASS
tonas() {
smbclient //192.168.0.130/Media $2 -U $1
}
# mountnas USER PASS
mountnas() {
sudo mkdir /mnt/nas
sudo mount -t cifs //192.168.0.130/Media /mnt/nas -o user=$1,password=$2
}
# unmount nas, all, lazy
umountnas() {
sudo umount -a -t cifs -l /mnt/nas
}
# doc viewer
word() {
doc_loc_virtual="Z:/$PWD/$1"
wine "C:\Program Files (x86)\Microsoft Office\OFFICE11\WORDVIEW.EXE" $doc_loc_virtual
}
setbn() {
sudo tee /sys/class/backlight/intel_backlight/brightness <<< $1
}
setb() {
case $1 in
h|'')
setbn 4650;;
m)
setbn 1000;;
l)
setbn 0;;
esac
return
if [[ "$1" == "h" || -z $1 ]]; then
setbn 4650
elif [[ "$1" == "m" ]]; then
setbn 2000
elif [[ "$1" == "l" ]]; then
setbn 0
fi
}
# fast cd to school hw
tohw() {
#PS3="Pick dir: "
todb;
cd school;
# init empty array
dirs=()
for DIR in `find . -mindepth 1 -maxdepth 1 -type d`; do
dirs+=($DIR)
done
# if passed index and index exists in dirs, cd to it
if [[ -n $1 && -n ${dirs[$1]} ]]; then
cd ${dirs[$1]}
return
fi
select opt in "${dirs[@]}"
do
# if opt is empty, ask again
if [[ -z $opt ]]; then
continue
fi
case $REPLY in
*)
cd $opt
break
;;
esac
done
}
# 3dprinting: mv gcode to sd
xgcode() {
# init empty array
gcodeFiles=()
# find ~/Downloads -cnewer ~/Downloads/z_stop_upSlic3r.gcode -name "*.gcode"
# find ~/Downloads -name "*.gcode" -exec ls -t "{}" +;
for gcode in `find ~/Downloads -name "*.gcode" -exec ls -t "{}" +;`; do
gcodeFiles+=($gcode)
done
# if passed index and index exists in gcodeFiles, move it
if [[ -n $1 && -n ${gcodeFiles[$1]} ]]; then
sudo cp -v ${gcodeFiles[$1]} /mnt/sd
return
fi
select opt in "${gcodeFiles[@]}"
do
# if opt is empty, ask again
if [[ -z $opt ]]; then
continue
fi
case $REPLY in
*)
sudo cp -v $opt /mnt/sd
break
;;
esac
done
}
# trim mp4 start end
# ffmpeg -i movie.mp4 -ss 00:00:03 -t 00:00:08 -async 1 cut.mp4
# mp4 to gif
# ffmpeg -i input.mp4 -vf scale=320:-1 -r 10 -f image2pipe -vcodec ppm - | \
# convert -delay 10 -loop 0 - output.gif
# colorize manpages
man() {
env LESS_TERMCAP_mb=$'\E[01;31m' \
LESS_TERMCAP_md=$'\E[01;38;5;74m' \
LESS_TERMCAP_me=$'\E[0m' \
LESS_TERMCAP_se=$'\E[0m' \
LESS_TERMCAP_so=$'\E[38;5;246m' \
LESS_TERMCAP_ue=$'\E[0m' \
LESS_TERMCAP_us=$'\E[04;38;5;146m' \
man "$@"
}
# fix keys
# delete key
#bindkey "^[[3~" delete-char
# home key
#bindkey "^[[7~" beginning-of-line
# end key
#bindkey "^[[8~" end-of-line
# shift up down left right arrows
#^[[5~^[[6~^[[7~^[[8~
# save path on cd
function cd {
builtin cd $@
pwd > ~/.last_dir
}
# restore last saved path
if [ -f ~/.last_dir ]
then cd `cat ~/.last_dir`
fi
# end config
# --------------------------------------------------------------------------------
# Auto-completion
# ---------------
if [[ -f /usr/share/zsh/site-functions/_fzf ]]; then
source /usr/share/zsh/site-functions/_fzf
fi
# Key bindings
# ------------
if [[ $- == *i* ]]; then
# CTRL-T - Paste the selected file path(s) into the command line
__fsel() {
local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
-o -type f -print \
-o -type d -print \
-o -type l -print 2> /dev/null | sed 1d | cut -b3-"}"
eval "$cmd" | $(__fzfcmd) -m | while read item; do
printf '%q ' "$item"
done
echo
}
__fzfcmd() {
[ ${FZF_TMUX:-1} -eq 1 ] && echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
}
fzf-file-widget() {
LBUFFER="${LBUFFER}$(__fsel)"
zle redisplay
}
zle -N fzf-file-widget
bindkey '^T' fzf-file-widget
# ALT-C - cd into the selected directory
fzf-cd-widget() {
local cmd="${FZF_ALT_C_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
-o -type d -print 2> /dev/null | sed 1d | cut -b3-"}"
cd "${$(eval "$cmd" | $(__fzfcmd) +m):-.}"
zle reset-prompt
}
zle -N fzf-cd-widget
bindkey '\ec' fzf-cd-widget
# CTRL-R - Paste the selected command from history into the command line
fzf-history-widget() {
local selected num
selected=( $(fc -l 1 | $(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r -q "${LBUFFER//$/\\$}") )
if [ -n "$selected" ]; then
num=$selected[1]
if [ -n "$num" ]; then
zle vi-fetch-history -n $num
fi
fi
zle redisplay
}
zle -N fzf-history-widget
bindkey '^R' fzf-history-widget
fi
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh