speed up your terminal interactions

When it comes to speeding up terminal interactions, there are a few things that help me to be more productive. I hope that we all can agree that re-typing same commands over and over again can be truly irritating, especially the long ones that take multiple arguments. How about navigating around a filesystem? No wonder that cd is one of the most used bash commands. Anyhow, there is always a place for improving the way how you interact with the terminal.

bash aliases & functions

I tend to use bash aliases to shorten most used CLIs to a single letter. I have aliased git to g, kubectl to k, you get the gist.
By aliasing you can achieve more complex tasks, take for an example - gcln which I have aliased to git branch | egrep -v "(master|\*)" | xargs git branch -D. I use this alias to tidy up checked out git repository by removing all locally checked out branches after I have finished actively working on it.
I could actually argue that this alias could be converted into a function to avoid piping, however it’s quite straight forward to read it, therefore I just let it be.
To demonstrate a bit more complex use case for which a bash function is more fitting than an alias, would be this function for getting k8s pods.

kgp() {
  if [[ $# -eq 0 ]] ; then
    echo "\e[34mk get pods $(kenv)\e[39m"
    k get pods $(kenv)
  elif [[ "$2" = "w" ]] ; then
    echo "\e[34mk get pods $(kenv) | grep $1\e[39m"
    watch "kubectl get pods $(kenv) | grep $1"
  else
    echo "\e[34mk get pods $(kenv) | grep $1\e[39m"
    k get pods $(kenv) | grep $1
  fi
}

If I would call kgp without any additional arguments, it would return all pods for the current k8s environment. However, if I would provide an additional argument to kgp it would return only matching pods that match the provided string. And if I add a second argument w then additionally to returning only matching pods, it would use the watch command which continuously calls the given command every 2 seconds. Additionally to this, I’m echoing the executed function which also includes some text formatting.

I have symlinked my bash aliases and functions from a git repository and I load them via .zshrc. By doing so, I can keep my aliases and functions up to date and use them on different machines.

warp directories

I have been using a zsh plugin called warp directory (wd) for some time now. This plugin allows adding wrap points to frequently used directories and then warp between directories with ease. Thanks to this must have plugin be assured that you will shave off some precious seconds from cd’ing around the filesystem.

jump forwards & backwards

Whenever I made a mistake in the command that I was typing, I was holding down or and waiting for the cursor to reach the place I wanted to edit. This neat trick allows to jump forwards and backwards over the words that you just typed. To achieve this you need to configure your terminal to add key shortcuts that send an escape sequence when ⌥← and ⌥→ are pressed. To send jump backwards - Esc+: b or jump forwards - Esc+: f.