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.

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