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.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. # 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() { okular $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 thn="thunar ."
  181. alias plz="f ~/platterz2018/ocr-reader/app/src/main/java/com/google/android/gms/samples/vision/ocrreader"
  182. alias ans="f /usr/local/android-studio/bin/"
  183. fi
  184. # laptop }}}
  185. # }}} device specific #
  186. # git {{{ #
  187. # aliases {{{
  188. alias gstore="git config credential.helper store"
  189. # add {{{ #
  190. alias ga="git add -A . && gs"
  191. alias gac="git add -A . && git commit"
  192. # }}} add #
  193. # diff/log {{{ #
  194. alias gd="git diff -w"
  195. alias gdc="git diff --cached"
  196. alias gl="git log"
  197. alias gsl="git shortlog"
  198. # }}} diff/log #
  199. # update {{{ #
  200. alias gs="git status -u"
  201. alias gchm="git checkout master"
  202. alias gchnw="git checkout -b wip"
  203. alias gchw="git checkout wip"
  204. alias gheadm1="git reset --hard HEAD~1"
  205. alias glstf="git ls-tree -r HEAD --name-only"
  206. # push {{{ #
  207. alias egc="nvim -c \"set syn=gitcommit\" -c \"set tw=72\" commit-msg.txt"
  208. alias gst="git stash"
  209. alias gstp="git stash pop"
  210. alias gc="git commit"
  211. alias gcam="ga && git commit --amend"
  212. # todo: fix
  213. function gcm(){ echo git commit -m \""$1"\" ; }
  214. function psg() {
  215. git add .
  216. git commit -m '.'
  217. git push
  218. }
  219. alias gps="git push"
  220. alias gpsf="git push --force"
  221. alias gclear="git stash clear"
  222. # }}} push #
  223. # pull {{{ #
  224. alias gpl="git pull --rebase"
  225. alias grbc="git rebase --continue"
  226. # }}} pull #
  227. # }}} update #
  228. # edit {{{ #
  229. alias vig="ni .gitignore"
  230. alias vir="ni README.md"
  231. alias crm="mrk README.md"
  232. # }}} edit #
  233. # aliases }}}
  234. # functions {{{
  235. function gcho() { git checkout $1 ; }
  236. function gchon() { git checkout -b $1 ; }
  237. function gcln() { git clone $1 ; }
  238. function gchp() { git cherry-pick $1 ; }
  239. alias gchpc="git cherry-pick --continue"
  240. # add multiple push repos
  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. # assume file unchanged
  256. function gunc() { git update-index --assume-unchanged $1 ; }
  257. # delete branch locally and on server
  258. function grmb() { git push -d origin $1 && git branch -D $1 ; }
  259. # functions }}}
  260. # }}} git #
  261. # coding projs {{{ #
  262. coding_dir="~/Documents/coding"
  263. cd_coding_dir="f $coding_dir"
  264. alias cdn="$cd_coding_dir"
  265. # ideas
  266. ideas_dir="$coding_dir""/ideas"
  267. alias ids="f $ideas_dir"
  268. alias lci="f $ideas_dir/general"
  269. alias vli="ni $ideas_dir/general/ideas.md"
  270. alias fyn="f $ideas_dir/yes-no"
  271. alias ans="f /usr/local/android-studio/bin && ./studio.sh"
  272. # trapbot {{{ #
  273. alias tb="$cd_coding_dir/trapbot"
  274. alias vtb="$cd_coding_dir/trapbot && ni scan_reddit.py"
  275. alias ptb="python scan_reddit.py"
  276. alias rtb="$cd_coding_dir/trapbot && python scan_reddit.py"
  277. # }}} trapbot #
  278. # }}} coding projs #
  279. # school {{{ #
  280. in_lab=false
  281. cd_school="f ~/Documents/School/notes"
  282. # general {{{
  283. alias sch="$cd_school"
  284. alias 236="$cd_school/236"
  285. alias rml="rm *.aux *.log *.pdf"
  286. # LaTeX {{{ #
  287. function pdl() { pdflatex $1 ; }
  288. function cptp() {
  289. cp *template.tex cp-template.tex
  290. chmod 600 cp-template.tex
  291. date=`date +%-m-%d`
  292. mv cp-template.tex "$date".tex
  293. }
  294. # }}} LaTeX #
  295. # }}}
  296. # 136 {{{
  297. alias clc="gcalccmd"
  298. alias mt="ok ~/Documents/School/calc-textbook.pdf"
  299. alias 136="$cd_school/136"
  300. alias 136l="$cd_school/136/lecture"
  301. alias pr3="$cd_school/136/par/3"
  302. # }}}
  303. # 209 {{{
  304. # dirs {{{
  305. cd_209="f ~/Documents/School/209";
  306. alias 209="$cd_209"
  307. alias 9r="$cd_209/mokkar"
  308. alias l9="$cd_209/mokkar/lab9"
  309. alias 9a="$cd_209/mokkar/a3"
  310. # }}}
  311. alias ll="ls -la"
  312. alias cdf="echo \". ./.bashrc\"&& ssh mokkar@cdf.utoronto.ca"
  313. function mkex() { chmod 777 $1 ; }
  314. # {{{ Compilation Functions
  315. # compile without running
  316. function c9() { gcc -Wall -std=gnu99 -g -o "${1%.*}.out" "$1" -lm ; }
  317. # compile all without running {{{ #
  318. function c9a() {
  319. for file in *; do
  320. if [[ $file = *.c ]]; then
  321. gcc -Wall -std=gnu99 -g -o "${file%.*}".out "$file"
  322. fi
  323. done
  324. }
  325. # }}} compile all without running #
  326. # compile and run
  327. function c9r() { c9 $1 && ./"${1%.*}.out" ; }
  328. # compile and run with input
  329. function c9i() { c9 $1 && ./"${1%.*}.out" < $2 ; }
  330. # compile and run with input file {{{ #
  331. function run() {
  332. while read line; do
  333. # ./$1.out $line
  334. echo ./$1.out $line
  335. done < $1.in
  336. }
  337. # }}} compile and run with input file #
  338. # temp {{{ #
  339. function m9() {
  340. c9 write_test_file.c
  341. ./write_test_file.out test.txt
  342. od -vtu1 test.txt
  343. }
  344. alias m92="c9 time_reads.c && ./time_reads.out 1 test.txt"
  345. # }}} temp #
  346. # }}}
  347. # }}}
  348. alias 36a="$cd_school/236/a1"
  349. alias 6t="ok ~/Documents/School/236-textbook.pdf"
  350. # }}} school #