How I use Zsh for Augmenting My Activities

Written on September 1, 2021

Zsh, or Z-Shell is a really good shell Unix/OSX/similar. It gets even better with oh-my-zsh. However, I made it even better with the help of scripts, themes and whatnot. Please note that this is not a How-to tutorial for the inexperienced zsh user; so I expect you, the reader, to know how to modify ~/.zshrc, or where to find it, or how to use aliases - those type of common scripting things. Lets dive in!

Look and Feel

I use the theme agnoster. Setting this up requires some delicate configuration of colors and fonts, so I suggest you to go through the link. But basically, you gotta set this line in zshrc:

ZSH_THEME="agnoster"

In addition, I use the amazing Jetbrains Mono font. However, it still does not look right. Too much space is being wasted.

See that amitseal@Amits-MacBook-Pro? That’s unnecessary, unless you are in a multi-user environment and you want to know both your username and hostname, All.the.time. Which I don’t. Hence make this modification in your ~/.zshrc:

DEFAULT_USER="amitseal"
prompt_context(){}

Which results in hiding both username and hostname. Nice!

In addition to this, I also use syntax highlighting in zsh. Here is what you can do:

brew install zsh-syntax-highlighting
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

Plugins

These are the plugins I use with zsh:

plugins=(
  # for git
  git
  # only if you use osx
  osx
  # if you like using visual studio code
  vscode
  # must have
  zsh-autosuggestions
  # only if you use clojure
  lein
)

Aliases

I use A LOT OF aliases. Some of them are based on modifying existing functions with switches. Some of them are my own, personal creations using python/shell scripting.

I made several git related aliases just so that I can avoid typing… 5 characters.

# This is for add, commit and pushing everything for commits that do not matter.
# I often use this when I am pushing things to website after building.
# The comprehensible comments go to the source commits.
function f_gitcap(){
git add .
git commit -m "update"
git push
}
alias gitcap=f_gitcap

# more git related aliases
alias gita='git add .'
alias gitc='git-cola'
alias gitcd='git-cola dag'
alias gitcu='git commit -m "update"'
alias gpom='git push origin master'

Helpful Aliases for Better Commands

Don’t like the output of cat? Too banal? Use pcat. Also, there is grep and vena.

alias grep='grep --color=auto'
# you will need to install pygmentize first
alias pcat='pygmentize -f terminal256 -O style=monokai -g'
# don't want to type a long command every time you want to activate a virtual env? Here:
alias vena='source venv/bin/activate'

Aliases for Jekyll

Who does not love jekyll? I Love Jekyll! But the commands are long.. and scary. Hence:

alias jeksl='bundle exec jekyll serve --config _devconfig.yml'
alias jeks='bundle exec jekyll serve'
alias jekbl='bundle exec jekyll build -I --config _devconfig.yml'
alias jekbs='bundle exec jekyll build'
alias jekcb='bundle exec jekyll clean && bundle exec jekyll build'

Custom Commands with Aliases

To make my life easier, I made many commands and then I connected them to aliases. All the source codes are available in my repository: Automating Boring Tasks using Python - inspired by the book Automate the Boring Stuff with Python.

# For pulling apks from device
# note that abtup is placeholder for the automating ... I linked above
alias pull_apk="abtup/get_apk_from_device/main.py"

# a image viewer with presentation mode made by yours truly;
# since I was unhappy with everything else
alias image_view='abtup/image_in_window_screensaver/runme.sh'

# images sorted in landscape and portrait directories
alias image_land_port="abtup/image_sort_landscape_portrait/src/main.py"

# HotCrp formatted paper reviews to markdown format for ease of reading
alias review_md='/usr/bin/python3 abtup/review_to_md/main.py'

# Clicker for Clicking games automatically
alias autoclicker="abtup/autoclicker/venv/bin/python abtup/autoclicker/autoclicker/main.py"
alias autoclickeri="abtup/autoclicker/venv/bin/python abtup/autoclicker/autoclicker/main.py 0"

For the LaTeX Fans

These are some python scripts I wrote that helps me avoid common writing issues as well as format LaTeX files.

# checks for silly issues,
# like not using `~` before \cite and \ref, and
# not using `,` before 'which', or using `,` before 'that'.
alias tex_silly="abtup/tex_misc/check_silly.py"

# script to avoid even sillier mistakes
# based on Dr. Tao Xie's Writing Issues
alias tex_words="abtup/tex_writing_issues/main.py"

# line breaker
# Adds new line in between sentences separated by periods.
# Respects existing line breaks, tries to respect indentation.
alias tex_linebreaks="abtup/tex_linebreaker/line_breaker.py"

# when you want to find a particular file with a particular word across folders
alias fwif="abtup/find_word_in_folders/find_word_in_folders.py"

More Custom Commands!

Script to convert first page of PDF to image. Does not go for highest quality to save size, but you can change density and quality to improve that. For PDFs, I don’t want the image to have transparent background, so I remove it while making it white.

#!/bin/bash
filename=$1
convert -density 190 "$filename[$2]" -quality 90 -background white -alpha remove "$1".jpg

That’s all folks!


To comment as guest, click on the field "Name". The option to do so will become visible.
লগইন ছাড়াই কমেন্ট করতে নাম এ ক্লিক করুন, দেখবেন তার নিচেই আছে অতিথি হিসাবে কমেন্ট করার অপশন।