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.

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