Which shell do you use for work each day? Do you have any tips to improve efficiency? Any functions you wrote that make certain tasks faster?
I recently switched to fish and have been thoroughly enjoying it. It offers command completion suggestions based on your history, which is really useful because I sometimes find myself running the same commands frequently. It is also able to tab-complete the options and flags associated with many commands (if I remember correctly, it scans the man pages for those, which is really cool). It is also fairly easy to write a completion script for an existing command, and I was able to get it working really well for one of our internal tools.
One shell trick that I used in bash quite often was running
sudo !!. The
!! in bash expands to the previously run command, so this let’s you easily re-run the previous command as root. fish doesn’t have this, but it does prepend
sudo if you press alt+s, which is still helpful.
Here’s one fish function that I wrote which helps me quickly run updates on all my packages:
function pkgup sudo apt update && sudo apt full-upgrade brew update && brew upgrade sudo snap refresh kubectl krew update && kubectl krew upgrade end
Here’s another that lets me easily switch my Kubernetes context:
function kcon switch $argv case [k8s context 1] kubie ctx [k8s context 1 name] case [k8s context 2] kubie ctx [k8s context 2 name] case [etc.] case '*' echo (set_color brred) "Invalid context: $argv" echo (set_color normal) "Contexts: [list of k8s contexts]" end end
I wrote it as a switch statement like that so that I can refer to my Kubernetes contexts by a different name than their real one. I find this useful because any kubeconfig created by k3d has the prefix
k3d- which isn’t fun to type each time.