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.

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