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.

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