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.

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