Hacker News new | past | comments | ask | show | jobs | submit login

I use fzf in this very way and could have written this article if I weren’t lazy lol. However, I can add two other use cases:

1. I use i3wm at home (haven’t yet made the jump into Sway/Wayland), and don’t want to change my screen resolution by opening an app, clicking with my mouse, and then waiting. So I use fzf for quick resolution changes using xrandr:

  cr() {
    xrandr | sed -En “s/^[ ]+([0-9]{3,4}x[0-9]{3,4}0.\*/\1/p” | fzf | xargs -I{} xrandr —output HDMI-0 —mode {}
  }
2. At work I switch between multiple Kubernetes contexts during the day. To make the switch fast without typing a sentence, I will use this helper function:

  kc () {
     kubectl config get-contexts | tail -n +2 | fzf | cut -c 2- | awk ‘{print $1}’ | xargs kubectl config use-context
  }
I found this to be better than tab-completion because with tab completion I only get the name of the context, and not the cluster/user/namespace fields that make it easier to select the right one.

Use the above at your own risk, as they are fast hack-ups and could be far more clear (my sed skills are prone to error and overly verbose).

—Edited for HN formatting




I would highly recommend looking at something like kubectx [0] to manage switching between kubernetes contexts! I've been using this for a while now and have it aliased to kx. It supports tab completion, as well as fzf integration if you have it installed [1]. There's also kubens in there which does the same for namespaces!

[0]: https://github.com/ahmetb/kubectx

[1]: https://github.com/ahmetb/kubectx#interactive-mode


Just a heads up that the quotes used in the kc function appear to be "smart quotes" and will likely throw an error if copied verbatim into your shell config


Thanks for the heads up! For some reason HN keeps mangling the post so I am not going to try to edit it again.


For something similar to your xrandr example in i3m, I prefer to use rofi, which gives you an interactive menu in the center of the screen:

Link to Rofi: https://github.com/davatorium/rofi

Examples of how I use rofi:https://adityam.github.io/linux-blog/post/rofi-selectors/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: