Skip to content

Instantly share code, notes, and snippets.

@nick133
Created February 4, 2021 23:22
Show Gist options
  • Save nick133/96168f13e775c5dbf219a4f0a490f01d to your computer and use it in GitHub Desktop.
Save nick133/96168f13e775c5dbf219a4f0a490f01d to your computer and use it in GitHub Desktop.
Sway (Wayland) waybar JSON data provider for custom/locale plugin
1 #!/bin/bash
2 #
3 # JSON data provider for waybar custom/locale plugin
4 #
5
6 makejson() {
7 sed $1 -e 's@^.*English.*$@{ "text": "En", "tooltip": "English (US)", "class": "lang_en", "percentage": 0 }@' \
8 ┊ -e 's@^.*Russian.*$@{ "text": "Ru", "tooltip": "Russian", "class": "lang_ru", "percentage": 0 }@' \
9 ┊ -e 's@^.*Ukrainian.*$@{ "text": "Uk", "tooltip": "Ukrainian", "class": "lang_uk", "percentage": 0 }@'
10 }
11
12 swaymsg -t get_inputs | grep -m1 "xkb_active_layout_name" | makejson
13
14 swaymsg -mt subscribe '["input"]' \
15 | jq -r --unbuffered 'select(.change == "xkb_layout").input.xkb_active_layout_name' \
16 | makejson -u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment