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.

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