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.

428 lines
9.7 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 pf="$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. # key swaps {{{ #
  175. xmodmap -e "keycode 9 = Escape"
  176. xmodmap -e "keycode 22 = Home"
  177. xmodmap -e "keycode 119 = End"
  178. xmodmap -e "keycode 110 = Delete"
  179. xmodmap -e "keycode 115 = BackSpace"
  180. # }}} key swaps #
  181. alias gbl="xbacklight -get"
  182. function bl() { xbacklight -set $(echo "scale=2;$1*10" | bc) ; }
  183. alias thn="thunar ."
  184. alias plz="f ~/platterz2018/ocr-reader/app/src/main/java/com/google/android/gms/samples/vision/ocrreader"
  185. alias ans="f /usr/local/android-studio/bin/"
  186. fi
  187. # laptop }}}
  188. # }}} device specific #
  189. # git {{{ #
  190. # aliases {{{
  191. alias gstore="git config credential.helper store"
  192. # add {{{ #
  193. alias ga="git add -A . && gs"
  194. alias gac="git add -A . && git commit"
  195. # }}} add #
  196. # diff/log {{{ #
  197. alias gd="git diff -w"
  198. alias gdc="git diff --cached"
  199. alias gl="git log"
  200. alias gsl="git shortlog"
  201. # }}} diff/log #
  202. # update {{{ #
  203. alias gs="git status -u"
  204. alias gchm="git checkout master"
  205. alias gchnw="git checkout -b wip"
  206. alias gchw="git checkout wip"
  207. alias gheadm1="git reset --hard HEAD~1"
  208. # push {{{ #
  209. alias egc="nvim -c \"set syn=gitcommit\" -c \"set tw=72\" commit-msg.txt"
  210. alias gst="git stash"
  211. alias gstp="git stash pop"
  212. alias gc="git commit"
  213. alias gcam="git commit --amend"
  214. # todo: fix
  215. function gcm(){ echo git commit -m \""$1"\" ; }
  216. function gpsg() {
  217. git add .
  218. git commit -m '.'
  219. git push
  220. }
  221. alias gps="git push"
  222. alias gpsfrc="git push --force"
  223. alias gdwip="git push -d origin wip && git branch -D wip"
  224. alias gclear="git stash clear"
  225. # }}} push #
  226. # pull {{{ #
  227. alias gpl="git pull --rebase"
  228. alias grbc="git rebase --continue"
  229. # }}} pull #
  230. # }}} update #
  231. # edit {{{ #
  232. alias vig="ni .gitignore"
  233. alias vir="ni README.md"
  234. alias crm="mrk README.md"
  235. # }}} edit #
  236. # aliases }}}
  237. # functions {{{
  238. function gcho() { git checkout $1 ; }
  239. function gcln() { git clone $1 ; }
  240. function gchp() { git cherry-pick $1 ; }
  241. function gremotes() {
  242. git remote set-url --add --push origin $1
  243. git remote set-url --add --push origin $2
  244. }
  245. # gmrgr: merge repos {{{ #
  246. function gmrgr() {
  247. # 1 = remote name, 2 = remote path
  248. git remote add $1 $2
  249. git fetch $1
  250. # whichever branch you want to merge
  251. git merge --allow-unrelated-histories $1/master
  252. git remote remove $1
  253. }
  254. # }}} merge repos #
  255. function gunc() { git update-index --assume-unchanged $1 ; }
  256. # pull all {{{ #
  257. function gpla() {
  258. cmds="lc snp 9r sch"
  259. for cmd in $cmds; do
  260. eval $cmd && gst && gpl && gstp && gclear
  261. done
  262. }
  263. # }}} pull all #
  264. # functions }}}
  265. # }}} git #
  266. # coding projs {{{ #
  267. coding_dir="~/Documents/coding"
  268. cd_coding_dir="f $coding_dir"
  269. alias cdn="$cd_coding_dir"
  270. # ideas
  271. ideas_dir="$coding_dir""/ideas"
  272. alias ids="f $ideas_dir"
  273. alias lci="f $ideas_dir/general"
  274. alias vli="ni $ideas_dir/ideas.md"
  275. alias fyn="f $ideas_dir/yes-no"
  276. alias ans="f /usr/local/android-studio/bin && ./studio.sh"
  277. # trapbot {{{ #
  278. alias tb="$cd_coding_dir/trapbot"
  279. alias vtb="$cd_coding_dir/trapbot && ni scan_reddit.py"
  280. alias ptb="python scan_reddit.py"
  281. alias rtb="$cd_coding_dir/trapbot && python scan_reddit.py"
  282. # }}} trapbot #
  283. # }}} coding projs #
  284. # school {{{ #
  285. in_lab=false
  286. cd_school="f ~/Documents/School/notes"
  287. # general {{{
  288. alias sch="$cd_school"
  289. alias 236="$cd_school/236"
  290. alias rml="rm *.aux *.log *.pdf"
  291. # LaTeX {{{ #
  292. function pdl() { pdflatex $1 ; }
  293. function cptp() {
  294. cp *template.tex cp-template.tex
  295. chmod 600 cp-template.tex
  296. date=`date +%-m-%d`
  297. mv cp-template.tex "$date".tex
  298. }
  299. # }}} LaTeX #
  300. # }}}
  301. # 136 {{{
  302. alias clc="gcalccmd"
  303. alias mt="ok ~/Documents/School/calc-textbook.pdf"
  304. alias 136="$cd_school/136"
  305. alias 136l="$cd_school/136/lecture"
  306. alias pr3="$cd_school/136/par/3"
  307. # }}}
  308. # 209 {{{
  309. # dirs {{{
  310. cd_209="f ~/Documents/School/209";
  311. alias 209="$cd_209"
  312. alias 9r="$cd_209/mokkar"
  313. alias l8="$cd_209/mokkar/lab8"
  314. alias 9a="$cd_209/mokkar/a3"
  315. # }}}
  316. alias ll="ls -la"
  317. alias cdf="echo \". ./.bashrc\"&& ssh mokkar@cdf.utoronto.ca"
  318. function mkex() { chmod 777 $1 ; }
  319. # {{{ Compilation Functions
  320. # compile without running
  321. function c9() { gcc -Wall -std=gnu99 -g -o "${1%.*}.out" "$1" -lm ; }
  322. # compile all without running {{{ #
  323. function c9a() {
  324. for file in *; do
  325. if [[ $file = *.c ]]; then
  326. gcc -Wall -std=gnu99 -g -o "${file%.*}".out "$file"
  327. fi
  328. done
  329. }
  330. # }}} compile all without running #
  331. # compile and run
  332. function c9r() { c9 $1 && ./"${1%.*}.out" ; }
  333. # compile and run with input
  334. function c9i() { c9 $1 && ./"${1%.*}.out" < $2 ; }
  335. # compile and run with input file {{{ #
  336. function run() {
  337. while read line; do
  338. # ./$1.out $line
  339. echo ./$1.out $line
  340. done < $1.in
  341. }
  342. # }}} compile and run with input file #
  343. # temp {{{ #
  344. alias m8="make checkpasswd && ./checkpasswd < passwd.in"
  345. alias m3="make pfact && ./pfact.out 14"
  346. alias 35w="c9 3-5_wait.c && ./3-5_wait.out abc a"
  347. # }}} temp #
  348. # }}}
  349. # }}}
  350. alias 36a="$cd_school/236/a1"
  351. alias 6t="ok ~/Documents/School/236-textbook.pdf"
  352. # }}} school #