Dotfiles for my tiling window manager + terminal workflow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

490 lines
12 KiB

  1. # system {{{ #
  2. setopt extendedglob
  3. # vim mode {{{ #
  4. bindkey -v
  5. function zle-line-init zle-keymap-select {
  6. VIM_PROMPT="%{$fg_bold[yellow]%} [% NORMAL]% %{$reset_color%}"
  7. RPS1="${${KEYMAP/vicmd/$VIM_PROMPT}/(main|viins)/} $EPS1"
  8. zle reset-prompt
  9. }
  10. zle -N zle-line-init
  11. zle -N zle-keymap-select
  12. export KEYTIMEOUT=1
  13. # }}} vim mode #
  14. # command line related {{{ #
  15. # search history
  16. bindkey '\e[A' history-beginning-search-backward
  17. bindkey '\e[B' history-beginning-search-forward
  18. function src() { source $1 ; }
  19. alias cs='printf "\033c"'
  20. alias hst="history"
  21. alias nf="neofetch"
  22. alias rur="xrdb ~/.Xresources"
  23. function gvx() { urxvt --help 2>&1 | grep $1 ; }
  24. # list file sizes in megabytes with depth 1
  25. alias dum="du -d 1 -B M"
  26. # pacman
  27. function pcs() { sudo pacman -S $1 ; }
  28. function pcr() { sudo pacman -R $1 ; }
  29. function aus() { aurman -S $1 ; }
  30. function mpk() { makepkg -si ; }
  31. alias grbm="sudo grub-mkconfig -o /boot/grub/grub.cfg"
  32. # install deb files
  33. function ideb() { sudo dpkg -i $1 ; }
  34. function cld() { colordiff -y --suppress-common-lines $1 $2 ; }
  35. alias grep='grep --color=auto'
  36. # for finding files by name
  37. function rfnd() { find . -name "$1" ; }
  38. # find text inside files
  39. function rgrp() { grep -r $1 * ; }
  40. function cpd() { cp -avr $1 $2 ; }
  41. # extract tar archive
  42. function untar() { tar -xzvf $1 && rm $1; }
  43. function runzip() { unzip $1 && rm $1; }
  44. # }}} command line related #
  45. # directory-related {{{ #
  46. alias l='ls -a'
  47. alias ll='ls -alF'
  48. function f() { cd $1 && pwd > ~/.last_dir && ls -a ; }
  49. # restore last dir
  50. if [ -f ~/.last_dir ]
  51. then cd `cat ~/.last_dir`
  52. fi
  53. function rmr() { rm -rf $1 ; }
  54. # todo: fix
  55. # function f.() { f $(printf "%0.s../" $(seq 1 $1 )) ; }
  56. alias "f."="f .."
  57. alias "f.2"="f ..."
  58. alias fd="f ~/Downloads"
  59. function mvd() { mv $1 ~/Downloads ; }
  60. alias fds="f ~/Downloads/sch"
  61. alias doc="f ~/Documents"
  62. alias cfg="f ~/.config"
  63. # }}} directory-related #
  64. # power options {{{ #
  65. alias s="systemctl suspend"
  66. alias sd="sudo shutdown 0"
  67. alias reb="sudo shutdown -r 0"
  68. alias lo="i3-msg exit"
  69. # }}} power options #
  70. # rotate monitor {{{ #
  71. function rt() {
  72. output="HDMI-0"
  73. if [ "$1" = "s" ]
  74. # if [ "${1:0:1}" = "s" ]
  75. then
  76. output="DVI-I-1"
  77. fi
  78. dir="normal"
  79. if [ "$2" = "r" ]
  80. # if [ "${1:1:2}" = "r" ]
  81. then
  82. dir="right"
  83. fi
  84. if [ "$2" = "l" ]
  85. then
  86. dir="left"
  87. fi
  88. # echo "xrandr --output \"$output\" --rotate \"$dir\""
  89. xrandr --output "$output" --rotate "$dir"
  90. }
  91. # }}} rotate monitor #
  92. function apti() { sudo apt install $1 ; }
  93. function aptr() { sudo apt remove $1 ; }
  94. # }}} system #
  95. # config files {{{ #
  96. alias lc="f ~/linux-config/"
  97. alias lca="f ~/linux-config/aliases"
  98. alias vv="ni ~/.vimrc"
  99. alias vu="ni ~/.Xresources"
  100. alias vzb="ni ~/.zshrc"
  101. alias vz="ni ~/linux-config/aliases/zsh_aliases"
  102. alias vr="ni ~/.config/ranger/rc.conf"
  103. # i3 {{{ #
  104. alias v3="ni ~/.config/i3/config"
  105. alias v3b="ni ~/.config/i3blocks/i3blocks.conf"
  106. alias i3b="f ~/i3blocks"
  107. alias pipes="pipes.sh -t 2"
  108. alias bg="f ~/Pictures/Backgrounds"
  109. # }}} i3 #
  110. # UltiSnips {{{ #
  111. usnp_dir="~/.vim/plugged/vim-snippets/UltiSnips"
  112. alias snp="f $usnp_dir"
  113. function vsnp() { ni ~/.vim/plugged/vim-snippets/UltiSnips/"$1".snippets ; }
  114. alias tm="ni $usnp_dir/texmath.snippets"
  115. # }}} #
  116. # }}} config files #
  117. # applications {{{ #
  118. alias rg="ranger"
  119. # okular
  120. function ok() { nohup okular $1 > /dev/null 2>&1& ; }
  121. # xviewer
  122. function xv() { nohup xviewer $1 > /dev/null 2>&1& ; }
  123. function chr() { google-chrome $1 ; }
  124. function ni() { nvim $1 ; }
  125. function sni() { sudo nvim $1 ; }
  126. alias nisw="f ~/.local/share/nvim/swap"
  127. # function mrk() { pandoc -o ${1%.*}.html $1 && chr ${1%.*}.html ; }
  128. function mrk() { pandoc -o ${1%.*}.html $1 ; }
  129. function auc() { xdotool click --repeat 1000000 --delay $1 1 ; }
  130. alias auc1="xdotool click --repeat 1000000 --delay 1 1"
  131. alias auc3="xdotool click --repeat 1000000 --delay 300 1"
  132. alias auc5="xdotool click --repeat 1000000 --delay 500 1"
  133. alias kauc="pkill -f xdotool"
  134. alias vbn="cvlc --loop --alsa-gain 1 ~/Music/brown-noise.mp3"
  135. alias vlm="alsamixer -c 0"
  136. alias rmsw="rm .sw*"
  137. # function rs(){ redshift -O $(echo "scale=2;$1*1000" | bc) ; }
  138. function rs(){ redshift -O $1 ; }
  139. alias rx="redshift -x"
  140. # python related {{{ #
  141. function grpy() { grep $1 *.py ; }
  142. function p3() { python3 $1 ; }
  143. function py() { python $1 ; }
  144. # }}} python related #
  145. # }}} applications #
  146. # device specific {{{ #
  147. # NZXT {{{
  148. if [ "$(hostname)" = "nzxt" ]; then
  149. # audio {{{ #
  150. # was for transferring sink inputs between DAC and speakers but not
  151. # necessary if not using
  152. alias alsi="pactl list short sink-inputs"
  153. alias als="pactl list short sinks"
  154. function amsih() { pactl move-sink-input $1 0 ; }
  155. function amsis() { pactl move-sink-input $1 1 ; }
  156. # }}} audio #
  157. # apps {{{ #
  158. alias nem="nemo ."
  159. alias spt="speedtest"
  160. alias pg="ping -c 5 google.ca"
  161. alias w7="VBoxManage startvm W7 --type headless"
  162. # }}} apps #
  163. # various coding projs {{{ #
  164. alias sfa="f ~/Documents/self-authoring"
  165. alias rcg="$cd_coding_dir/random-color-generator"
  166. alias dcr="$cd_coding_dir/dcr-logger"
  167. alias prf="$cd_coding_dir/ParsaFood"
  168. # swbot {{{ #
  169. alias sb="$cd_coding_dir/swbot"
  170. # alias psb="p3 create_skills_dict.py"
  171. # alias psbo="p3 create_skills_dict.py > output.py"
  172. alias psb="p3 create_monster_dict.py"
  173. alias psbo="p3 create_monster_dict.py > output.py"
  174. # }}} swbot #
  175. # resume {{{ #
  176. alias cv="f ~/Documents/resume/examples"
  177. alias cvf="f ~/Documents/resume/examples/cv"
  178. alias vcv="ni ~/Documents/resume/examples/cv.tex"
  179. alias cvn="ni ~/Documents/resume/resume-notes.md"
  180. alias okcv="ok ~/Documents/resume/examples/cv.pdf"
  181. # https://stackoverflow.com/a/6605085/8811872
  182. function pdftojpg() {
  183. convert \
  184. -verbose \
  185. -density 150 \
  186. -trim \
  187. $1.pdf \
  188. -quality 100 \
  189. -flatten \
  190. -sharpen 0x1.0 \
  191. $1.jpg
  192. }
  193. # }}} resume #
  194. # }}} various coding projs #
  195. # NZXT }}}
  196. # laptop {{{
  197. elif [[ "$(hostname)" = "X1-Carbon" ]]; then
  198. alias gbl="xbacklight -get"
  199. function bl() { xbacklight -set $(echo "scale=2;$1*10" | bc) ; }
  200. alias labm="xrandr --auto && xrandr --output HDMI2 --right-of eDP1 --dpi 100"
  201. alias vlm="alsamixer -c 1"
  202. alias thn="thunar ."
  203. alias plz="f ~/platterz2018/ocr-reader/app/src/main/java/com/google/android/gms/samples/vision/ocrreader"
  204. alias ans="f /usr/local/android-studio/bin/"
  205. # laptop }}}
  206. # ubuntu {{{
  207. elif [ "$(hostname)" = "nzxt-ubuntu" ]; then
  208. # Stardew Valley {{{
  209. sdv_save_dir=~/Documents/sdv-save
  210. alias sdv="f $sdv_save_dir"
  211. alias smp="~/Downloads/sdv/smapi/install\ on\ Linux.sh"
  212. alias imc="sdv && source import-save.sh coop"
  213. function ucf() { f ~/Documents/StardewMods/UncaughtFish ; }
  214. function svmd() { f ~/.local/share/Steam/steamapps/common/Stardew\ Valley/Mods ; }
  215. function svm() { mv $1 ~/.local/share/Steam/steamapps/common/Stardew\ Valley/Mods ; }
  216. # }}}
  217. alias gx="ni ~/Documents/csgo-config/autoexec.cfg"
  218. fi
  219. # }}}
  220. # }}} device specific #
  221. # git {{{ #
  222. # aliases {{{
  223. alias gstr="git config credential.helper store"
  224. # add {{{ #
  225. alias ga="git add -A . && gs"
  226. alias gac="git add -A . && git commit"
  227. # }}} add #
  228. # diff/log {{{ #
  229. alias gd="git diff -w"
  230. alias gdc="git diff --cached"
  231. alias gds="git diff --stat"
  232. alias gl="git log"
  233. alias gsl="git shortlog"
  234. # }}} diff/log #
  235. # update {{{ #
  236. alias gs="git status -u"
  237. alias gchm="git checkout master"
  238. alias gchnw="git checkout -b wip"
  239. alias gchw="git checkout wip"
  240. alias gheadm1="git reset --hard HEAD~1"
  241. alias glstf="git ls-tree -r HEAD --name-only"
  242. # push {{{ #
  243. alias egc="nvim -c \"set syn=gitcommit\" -c \"set tw=72\" commit-msg.txt"
  244. alias gst="git stash"
  245. alias gstp="git stash pop"
  246. alias gc="git commit"
  247. alias gcam="ga && git commit --amend"
  248. # todo: fix
  249. function gcm(){ echo git commit -m \""$1"\" ; }
  250. function psg() {
  251. git add .
  252. git commit -m '.'
  253. git push
  254. }
  255. alias gps="git push"
  256. alias gpsf="git push --force"
  257. alias gclear="git stash clear"
  258. # }}} push #
  259. # pull {{{ #
  260. alias gpl="git pull --rebase"
  261. alias grbc="git rebase --continue"
  262. # }}} pull #
  263. # }}} update #
  264. # edit {{{ #
  265. alias vig="ni .gitignore"
  266. alias vir="ni README.md"
  267. alias crm="mrk README.md"
  268. # }}} edit #
  269. # aliases }}}
  270. # functions {{{
  271. function gcho() { git checkout $1 ; }
  272. function gchon() { git checkout -b $1 ; }
  273. function gchof() { git checkout $1 $2 ; }
  274. function gcln() { git clone $1 ; }
  275. function gchp() { git cherry-pick $1 ; }
  276. alias gchpc="git cherry-pick --continue"
  277. # add multiple push repos
  278. function gremotes() {
  279. git remote set-url --add --push origin $1
  280. git remote set-url --add --push origin $2
  281. git remote -v
  282. }
  283. # gmrgr: merge repos {{{ #
  284. function gmrgr() {
  285. # 1 = remote name, 2 = remote path
  286. git remote add $1 $2
  287. git fetch $1
  288. # whichever branch you want to merge
  289. git merge --allow-unrelated-histories $1/master
  290. git remote remove $1
  291. }
  292. # }}} merge repos #
  293. # assume file unchanged
  294. function gunc() { git update-index --assume-unchanged $1 ; }
  295. # delete branch locally and on server
  296. function grmb() { git push -d origin $1 && git branch -D $1 ; }
  297. # functions }}}
  298. # }}} git #
  299. # coding projs {{{ #
  300. coding_dir="~/coding"
  301. cd_coding_dir="f $coding_dir"
  302. alias cdn="$cd_coding_dir"
  303. # ideas
  304. ideas_dir="$coding_dir""/ideas"
  305. alias ids="f $ideas_dir"
  306. alias lci="f $ideas_dir/general"
  307. alias vli="ni $ideas_dir/general/ideas.md"
  308. alias fyn="f $ideas_dir/yes-no"
  309. alias ans="f /usr/local/android-studio/bin && ./studio.sh"
  310. # trapbot {{{ #
  311. alias tb="$cd_coding_dir/trapbot"
  312. alias vtb="$cd_coding_dir/trapbot && ni scan_reddit.py"
  313. alias ptb="python scan_reddit.py"
  314. alias rtb="$cd_coding_dir/trapbot && python scan_reddit.py"
  315. # }}} trapbot #
  316. # spotify-lib-vis {{{ #
  317. spv_dir="$coding_dir""/spotify-lib-vis"
  318. alias spv="f $spv_dir/src/spotifyvis"
  319. alias spvd="f $spv_dir/src"
  320. function sspv() {
  321. source api-keys.sh
  322. source ../bin/activate
  323. python manage.py runserver
  324. }
  325. # }}} spotify-lib-vis #
  326. # }}} coding projs #
  327. # school {{{ #
  328. in_lab=false
  329. cd_school="f ~/Documents/School/notes"
  330. # general {{{
  331. alias sch="$cd_school"
  332. alias 236="$cd_school/236"
  333. alias rml="rm *.aux *.log *.pdf"
  334. # LaTeX {{{ #
  335. function pdl() { pdflatex $1 ; }
  336. function pdlb() { pdflatex $1 && biber $1 && pdflatex $1 ; }
  337. function cptp() {
  338. cp *template.tex cp-template.tex
  339. chmod 600 cp-template.tex
  340. date=`date +%-m-%d`
  341. mv cp-template.tex "$date".tex
  342. }
  343. # }}} LaTeX #
  344. # }}}
  345. # 136 {{{
  346. alias clc="gcalccmd"
  347. alias mt="ok ~/Documents/School/calc-textbook.pdf"
  348. alias mt2="ok ~/Documents/School/calc-textbook-2.pdf"
  349. alias 136="$cd_school/136"
  350. alias 136l="$cd_school/136/lecture"
  351. alias pr3="$cd_school/136/par/3"
  352. # }}}
  353. # 209 {{{
  354. # dirs {{{
  355. cd_209="f ~/Documents/School/209";
  356. alias 209="$cd_209"
  357. alias 9r="$cd_209/mokkar"
  358. alias 9l="$cd_209/mokkar/lab10"
  359. alias 9a="$cd_209/mokkar/a4"
  360. # }}}
  361. alias ll="ls -la"
  362. alias cdf="echo \". ./.bashrc\"&& ssh mokkar@cdf.utoronto.ca"
  363. function mkex() { chmod 777 $1 ; }
  364. # {{{ Compilation Functions
  365. # compile without running
  366. function c9() { gcc -Wall -std=gnu99 -g -o "${1%.*}.out" "$1" -lm ; }
  367. # compile all without running {{{ #
  368. function c9a() {
  369. for file in *; do
  370. if [[ $file = *.c ]]; then
  371. gcc -Wall -std=gnu99 -g -o "${file%.*}".out "$file"
  372. fi
  373. done
  374. }
  375. # }}} compile all without running #
  376. # compile and run
  377. function c9r() { c9 $1 && ./"${1%.*}.out" ; }
  378. # compile and run with input
  379. function c9i() { c9 $1 && ./"${1%.*}.out" < $2 ; }
  380. # compile and run with input file {{{ #
  381. function run() {
  382. while read line; do
  383. # ./$1.out $line
  384. echo ./$1.out $line
  385. done < $1.in
  386. }
  387. # }}} compile and run with input file #
  388. # temp {{{ #
  389. function m9() {
  390. c9 write_test_file.c
  391. ./write_test_file.out test.txt
  392. od -vtu1 test.txt
  393. }
  394. alias m92="c9 time_reads.c && ./time_reads.out 1 test.txt"
  395. # }}} temp #
  396. # }}}
  397. # }}}
  398. alias 6a="$cd_school/236/a2"
  399. alias 6t="ok ~/Documents/School/236-textbook.pdf"
  400. # }}} school #