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.

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