set up Caps Lock as a shortcut for changing the input language I want to set up Casp Lock as a shortcut for changing the input language. There are some solutions like this. But it requires installing some software and doing tricks. Is there a way to do it in a neat way, say through terminal command?
Yes, you can use Caps Lock to change input language without third-party software.
All you need is a custom-made keyboard layout (usually made with Ukelele ) that has two alternative sets of characters bound to Caps lock=on and Caps lock=on and Shift=on states.

Pros: zero-lag, no weird key remapping hacks needed
Cons: buit-in input source indicator becomes useless, looking at the Caps LED is not very convenient for touch-typists.

To mitigate the "cons" I use lightweight third-party app called Capster that changes the icon in the menubar depending on the Caps lock state.
I also use small Applescript to disable Caps lock delay.

I'm using this method for many years and never looked back.

This is my bundle for Russian language (with additional Ukrainian characters bound to alt+key)
https://github.com/falcn/Caps-layout