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.

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