Tuesday 7 April 2020

Bash, fish-shell, Zsh - in the pursuit of command line happiness

The years are going on but the command line is not disappearing. There are few productive tips I found useful for myself.

Shell - bash, fish, zsh, tcsh?

Bash

Bash is a good default. Bash is Turing complete. My one outstanding issue with bash is that is has problems when editing commands longer than single line. I have spent years using bash and I am still not sure about some constructs there. The ifs and ors. The crucial `set -x` There used to be conference talks when people would argument, how it is more productive and maintainable and now even more carbon neutral to write longer scripts in Perl than in Bash. Or Python. Or in Ruby. But people love to challenge them self with longer bash codes. Whatever.

Fish-shell

Fish looks fancy, fish looks smart, fish feels cool. At least for the first moment. I tried to use it, but then I realised it is too incompatible with bash - I was using some AWS commands and I couldn't get the `source` command working together. To the point it was blocking me from doing what I needed to do. It was 2 years ago so maybe something has changed since. Anyway, I swam away from that fish.

Zsh

I have tried it once years ago. The same time I have tried csh (so I could write shell scripts easier). I think I skipped it because I was trying to get my team with some uniformity and bash was looking more like "it is default and it works". Years later I tried it again. And again. I couldn't get used to the way I have one history across all different tabs and windows. I don't think I like it that way but I got used to it. I added oh-my-zsh and powerlevel10k theme. I learned how to search history with regexps. There was still something missing. Then I learned from my colleague Hung (thanks!) I can have a fuzzy search commands history on top of it. That's quite nice. Usable. Nice prompts with current git repo branch and status, commands execution time, current kubernetes cluster.

~/w/dotshellapps master ?2 ▓▒░ sleep 3 
~/w/dotshellapps master ?2 ▓▒░     ░▒▓ 3s anaconda3   dev ⎈ 21:14:41 

I am not sure I need anaconda there. I may fix it later. Yes, the right side is probably too long, but it disappears when you type. So it is not that annoying and my console screen is much wider. Ok, I may fix it one day, I promise.